1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-AbstractManager'>/**
2 </span> * @class Ext.AbstractManager
8 Ext.define('Ext.AbstractManager', {
10 /* Begin Definitions */
12 requires: ['Ext.util.HashMap'],
18 constructor: function(config) {
19 Ext.apply(this, config || {});
21 <span id='Ext-AbstractManager-property-all'> /**
22 </span> * Contains all of the items currently managed
24 * @type Ext.util.MixedCollection
26 this.all = Ext.create('Ext.util.HashMap');
31 <span id='Ext-AbstractManager-method-get'> /**
32 </span> * Returns an item by id.
33 * For additional details see {@link Ext.util.HashMap#get}.
34 * @param {String} id The id of the item
35 * @return {Mixed} The item, <code>undefined</code> if not found.
38 return this.all.get(id);
41 <span id='Ext-AbstractManager-method-register'> /**
42 </span> * Registers an item to be managed
43 * @param {Mixed} item The item to register
45 register: function(item) {
49 <span id='Ext-AbstractManager-method-unregister'> /**
50 </span> * Unregisters an item by removing it from this manager
51 * @param {Mixed} item The item to unregister
53 unregister: function(item) {
54 this.all.remove(item);
57 <span id='Ext-AbstractManager-method-registerType'> /**
58 </span> * <p>Registers a new item constructor, keyed by a type key.
59 * @param {String} type The mnemonic string by which the class may be looked up.
60 * @param {Constructor} cls The new instance class.
62 registerType : function(type, cls) {
63 this.types[type] = cls;
64 cls[this.typeName] = type;
67 <span id='Ext-AbstractManager-method-isRegistered'> /**
68 </span> * Checks if an item type is registered.
69 * @param {String} type The mnemonic string by which the class may be looked up
70 * @return {Boolean} Whether the type is registered.
72 isRegistered : function(type){
73 return this.types[type] !== undefined;
76 <span id='Ext-AbstractManager-method-create'> /**
77 </span> * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
78 * @param {Object} config The config object
79 * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
80 * @return {Mixed} The instance of whatever this manager is managing
82 create: function(config, defaultType) {
83 var type = config[this.typeName] || config.type || defaultType,
84 Constructor = this.types[type];
87 if (Constructor == undefined) {
88 Ext.Error.raise("The '" + type + "' type has not been registered with this manager");
92 return new Constructor(config);
95 <span id='Ext-AbstractManager-method-onAvailable'> /**
96 </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.
97 * @param {String} id The item id
98 * @param {Function} fn The callback function. Called with a single parameter, the item.
99 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the item.
101 onAvailable : function(id, fn, scope){
105 if (all.containsKey(id)) {
107 fn.call(scope || item, item);
109 all.on('add', function(map, key, item){
111 fn.call(scope || item, item);
112 all.un('add', fn, scope);
118 <span id='Ext-AbstractManager-method-each'> /**
119 </span> * Executes the specified function once for each item in the collection.
120 * Returning false from the function will cease iteration.
122 * The paramaters passed to the function are:
123 * <div class="mdetail-params"><ul>
124 * <li><b>key</b> : String<p class="sub-desc">The key of the item</p></li>
125 * <li><b>value</b> : Number<p class="sub-desc">The value of the item</p></li>
126 * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
127 * </ul></div>
128 * @param {Object} fn The function to execute.
129 * @param {Object} scope The scope to execute in. Defaults to <tt>this</tt>.
131 each: function(fn, scope){
132 this.all.each(fn, scope || this);
135 <span id='Ext-AbstractManager-method-getCount'> /**
136 </span> * Gets the number of items in the collection.
137 * @return {Number} The number of items in the collection.
139 getCount: function(){
140 return this.all.getCount();
143 </pre></pre></body></html>