Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / AbstractManager.html
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="../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; }
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> * @class Ext.AbstractManager
20  * @extends Object
21  * Base Manager class
22  */
23 Ext.define('Ext.AbstractManager', {
24
25     /* Begin Definitions */
26
27     requires: ['Ext.util.HashMap'],
28
29     /* End Definitions */
30
31     typeName: 'type',
32
33     constructor: function(config) {
34         Ext.apply(this, config || {});
35
36 <span id='Ext-AbstractManager-property-all'>        /**
37 </span>         * Contains all of the items currently managed
38          * @property all
39          * @type Ext.util.MixedCollection
40          */
41         this.all = Ext.create('Ext.util.HashMap');
42
43         this.types = {};
44     },
45
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, &lt;code&gt;undefined&lt;/code&gt; if not found.
51      */
52     get : function(id) {
53         return this.all.get(id);
54     },
55
56 <span id='Ext-AbstractManager-method-register'>    /**
57 </span>     * Registers an item to be managed
58      * @param {Mixed} item The item to register
59      */
60     register: function(item) {
61         this.all.add(item);
62     },
63
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
67      */
68     unregister: function(item) {
69         this.all.remove(item);
70     },
71
72 <span id='Ext-AbstractManager-method-registerType'>    /**
73 </span>     * &lt;p&gt;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.
76      */
77     registerType : function(type, cls) {
78         this.types[type] = cls;
79         cls[this.typeName] = type;
80     },
81
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.
86      */
87     isRegistered : function(type){
88         return this.types[type] !== undefined;
89     },
90
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
96      */
97     create: function(config, defaultType) {
98         var type        = config[this.typeName] || config.type || defaultType,
99             Constructor = this.types[type];
100
101         //&lt;debug&gt;
102         if (Constructor == undefined) {
103             Ext.Error.raise(&quot;The '&quot; + type + &quot;' type has not been registered with this manager&quot;);
104         }
105         //&lt;/debug&gt;
106
107         return new Constructor(config);
108     },
109
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 (&lt;code&gt;this&lt;/code&gt; reference) in which the callback is executed. Defaults to the item.
115      */
116     onAvailable : function(id, fn, scope){
117         var all = this.all,
118             item;
119         
120         if (all.containsKey(id)) {
121             item = all.get(id);
122             fn.call(scope || item, item);
123         } else {
124             all.on('add', function(map, key, item){
125                 if (key == id) {
126                     fn.call(scope || item, item);
127                     all.un('add', fn, scope);
128                 }
129             });
130         }
131     },
132     
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.
136      * 
137      * The paramaters passed to the function are:
138      * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
139      * &lt;li&gt;&lt;b&gt;key&lt;/b&gt; : String&lt;p class=&quot;sub-desc&quot;&gt;The key of the item&lt;/p&gt;&lt;/li&gt;
140      * &lt;li&gt;&lt;b&gt;value&lt;/b&gt; : Number&lt;p class=&quot;sub-desc&quot;&gt;The value of the item&lt;/p&gt;&lt;/li&gt;
141      * &lt;li&gt;&lt;b&gt;length&lt;/b&gt; : Number&lt;p class=&quot;sub-desc&quot;&gt;The total number of items in the collection&lt;/p&gt;&lt;/li&gt;
142      * &lt;/ul&gt;&lt;/div&gt;
143      * @param {Object} fn The function to execute.
144      * @param {Object} scope The scope to execute in. Defaults to &lt;tt&gt;this&lt;/tt&gt;.
145      */
146     each: function(fn, scope){
147         this.all.each(fn, scope || this);    
148     },
149     
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.
153      */
154     getCount: function(){
155         return this.all.getCount();
156     }
157 });
158 </pre>
159 </body>
160 </html>