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
23 Ext.define('Ext.AbstractManager', {
25 /* Begin Definitions */
27 requires: ['Ext.util.HashMap'],
33 constructor: function(config) {
34 Ext.apply(this, config || {});
36 <span id='Ext-AbstractManager-property-all'> /**
37 </span> * Contains all of the items currently managed
39 * @type Ext.util.MixedCollection
41 this.all = Ext.create('Ext.util.HashMap');
46 <span id='Ext-AbstractManager-method-get'> /**
47 </span> * Returns an item by id.
48 * For additional details see {@link Ext.util.HashMap#get}.
49 * @param {String} id The id of the item
50 * @return {Mixed} The item, <code>undefined</code> if not found.
53 return this.all.get(id);
56 <span id='Ext-AbstractManager-method-register'> /**
57 </span> * Registers an item to be managed
58 * @param {Mixed} item The item to register
60 register: function(item) {
64 <span id='Ext-AbstractManager-method-unregister'> /**
65 </span> * Unregisters an item by removing it from this manager
66 * @param {Mixed} item The item to unregister
68 unregister: function(item) {
69 this.all.remove(item);
72 <span id='Ext-AbstractManager-method-registerType'> /**
73 </span> * <p>Registers a new item constructor, keyed by a type key.
74 * @param {String} type The mnemonic string by which the class may be looked up.
75 * @param {Constructor} cls The new instance class.
77 registerType : function(type, cls) {
78 this.types[type] = cls;
79 cls[this.typeName] = type;
82 <span id='Ext-AbstractManager-method-isRegistered'> /**
83 </span> * Checks if an item type is registered.
84 * @param {String} type The mnemonic string by which the class may be looked up
85 * @return {Boolean} Whether the type is registered.
87 isRegistered : function(type){
88 return this.types[type] !== undefined;
91 <span id='Ext-AbstractManager-method-create'> /**
92 </span> * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
93 * @param {Object} config The config object
94 * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
95 * @return {Mixed} The instance of whatever this manager is managing
97 create: function(config, defaultType) {
98 var type = config[this.typeName] || config.type || defaultType,
99 Constructor = this.types[type];
102 if (Constructor == undefined) {
103 Ext.Error.raise("The '" + type + "' type has not been registered with this manager");
107 return new Constructor(config);
110 <span id='Ext-AbstractManager-method-onAvailable'> /**
111 </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.
112 * @param {String} id The item id
113 * @param {Function} fn The callback function. Called with a single parameter, the item.
114 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the item.
116 onAvailable : function(id, fn, scope){
120 if (all.containsKey(id)) {
122 fn.call(scope || item, item);
124 all.on('add', function(map, key, item){
126 fn.call(scope || item, item);
127 all.un('add', fn, scope);
133 <span id='Ext-AbstractManager-method-each'> /**
134 </span> * Executes the specified function once for each item in the collection.
135 * Returning false from the function will cease iteration.
137 * The paramaters passed to the function are:
138 * <div class="mdetail-params"><ul>
139 * <li><b>key</b> : String<p class="sub-desc">The key of the item</p></li>
140 * <li><b>value</b> : Number<p class="sub-desc">The value of the item</p></li>
141 * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
142 * </ul></div>
143 * @param {Object} fn The function to execute.
144 * @param {Object} scope The scope to execute in. Defaults to <tt>this</tt>.
146 each: function(fn, scope){
147 this.all.each(fn, scope || this);
150 <span id='Ext-AbstractManager-method-getCount'> /**
151 </span> * Gets the number of items in the collection.
152 * @return {Number} The number of items in the collection.
154 getCount: function(){
155 return this.all.getCount();