AbstractManager.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-AbstractManager'>/**
  19. </span> * Base Manager class
  20. */
  21. Ext.define('Ext.AbstractManager', {
  22. /* Begin Definitions */
  23. requires: ['Ext.util.HashMap'],
  24. /* End Definitions */
  25. typeName: 'type',
  26. constructor: function(config) {
  27. Ext.apply(this, config || {});
  28. <span id='Ext-AbstractManager-property-all'> /**
  29. </span> * @property {Ext.util.HashMap} all
  30. * Contains all of the items currently managed
  31. */
  32. this.all = new Ext.util.HashMap();
  33. this.types = {};
  34. },
  35. <span id='Ext-AbstractManager-method-get'> /**
  36. </span> * Returns an item by id.
  37. * For additional details see {@link Ext.util.HashMap#get}.
  38. * @param {String} id The id of the item
  39. * @return {Object} The item, undefined if not found.
  40. */
  41. get : function(id) {
  42. return this.all.get(id);
  43. },
  44. <span id='Ext-AbstractManager-method-register'> /**
  45. </span> * Registers an item to be managed
  46. * @param {Object} item The item to register
  47. */
  48. register: function(item) {
  49. //&lt;debug&gt;
  50. var all = this.all,
  51. key = all.getKey(item);
  52. if (all.containsKey(key)) {
  53. Ext.Error.raise('Registering duplicate id &quot;' + key + '&quot; with this manager');
  54. }
  55. //&lt;/debug&gt;
  56. this.all.add(item);
  57. },
  58. <span id='Ext-AbstractManager-method-unregister'> /**
  59. </span> * Unregisters an item by removing it from this manager
  60. * @param {Object} item The item to unregister
  61. */
  62. unregister: function(item) {
  63. this.all.remove(item);
  64. },
  65. <span id='Ext-AbstractManager-method-registerType'> /**
  66. </span> * Registers a new item constructor, keyed by a type key.
  67. * @param {String} type The mnemonic string by which the class may be looked up.
  68. * @param {Function} cls The new instance class.
  69. */
  70. registerType : function(type, cls) {
  71. this.types[type] = cls;
  72. cls[this.typeName] = type;
  73. },
  74. <span id='Ext-AbstractManager-method-isRegistered'> /**
  75. </span> * Checks if an item type is registered.
  76. * @param {String} type The mnemonic string by which the class may be looked up
  77. * @return {Boolean} Whether the type is registered.
  78. */
  79. isRegistered : function(type){
  80. return this.types[type] !== undefined;
  81. },
  82. <span id='Ext-AbstractManager-method-create'> /**
  83. </span> * Creates and returns an instance of whatever this manager manages, based on the supplied type and
  84. * config object.
  85. * @param {Object} config The config object
  86. * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
  87. * @return {Object} The instance of whatever this manager is managing
  88. */
  89. create: function(config, defaultType) {
  90. var type = config[this.typeName] || config.type || defaultType,
  91. Constructor = this.types[type];
  92. //&lt;debug&gt;
  93. if (Constructor === undefined) {
  94. Ext.Error.raise(&quot;The '&quot; + type + &quot;' type has not been registered with this manager&quot;);
  95. }
  96. //&lt;/debug&gt;
  97. return new Constructor(config);
  98. },
  99. <span id='Ext-AbstractManager-method-onAvailable'> /**
  100. </span> * Registers a function that will be called when an item with the specified id is added to the manager.
  101. * This will happen on instantiation.
  102. * @param {String} id The item id
  103. * @param {Function} fn The callback function. Called with a single parameter, the item.
  104. * @param {Object} scope The scope (this reference) in which the callback is executed.
  105. * Defaults to the item.
  106. */
  107. onAvailable : function(id, fn, scope){
  108. var all = this.all,
  109. item,
  110. callback;
  111. if (all.containsKey(id)) {
  112. item = all.get(id);
  113. fn.call(scope || item, item);
  114. } else {
  115. callback = function(map, key, item){
  116. if (key == id) {
  117. fn.call(scope || item, item);
  118. all.un('add', callback);
  119. }
  120. };
  121. all.on('add', callback);
  122. }
  123. },
  124. <span id='Ext-AbstractManager-method-each'> /**
  125. </span> * Executes the specified function once for each item in the collection.
  126. * @param {Function} fn The function to execute.
  127. * @param {String} fn.key The key of the item
  128. * @param {Number} fn.value The value of the item
  129. * @param {Number} fn.length The total number of items in the collection
  130. * @param {Boolean} fn.return False to cease iteration.
  131. * @param {Object} scope The scope to execute in. Defaults to `this`.
  132. */
  133. each: function(fn, scope){
  134. this.all.each(fn, scope || this);
  135. },
  136. <span id='Ext-AbstractManager-method-getCount'> /**
  137. </span> * Gets the number of items in the collection.
  138. * @return {Number} The number of items in the collection.
  139. */
  140. getCount: function(){
  141. return this.all.getCount();
  142. }
  143. });
  144. </pre>
  145. </body>
  146. </html>