4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-AbstractManager'>/**
19 </span> * @class Ext.AbstractManager
25 Ext.define('Ext.AbstractManager', {
27 /* Begin Definitions */
29 requires: ['Ext.util.HashMap'],
35 constructor: function(config) {
36 Ext.apply(this, config || {});
38 <span id='Ext-AbstractManager-property-all'> /**
39 </span> * Contains all of the items currently managed
41 * @type Ext.util.MixedCollection
43 this.all = Ext.create('Ext.util.HashMap');
48 <span id='Ext-AbstractManager-method-get'> /**
49 </span> * Returns an item by id.
50 * For additional details see {@link Ext.util.HashMap#get}.
51 * @param {String} id The id of the item
52 * @return {Mixed} The item, <code>undefined</code> if not found.
55 return this.all.get(id);
58 <span id='Ext-AbstractManager-method-register'> /**
59 </span> * Registers an item to be managed
60 * @param {Mixed} item The item to register
62 register: function(item) {
66 <span id='Ext-AbstractManager-method-unregister'> /**
67 </span> * Unregisters an item by removing it from this manager
68 * @param {Mixed} item The item to unregister
70 unregister: function(item) {
71 this.all.remove(item);
74 <span id='Ext-AbstractManager-method-registerType'> /**
75 </span> * <p>Registers a new item constructor, keyed by a type key.
76 * @param {String} type The mnemonic string by which the class may be looked up.
77 * @param {Constructor} cls The new instance class.
79 registerType : function(type, cls) {
80 this.types[type] = cls;
81 cls[this.typeName] = type;
84 <span id='Ext-AbstractManager-method-isRegistered'> /**
85 </span> * Checks if an item type is registered.
86 * @param {String} type The mnemonic string by which the class may be looked up
87 * @return {Boolean} Whether the type is registered.
89 isRegistered : function(type){
90 return this.types[type] !== undefined;
93 <span id='Ext-AbstractManager-method-create'> /**
94 </span> * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
95 * @param {Object} config The config object
96 * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
97 * @return {Mixed} The instance of whatever this manager is managing
99 create: function(config, defaultType) {
100 var type = config[this.typeName] || config.type || defaultType,
101 Constructor = this.types[type];
104 if (Constructor == undefined) {
105 Ext.Error.raise("The '" + type + "' type has not been registered with this manager");
109 return new Constructor(config);
112 <span id='Ext-AbstractManager-method-onAvailable'> /**
113 </span> * Registers a function that will be called when an item with the specified id is added to the manager. This will happen on instantiation.
114 * @param {String} id The item id
115 * @param {Function} fn The callback function. Called with a single parameter, the item.
116 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the item.
118 onAvailable : function(id, fn, scope){
122 if (all.containsKey(id)) {
124 fn.call(scope || item, item);
126 all.on('add', function(map, key, item){
128 fn.call(scope || item, item);
129 all.un('add', fn, scope);
135 <span id='Ext-AbstractManager-method-each'> /**
136 </span> * Executes the specified function once for each item in the collection.
137 * Returning false from the function will cease iteration.
139 * The paramaters passed to the function are:
140 * <div class="mdetail-params"><ul>
141 * <li><b>key</b> : String<p class="sub-desc">The key of the item</p></li>
142 * <li><b>value</b> : Number<p class="sub-desc">The value of the item</p></li>
143 * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
144 * </ul></div>
145 * @param {Object} fn The function to execute.
146 * @param {Object} scope The scope to execute in. Defaults to <tt>this</tt>.
148 each: function(fn, scope){
149 this.all.each(fn, scope || this);
152 <span id='Ext-AbstractManager-method-getCount'> /**
153 </span> * Gets the number of items in the collection.
154 * @return {Number} The number of items in the collection.
156 getCount: function(){
157 return this.all.getCount();