Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27 jpm 1
/*
2
 * Ext JS Library 2.0.2
3
 * Copyright(c) 2006-2008, 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 (specifically subclasses of
12
 * {@link Ext.Component}) on a page so that they can be easily accessed by
13
 * component id (see {@link 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}.
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>
19
 * A child Component may be specified simply as a <i>config object</i>
20
 * as long as the correct xtype is specified so that if and when the Component
21
 * needs rendering, the correct type can be looked up for lazy instantiation.</p>
22
 * <p>For a list of all available xtypes, see {@link Ext.Component}.</p>
23
 * @singleton
24
 */
25
Ext.ComponentMgr = function(){
26
    var all = new Ext.util.MixedCollection();
27
    var types = {};
28
 
29
    return {
30
        /**
31
         * Registers a component.
32
         * @param {Ext.Component} c The component
33
         */
34
        register : function(c){
35
            all.add(c);
36
        },
37
 
38
        /**
39
         * Unregisters a component.
40
         * @param {Ext.Component} c The component
41
         */
42
        unregister : function(c){
43
            all.remove(c);
44
        },
45
 
46
        /**
47
         * Returns a component by id
48
         * @param {String} id The component id
49
         * @return Ext.Component
50
         */
51
        get : function(id){
52
            return all.get(id);
53
        },
54
 
55
        /**
56
         * Registers a function that will be called when a specified component is added to ComponentMgr
57
         * @param {String} id The component id
58
         * @param {Function} fn The callback function
59
         * @param {Object} scope The scope of the callback
60
         */
61
        onAvailable : function(id, fn, scope){
62
            all.on("add", function(index, o){
63
                if(o.id == id){
64
                    fn.call(scope || o, o);
65
                    all.un("add", fn, scope);
66
                }
67
            });
68
        },
69
 
70
        /**
71
         * The MixedCollection used internally for the component cache. An example usage may be subscribing to
72
         * events on the MixedCollection to monitor addition or removal.  Read-only.
73
         * @type {MixedCollection}
74
         */
75
        all : all,
76
 
77
        /**
78
         * Registers a new Component constructor, keyed by a new
79
         * {@link Ext.Component#xtype}.<br><br>
80
         * Use this method to register new subclasses of {@link Ext.Component} so
81
         * that lazy instantiation may be used when specifying child Components.
82
         * see {@link Ext.Container#items}
83
         * @param {String} xtype The mnemonic string by which the Component class
84
         * may be looked up.
85
         * @param {Constructor} cls The new Component class.
86
         */
87
        registerType : function(xtype, cls){
88
            types[xtype] = cls;
89
            cls.xtype = xtype;
90
        },
91
 
92
        // private
93
        create : function(config, defaultType){
94
            return new types[config.xtype || defaultType](config);
95
        }
96
    };
97
}();
98
 
99
// this will be called a lot internally,
100
// shorthand to keep the bytes down
101
Ext.reg = Ext.ComponentMgr.registerType;