workflow.registry.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. /**
  17. * Registry of models
  18. * - Each model should have an ID attribute.
  19. */
  20. var RegistryModule = function($) {
  21. var module = function() {
  22. var self = this;
  23. self.nodes = {};
  24. module.prototype.initialize.apply(self, arguments);
  25. return self;
  26. };
  27. $.extend(module.prototype, {
  28. // Normal stuff
  29. initialize: function() {},
  30. toString: function() {
  31. var self = this;
  32. var s = $.map(self.nodes, function(node) {
  33. return node.id();
  34. }).join();
  35. return s;
  36. },
  37. add: function(id, node) {
  38. var self = this;
  39. $(self).trigger('registry.add');
  40. self.nodes[String(id)] = node;
  41. },
  42. remove: function(id) {
  43. var self = this;
  44. $(self).trigger('registry.remove');
  45. delete self.nodes[String(id)];
  46. },
  47. get: function(id) {
  48. var self = this;
  49. return self.nodes[id];
  50. },
  51. clear: function() {
  52. var self = this;
  53. delete self.nodes;
  54. self.nodes = {};
  55. }
  56. });
  57. return module;
  58. };