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         Roo.log(this);
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         Roo.log(this.layout);
81         var reg = false;
82         for (var r in this.layout.regions) {
83             reg = this.layout.getRegion(r);
84             Roo.log(reg);
85             if (reg.getActivePanel()) {
86                 Roo.log('Active Panel????????????????????????????');
87                 //reg.showPanel(reg.getActivePanel()); // force it to activate.. 
88                 reg.setActivePanel(reg.getActivePanel());
89                 continue;
90             }
91             Roo.log(reg.panels.length);
92             if (!reg.panels.length) {
93                 continue;
94             }
95             reg.showPanel(reg.getPanel(0));
96         }
97         
98         
99         
100         
101     },
102     
103     /**
104      * Returns the nested BorderLayout for this panel
105      * @return {Roo.BorderLayout} 
106      */
107     getLayout : function(){
108         return this.layout;
109     },
110     
111      /**
112      * Adds a xtype elements to the layout of the nested panel
113      * <pre><code>
114
115 panel.addxtype({
116        xtype : 'ContentPanel',
117        region: 'west',
118        items: [ .... ]
119    }
120 );
121
122 panel.addxtype({
123         xtype : 'NestedLayoutPanel',
124         region: 'west',
125         layout: {
126            center: { },
127            west: { }   
128         },
129         items : [ ... list of content panels or nested layout panels.. ]
130    }
131 );
132 </code></pre>
133      * @param {Object} cfg Xtype definition of item to add.
134      */
135     addxtype : function(cfg) {
136         return this.layout.addxtype(cfg);
137     
138     }
139 });