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     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             el.setSize(size.width, size.height);
47             var touch = el.dom.offsetWidth;
48             this.layout.layout();
49             // ie requires a double layout on the first pass
50             if(Roo.isIE && !this.initialized){
51                 this.initialized = true;
52                 this.layout.layout();
53             }
54         }
55     },
56     
57     // activate all subpanels if not currently active..
58     
59     setActiveState : function(active){
60         this.active = active;
61         if(!active){
62             this.fireEvent("deactivate", this);
63             return;
64         }
65         
66         this.fireEvent("activate", this);
67         // not sure if this should happen before or after..
68         if (!this.layout) {
69             return; // should not happen..
70         }
71         var reg = false;
72         for (var r in this.layout.regions) {
73             reg = this.layout.getRegion(r);
74             if (reg.getActivePanel()) {
75                 //reg.showPanel(reg.getActivePanel()); // force it to activate.. 
76                 reg.setActivePanel(reg.getActivePanel());
77                 continue;
78             }
79             if (!reg.panels.length) {
80                 continue;
81             }
82             reg.showPanel(reg.getPanel(0));
83         }
84         
85         
86         
87         
88     },
89     
90     /**
91      * Returns the nested BorderLayout for this panel
92      * @return {Roo.BorderLayout} 
93      */
94     getLayout : function(){
95         return this.layout;
96     },
97     
98      /**
99      * Adds a xtype elements to the layout of the nested panel
100      * <pre><code>
101
102 panel.addxtype({
103        xtype : 'ContentPanel',
104        region: 'west',
105        items: [ .... ]
106    }
107 );
108
109 panel.addxtype({
110         xtype : 'NestedLayoutPanel',
111         region: 'west',
112         layout: {
113            center: { },
114            west: { }   
115         },
116         items : [ ... list of content panels or nested layout panels.. ]
117    }
118 );
119 </code></pre>
120      * @param {Object} cfg Xtype definition of item to add.
121      */
122     addxtype : function(cfg) {
123         return this.layout.addxtype(cfg);
124     
125     }
126 });