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