source: trunk/web/addons/job_monarch/lib/extjs/source/widgets/ComponentMgr.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 4.3 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9/**
10 * @class Ext.ComponentMgr
11 * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
12 * thereof) on a page so that they can be easily accessed by component id (see {@link #get}, or
13 * the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
14 * <p>This object also provides a registry of available Component <i>classes</i>
15 * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
16 * The <tt>xtype</tt> provides a way to avoid instantiating child Components
17 * when creating a full, nested config object for a complete Ext page.</p>
18 * <p>A child Component may be specified simply as a <i>config object</i>
19 * as long as the correct xtype is specified so that if and when the Component
20 * needs rendering, the correct type can be looked up for lazy instantiation.</p>
21 * <p>For a list of all available xtypes, see {@link Ext.Component}.</p>
22 * @singleton
23 */
24Ext.ComponentMgr = function(){
25    var all = new Ext.util.MixedCollection();
26    var types = {};
27
28    return {
29        /**
30         * Registers a component.
31         * @param {Ext.Component} c The component
32         */
33        register : function(c){
34            all.add(c);
35        },
36
37        /**
38         * Unregisters a component.
39         * @param {Ext.Component} c The component
40         */
41        unregister : function(c){
42            all.remove(c);
43        },
44
45        /**
46         * Returns a component by id
47         * @param {String} id The component id
48         * @return Ext.Component
49         */
50        get : function(id){
51            return all.get(id);
52        },
53
54        /**
55         * Registers a function that will be called when a specified component is added to ComponentMgr
56         * @param {String} id The component id
57         * @param {Function} fn The callback function
58         * @param {Object} scope The scope of the callback
59         */
60        onAvailable : function(id, fn, scope){
61            all.on("add", function(index, o){
62                if(o.id == id){
63                    fn.call(scope || o, o);
64                    all.un("add", fn, scope);
65                }
66            });
67        },
68
69        /**
70         * The MixedCollection used internally for the component cache. An example usage may be subscribing to
71         * events on the MixedCollection to monitor addition or removal.  Read-only.
72         * @type {MixedCollection}
73         */
74        all : all,
75
76        /**
77         * <p>Registers a new Component constructor, keyed by a new
78         * {@link Ext.Component#xtype}.</p>
79         * <p>Use this method to register new subclasses of {@link Ext.Component} so
80         * that lazy instantiation may be used when specifying child Components.
81         * see {@link Ext.Container#items}</p>
82         * @param {String} xtype The mnemonic string by which the Component class
83         * may be looked up.
84         * @param {Constructor} cls The new Component class.
85         */
86        registerType : function(xtype, cls){
87            types[xtype] = cls;
88            cls.xtype = xtype;
89        },
90
91        /**
92         * Creates a new Component from the specified config object using the
93         * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
94         * @param config {Object} A configuration object for the Component you wish to create.
95         * @param defaultType {Constructor} The constructor to provide the default Component type if
96         * the config object does not contain an xtype. (Optional if the config contains an xtype).
97         * @return {Ext.Component} The newly instantiated Component.
98         */
99        create : function(config, defaultType){
100            return new types[config.xtype || defaultType](config);
101        }
102    };
103}();
104
105/**
106 * Shorthand for {@link Ext.ComponentMgr#registerType}
107 * @param {String} xtype The mnemonic string by which the Component class
108 * may be looked up.
109 * @param {Constructor} cls The new Component class.
110 * @member Ext
111 * @method reg
112 */
113Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down
Note: See TracBrowser for help on using the repository browser.