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: 'fa fa-minus'
155                     });
156                 }
157                 
158                 h.push(
159                     {
160                         tag: 'span',
161                         cls : 'panel-title',
162                         html : this.header
163                     },
164                     {
165                         tag: 'span',
166                         cls: 'panel-header-right',
167                         html: this.rheader
168                     }
169                 );
170                 
171                 cfg.cn.push({
172                     cls : 'panel-heading',
173                     cn : h
174                 });
175                 
176             }
177             
178             body = false;
179             cfg.cn.push({
180                 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
181                 html : this.html
182             });
183             
184             
185             if (this.footer.length) {
186                 cfg.cn.push({
187                     cls : 'panel-footer',
188                     html : this.footer
189                     
190                 });
191             }
192             
193         }
194         
195         if (body) {
196             body.html = this.html || cfg.html;
197             // prefix with the icons..
198             if (this.fa) {
199                 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
200             }
201             if (this.icon) {
202                 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
203             }
204             
205             
206         }
207         if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
208             cfg.cls =  'container';
209         }
210         
211         return cfg;
212     },
213     
214     initEvents: function() 
215     {
216         if(!this.expandable){
217             return;
218         }
219         
220         var headerEl = this.headerEl();
221         
222         if(!headerEl){
223             return;
224         }
225         
226         headerEl.on('click', this.onToggleClick, this);
227         
228     },
229     
230     onToggleClick : function()
231     {
232         var headerEl = this.headerEl();
233         
234         if(!headerEl){
235             return;
236         }
237         
238         if(this.expanded){
239             this.collapse();
240             return;
241         }
242         
243         this.expand();
244     },
245     
246     expand : function()
247     {
248         if(this.fireEvent('expand', this)) {
249             
250             this.expanded = true;
251             
252             //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
253             
254             this.el.select('.panel-body',true).first().removeClass('hide');
255             
256             var toggleEl = this.toggleEl();
257
258             if(!toggleEl){
259                 return;
260             }
261
262             toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
263         }
264         
265     },
266     
267     collapse : function()
268     {
269         if(this.fireEvent('collapse', this)) {
270             
271             this.expanded = false;
272             
273             //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
274             this.el.select('.panel-body',true).first().addClass('hide');
275         
276             var toggleEl = this.toggleEl();
277
278             if(!toggleEl){
279                 return;
280             }
281
282             toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
283         }
284     },
285     
286     toggleEl : function()
287     {
288         if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
289             return;
290         }
291         
292         return this.el.select('.panel-heading .fa',true).first();
293     },
294     
295     headerEl : function()
296     {
297         if(!this.el || !this.panel.length || !this.header.length){
298             return;
299         }
300         
301         return this.el.select('.panel-heading',true).first()
302     },
303     
304     titleEl : function()
305     {
306         if(!this.el || !this.panel.length || !this.header.length){
307             return;
308         }
309         
310         return this.el.select('.panel-title',true).first();
311     },
312     
313     setTitle : function(v)
314     {
315         var titleEl = this.titleEl();
316         
317         if(!titleEl){
318             return;
319         }
320         
321         titleEl.dom.innerHTML = v;
322     },
323     
324     getTitle : function()
325     {
326         
327         var titleEl = this.titleEl();
328         
329         if(!titleEl){
330             return '';
331         }
332         
333         return titleEl.dom.innerHTML;
334     },
335     
336     setRightTitle : function(v)
337     {
338         var t = this.el.select('.panel-header-right',true).first();
339         
340         if(!t){
341             return;
342         }
343         
344         t.dom.innerHTML = v;
345     }
346    
347 });
348
349