Roo/bootstrap/panel/Nest.js
[roojs1] / Roo / bootstrap / panel / Nest.js
1
2 /**
3  * @class Roo.bootstrap.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.bootstrap.panel.Nest = function(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     config.el =  config.layout.getEl();
28     
29     Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
30     
31     config.layout.monitorWindowResize = false; // turn off autosizing
32     this.layout = config.layout;
33     this.layout.getEl().addClass("roo-layout-nested-layout");
34     
35     
36     
37     
38 };
39
40 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
41
42     setSize : function(width, height){
43         if(!this.ignoreResize(width, height)){
44             var size = this.adjustForComponents(width, height);
45             var el = this.layout.getEl();
46             if (size.height < 1) {
47                 el.setWidth(size.width);   
48             } else {
49                 el.setSize(size.width, size.height);
50             }
51             var touch = el.dom.offsetWidth;
52             this.layout.layout();
53             // ie requires a double layout on the first pass
54             if(Roo.isIE && !this.initialized){
55                 this.initialized = true;
56                 this.layout.layout();
57             }
58         }
59     },
60     
61     // activate all subpanels if not currently active..
62     
63     setActiveState : function(active){
64         this.active = active;
65         Roo.log('setActiveState !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
66         Roo.log(active);
67         this.setActiveClass(active);
68         
69         if(!active){
70             this.fireEvent("deactivate", this);
71             return;
72         }
73         
74         this.fireEvent("activate", this);
75         // not sure if this should happen before or after..
76         if (!this.layout) {
77             return; // should not happen..
78         }
79         var reg = false;
80         for (var r in this.layout.regions) {
81             reg = this.layout.getRegion(r);
82             if (reg.getActivePanel()) {
83                 //reg.showPanel(reg.getActivePanel()); // force it to activate.. 
84                 reg.setActivePanel(reg.getActivePanel());
85                 continue;
86             }
87             if (!reg.panels.length) {
88                 continue;
89             }
90             reg.showPanel(reg.getPanel(0));
91         }
92         
93         
94         
95         
96     },
97     
98     /**
99      * Returns the nested BorderLayout for this panel
100      * @return {Roo.BorderLayout} 
101      */
102     getLayout : function(){
103         return this.layout;
104     },
105     
106      /**
107      * Adds a xtype elements to the layout of the nested panel
108      * <pre><code>
109
110 panel.addxtype({
111        xtype : 'ContentPanel',
112        region: 'west',
113        items: [ .... ]
114    }
115 );
116
117 panel.addxtype({
118         xtype : 'NestedLayoutPanel',
119         region: 'west',
120         layout: {
121            center: { },
122            west: { }   
123         },
124         items : [ ... list of content panels or nested layout panels.. ]
125    }
126 );
127 </code></pre>
128      * @param {Object} cfg Xtype definition of item to add.
129      */
130     addxtype : function(cfg) {
131         return this.layout.addxtype(cfg);
132     
133     }
134 });