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