Roo/bootstrap/Container.js
[roojs1] / Roo / bootstrap / Container.js
1 /*
2  * - LGPL
3  *
4  * page container.
5  * 
6  */
7
8
9 /**
10  * @class Roo.bootstrap.Container
11  * @extends Roo.bootstrap.Component
12  * Bootstrap Container class
13  * @cfg {Boolean} jumbotron is it a jumbotron element
14  * @cfg {String} html content of element
15  * @cfg {String} well (lg|sm|md) a well, large, small or medium.
16  * @cfg {String} panel (primary|success|info|warning|danger) render as a panel.
17  * @cfg {String} header content of header (for panel)
18  * @cfg {String} footer content of footer (for panel)
19  * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
20  * @cfg {String} tag (header|aside|section) type of HTML tag.
21  * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
22  * @cfg {String} fa (ban|check|...) font awesome icon
23  * @cfg {String} icon (info-sign|check|...) glyphicon name
24  * @cfg {Boolean} hidden (true|false) hide the element
25  * @cfg {Boolean} expandable (true|false) default false
26  * @cfg {Boolean} expanded (true|false) default true
27  * @cfg {String} rheader contet on the right of header
28
29  *     
30  * @constructor
31  * Create a new Container
32  * @param {Object} config The config object
33  */
34
35 Roo.bootstrap.Container = function(config){
36     Roo.bootstrap.Container.superclass.constructor.call(this, config);
37     
38     this.addEvents({
39         // raw events
40          /**
41          * @event expand
42          * After the panel has been expand
43          * 
44          * @param {Roo.bootstrap.Container} this
45          */
46         "expand" : true,
47         /**
48          * @event collapse
49          * After the panel has been collapsed
50          * 
51          * @param {Roo.bootstrap.Container} this
52          */
53         "collapse" : true
54     });
55 };
56
57 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component,  {
58     
59     jumbotron : false,
60     well: '',
61     panel : '',
62     header: '',
63     footer : '',
64     sticky: '',
65     tag : false,
66     alert : false,
67     fa: false,
68     icon : false,
69     expandable : false,
70     rheader : '',
71     expanded : true,
72   
73      
74     getChildContainer : function() {
75         
76         if(!this.el){
77             return false;
78         }
79         
80         if (this.panel.length) {
81             return this.el.select('.panel-body',true).first();
82         }
83         
84         return this.el;
85     },
86     
87     
88     getAutoCreate : function(){
89         
90         var cfg = {
91             tag : this.tag || 'div',
92             html : '',
93             cls : ''
94         };
95         if (this.jumbotron) {
96             cfg.cls = 'jumbotron';
97         }
98         
99         
100         
101         // - this is applied by the parent..
102         //if (this.cls) {
103         //    cfg.cls = this.cls + '';
104         //}
105         
106         if (this.sticky.length) {
107             
108             var bd = Roo.get(document.body);
109             if (!bd.hasClass('bootstrap-sticky')) {
110                 bd.addClass('bootstrap-sticky');
111                 Roo.select('html',true).setStyle('height', '100%');
112             }
113              
114             cfg.cls += 'bootstrap-sticky-' + this.sticky;
115         }
116         
117         
118         if (this.well.length) {
119             switch (this.well) {
120                 case 'lg':
121                 case 'sm':
122                     cfg.cls +=' well well-' +this.well;
123                     break;
124                 default:
125                     cfg.cls +=' well';
126                     break;
127             }
128         }
129         
130         if (this.hidden) {
131             cfg.cls += ' hidden';
132         }
133         
134         
135         if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
136             cfg.cls +=' alert alert-' + this.alert;
137         }
138         
139         var body = cfg;
140         
141         if (this.panel.length) {
142             cfg.cls += ' panel panel-' + this.panel;
143             cfg.cn = [];
144             if (this.header.length) {
145                 
146                 var h = [];
147                 
148                 if(this.expandable){
149                     
150                     cfg.cls = cfg.cls + ' expandable';
151                     
152                     h.push({
153                         tag: 'i',
154                         cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus') 
155                     });
156                     
157                 }
158                 
159                 h.push(
160                     {
161                         tag: 'span',
162                         cls : 'panel-title',
163                         html : (this.expandable ? ' ' : '') + this.header
164                     },
165                     {
166                         tag: 'span',
167                         cls: 'panel-header-right',
168                         html: this.rheader
169                     }
170                 );
171                 
172                 cfg.cn.push({
173                     cls : 'panel-heading',
174                     cn : h
175                 });
176                 
177             }
178             
179             body = false;
180             cfg.cn.push({
181                 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
182                 html : this.html
183             });
184             
185             
186             if (this.footer.length) {
187                 cfg.cn.push({
188                     cls : 'panel-footer',
189                     html : this.footer
190                     
191                 });
192             }
193             
194         }
195         
196         if (body) {
197             body.html = this.html || cfg.html;
198             // prefix with the icons..
199             if (this.fa) {
200                 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
201             }
202             if (this.icon) {
203                 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
204             }
205             
206             
207         }
208         if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
209             cfg.cls =  'container';
210         }
211         
212         return cfg;
213     },
214     
215     initEvents: function() 
216     {
217         if(!this.expandable){
218             return;
219         }
220         
221         var headerEl = this.headerEl();
222         
223         if(!headerEl){
224             return;
225         }
226         
227         headerEl.on('click', this.onToggleClick, this);
228         
229     },
230     
231     onToggleClick : function()
232     {
233         var headerEl = this.headerEl();
234         
235         if(!headerEl){
236             return;
237         }
238         
239         if(this.expanded){
240             this.collapse();
241             return;
242         }
243         
244         this.expand();
245     },
246     
247     expand : function()
248     {
249         if(this.fireEvent('expand', this)) {
250             
251             this.expanded = true;
252             
253             //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
254             
255             this.el.select('.panel-body',true).first().removeClass('hide');
256             
257             var toggleEl = this.toggleEl();
258
259             if(!toggleEl){
260                 return;
261             }
262
263             toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
264         }
265         
266     },
267     
268     collapse : function()
269     {
270         if(this.fireEvent('collapse', this)) {
271             
272             this.expanded = false;
273             
274             //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
275             this.el.select('.panel-body',true).first().addClass('hide');
276         
277             var toggleEl = this.toggleEl();
278
279             if(!toggleEl){
280                 return;
281             }
282
283             toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
284         }
285     },
286     
287     toggleEl : function()
288     {
289         if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
290             return;
291         }
292         
293         return this.el.select('.panel-heading .fa',true).first();
294     },
295     
296     headerEl : function()
297     {
298         if(!this.el || !this.panel.length || !this.header.length){
299             return;
300         }
301         
302         return this.el.select('.panel-heading',true).first()
303     },
304     
305     titleEl : function()
306     {
307         if(!this.el || !this.panel.length || !this.header.length){
308             return;
309         }
310         
311         return this.el.select('.panel-title',true).first();
312     },
313     
314     setTitle : function(v)
315     {
316         var titleEl = this.titleEl();
317         
318         if(!titleEl){
319             return;
320         }
321         
322         titleEl.dom.innerHTML = v;
323     },
324     
325     getTitle : function()
326     {
327         
328         var titleEl = this.titleEl();
329         
330         if(!titleEl){
331             return '';
332         }
333         
334         return titleEl.dom.innerHTML;
335     },
336     
337     setRightTitle : function(v)
338     {
339         var t = this.el.select('.panel-header-right',true).first();
340         
341         if(!t){
342             return;
343         }
344         
345         t.dom.innerHTML = v;
346     }
347    
348 });
349
350