roojs-core.js
[roojs1] / Roo / NestedLayoutPanel.js
1
2
3 /**
4  * @class Roo.NestedLayoutPanel
5  * @extends Roo.ContentPanel
6  * @parent Roo.BorderLayout Roo.LayoutDialog builder
7  * @cfg {Roo.BorderLayout} layout   [required] The layout for this panel
8  *
9  * 
10  * @constructor
11  * Create a new NestedLayoutPanel.
12  * 
13  * 
14  * @param {Roo.BorderLayout} layout [required] The layout for this panel
15  * @param {String/Object} config A string to set only the title or a config object
16  */
17 Roo.NestedLayoutPanel = function(layout, config)
18 {
19     // construct with only one argument..
20     /* FIXME - implement nicer consturctors
21     if (layout.layout) {
22         config = layout;
23         layout = config.layout;
24         delete config.layout;
25     }
26     if (layout.xtype && !layout.getEl) {
27         // then layout needs constructing..
28         layout = Roo.factory(layout, Roo);
29     }
30     */
31     
32     
33     Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
34     
35     layout.monitorWindowResize = false; // turn off autosizing
36     this.layout = layout;
37     this.layout.getEl().addClass("x-layout-nested-layout");
38     
39     
40     
41     
42 };
43
44 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
45
46     layout : false,
47
48     setSize : function(width, height){
49         if(!this.ignoreResize(width, height)){
50             var size = this.adjustForComponents(width, height);
51             var el = this.layout.getEl();
52             el.setSize(size.width, size.height);
53             var touch = el.dom.offsetWidth;
54             this.layout.layout();
55             // ie requires a double layout on the first pass
56             if(Roo.isIE && !this.initialized){
57                 this.initialized = true;
58                 this.layout.layout();
59             }
60         }
61     },
62     
63     // activate all subpanels if not currently active..
64     
65     setActiveState : function(active){
66         this.active = active;
67         if(!active){
68             this.fireEvent("deactivate", this);
69             return;
70         }
71         
72         this.fireEvent("activate", this);
73         // not sure if this should happen before or after..
74         if (!this.layout) {
75             return; // should not happen..
76         }
77         var reg = false;
78         for (var r in this.layout.regions) {
79             reg = this.layout.getRegion(r);
80             if (reg.getActivePanel()) {
81                 //reg.showPanel(reg.getActivePanel()); // force it to activate.. 
82                 reg.setActivePanel(reg.getActivePanel());
83                 continue;
84             }
85             if (!reg.panels.length) {
86                 continue;
87             }
88             reg.showPanel(reg.getPanel(0));
89         }
90         
91         
92         
93         
94     },
95     
96     /**
97      * Returns the nested BorderLayout for this panel
98      * @return {Roo.BorderLayout}
99      */
100     getLayout : function(){
101         return this.layout;
102     },
103     
104      /**
105      * Adds a xtype elements to the layout of the nested panel
106      * <pre><code>
107
108 panel.addxtype({
109        xtype : 'ContentPanel',
110        region: 'west',
111        items: [ .... ]
112    }
113 );
114
115 panel.addxtype({
116         xtype : 'NestedLayoutPanel',
117         region: 'west',
118         layout: {
119            center: { },
120            west: { }   
121         },
122         items : [ ... list of content panels or nested layout panels.. ]
123    }
124 );
125 </code></pre>
126      * @param {Object} cfg Xtype definition of item to add.
127      */
128     addxtype : function(cfg) {
129         return this.layout.addxtype(cfg);
130     
131     }
132 });