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; }
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> * Base Manager class
21 Ext.define('Ext.AbstractManager', {
23 /* Begin Definitions */
25 requires: ['Ext.util.HashMap'],
31 constructor: function(config) {
32 Ext.apply(this, config || {});
34 <span id='Ext-AbstractManager-property-all'> /**
35 </span> * @property {Ext.util.HashMap} all
36 * Contains all of the items currently managed
38 this.all = Ext.create('Ext.util.HashMap');
43 <span id='Ext-AbstractManager-method-get'> /**
44 </span> * Returns an item by id.
45 * For additional details see {@link Ext.util.HashMap#get}.
46 * @param {String} id The id of the item
47 * @return {Object} The item, undefined if not found.
50 return this.all.get(id);
53 <span id='Ext-AbstractManager-method-register'> /**
54 </span> * Registers an item to be managed
55 * @param {Object} item The item to register
57 register: function(item) {
60 key = all.getKey(item);
62 if (all.containsKey(key)) {
63 Ext.Error.raise('Registering duplicate id "' + key + '" with this manager');
69 <span id='Ext-AbstractManager-method-unregister'> /**
70 </span> * Unregisters an item by removing it from this manager
71 * @param {Object} item The item to unregister
73 unregister: function(item) {
74 this.all.remove(item);
77 <span id='Ext-AbstractManager-method-registerType'> /**
78 </span> * Registers a new item constructor, keyed by a type key.
79 * @param {String} type The mnemonic string by which the class may be looked up.
80 * @param {Function} cls The new instance class.
82 registerType : function(type, cls) {
83 this.types[type] = cls;
84 cls[this.typeName] = type;
87 <span id='Ext-AbstractManager-method-isRegistered'> /**
88 </span> * Checks if an item type is registered.
89 * @param {String} type The mnemonic string by which the class may be looked up
90 * @return {Boolean} Whether the type is registered.
92 isRegistered : function(type){
93 return this.types[type] !== undefined;
96 <span id='Ext-AbstractManager-method-create'> /**
97 </span> * Creates and returns an instance of whatever this manager manages, based on the supplied type and
99 * @param {Object} config The config object
100 * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
101 * @return {Object} The instance of whatever this manager is managing
103 create: function(config, defaultType) {
104 var type = config[this.typeName] || config.type || defaultType,
105 Constructor = this.types[type];
108 if (Constructor === undefined) {
109 Ext.Error.raise("The '" + type + "' type has not been registered with this manager");
113 return new Constructor(config);
116 <span id='Ext-AbstractManager-method-onAvailable'> /**
117 </span> * Registers a function that will be called when an item with the specified id is added to the manager.
118 * This will happen on instantiation.
119 * @param {String} id The item id
120 * @param {Function} fn The callback function. Called with a single parameter, the item.
121 * @param {Object} scope The scope (this reference) in which the callback is executed.
122 * Defaults to the item.
124 onAvailable : function(id, fn, scope){
128 if (all.containsKey(id)) {
130 fn.call(scope || item, item);
132 all.on('add', function(map, key, item){
134 fn.call(scope || item, item);
135 all.un('add', fn, scope);
141 <span id='Ext-AbstractManager-method-each'> /**
142 </span> * Executes the specified function once for each item in the collection.
143 * @param {Function} fn The function to execute.
144 * @param {String} fn.key The key of the item
145 * @param {Number} fn.value The value of the item
146 * @param {Number} fn.length The total number of items in the collection
147 * @param {Boolean} fn.return False to cease iteration.
148 * @param {Object} scope The scope to execute in. Defaults to `this`.
150 each: function(fn, scope){
151 this.all.each(fn, scope || this);
154 <span id='Ext-AbstractManager-method-getCount'> /**
155 </span> * Gets the number of items in the collection.
156 * @return {Number} The number of items in the collection.
158 getCount: function(){
159 return this.all.getCount();