610e8de947412d417e1fc90c0b70f1831b4f2b60
[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         this.setActiveClass(active);
66         
67         if(!active){
68             this.fireEvent("deactivate", this);
69             return;
70         }
71         
72         this.fireEvent("activate", this);
73         // not sure if this should happen before or after..
74         if (!this.layout) {
75             return; // should not happen..
76         }
77         var reg = false;
78         for (var r in this.layout.regions) {
79             reg = this.layout.getRegion(r);
80             if (reg.getActivePanel()) {
81                 //reg.showPanel(reg.getActivePanel()); // force it to activate.. 
82                 reg.setActivePanel(reg.getActivePanel());
83                 continue;
84             }
85             if (!reg.panels.length) {
86                 continue;
87             }
88             reg.showPanel(reg.getPanel(0));
89         }
90         
91         
92         
93         
94     },
95     
96     /**
97      * Returns the nested BorderLayout for this panel
98      * @return {Roo.BorderLayout} 
99      */
100     getLayout : function(){
101         return this.layout;
102     },
103     
104      /**
105      * Adds a xtype elements to the layout of the nested panel
106      * <pre><code>
107
108 panel.addxtype({
109        xtype : 'ContentPanel',
110        region: 'west',
111        items: [ .... ]
112    }
113 );
114
115 panel.addxtype({
116         xtype : 'NestedLayoutPanel',
117         region: 'west',
118         layout: {
119            center: { },
120            west: { }   
121         },
122         items : [ ... list of content panels or nested layout panels.. ]
123    }
124 );
125 </code></pre>
126      * @param {Object} cfg Xtype definition of item to add.
127      */
128     addxtype : function(cfg) {
129         return this.layout.addxtype(cfg);
130     
131     }
132 });