<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-AbstractManager'>/**
</span> * @class Ext.AbstractManager
 * @extends Object
 * Base Manager class - extended by ComponentMgr and PluginMgr
 */
Ext.AbstractManager = Ext.extend(Object, {
<span id='Ext-AbstractManager-property-typeName'>    typeName: 'type',
</span>    
<span id='Ext-AbstractManager-method-constructor'>    constructor: function(config) {
</span>        Ext.apply(this, config || {});
        
<span id='Ext-AbstractManager-property-all'>        /**
</span>         * Contains all of the items currently managed
         * @property all
         * @type Ext.util.MixedCollection
         */
        this.all = new Ext.util.MixedCollection();
        
        this.types = {};
    },
    
<span id='Ext-AbstractManager-method-get'>    /**
</span>     * Returns a component by {@link Ext.Component#id id}.
     * For additional details see {@link Ext.util.MixedCollection#get}.
     * @param {String} id The component {@link Ext.Component#id id}
     * @return Ext.Component The Component, &lt;code&gt;undefined&lt;/code&gt; if not found, or &lt;code&gt;null&lt;/code&gt; if a
     * Class was found.
     */
    get : function(id){
        return this.all.get(id);
    },
    
<span id='Ext-AbstractManager-method-register'>    /**
</span>     * Registers an item to be managed
     * @param {Mixed} item The item to register
     */
    register: function(item) {
        this.all.add(item);
    },
    
<span id='Ext-AbstractManager-method-unregister'>    /**
</span>     * Unregisters a component by removing it from this manager
     * @param {Mixed} item The item to unregister
     */
    unregister: function(item) {
        this.all.remove(item);        
    },
    
<span id='Ext-AbstractManager-method-registerType'>    /**
</span>     * &lt;p&gt;Registers a new Component constructor, keyed by a new
     * {@link Ext.Component#xtype}.&lt;/p&gt;
     * &lt;p&gt;Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
     * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
     * child Components.
     * see {@link Ext.Container#items}&lt;/p&gt;
     * @param {String} xtype The mnemonic string by which the Component class may be looked up.
     * @param {Constructor} cls The new Component class.
     */
    registerType : function(type, cls){
        this.types[type] = cls;
        cls[this.typeName] = type;
    },
    
<span id='Ext-AbstractManager-method-isRegistered'>    /**
</span>     * Checks if a Component type is registered.
     * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
     * @return {Boolean} Whether the type is registered.
     */
    isRegistered : function(type){
        return this.types[type] !== undefined;    
    },
    
<span id='Ext-AbstractManager-method-create'>    /**
</span>     * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
     * @param {Object} config The config object
     * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
     * @return {Mixed} The instance of whatever this manager is managing
     */
    create: function(config, defaultType) {
        var type        = config[this.typeName] || config.type || defaultType,
            Constructor = this.types[type];
        
        if (Constructor == undefined) {
            throw new Error(String.format(&quot;The '{0}' type has not been registered with this manager&quot;, type));
        }
        
        return new Constructor(config);
    },
    
<span id='Ext-AbstractManager-method-onAvailable'>    /**
</span>     * Registers a function that will be called when a Component with the specified id is added to the manager. This will happen on instantiation.
     * @param {String} id The component {@link Ext.Component#id id}
     * @param {Function} fn The callback function
     * @param {Object} scope The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the callback is executed. Defaults to the Component.
     */
    onAvailable : function(id, fn, scope){
        var all = this.all;
        
        all.on(&quot;add&quot;, function(index, o){
            if (o.id == id) {
                fn.call(scope || o, o);
                all.un(&quot;add&quot;, fn, scope);
            }
        });
    }
});</pre>
</body>
</html>