Fix #6464 - card header
[roojs1] / Roo / bootstrap / MessageBar.js
1 /*
2  * - LGPL
3  *
4  * element
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.MessageBar
10  * @extends Roo.bootstrap.Component
11  * Bootstrap MessageBar class
12  * @cfg {String} html contents of the MessageBar
13  * @cfg {String} weight (info | success | warning | danger) default info
14  * @cfg {String} beforeClass insert the bar before the given class
15  * @cfg {Boolean} closable (true | false) default false
16  * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
17  * 
18  * @constructor
19  * Create a new Element
20  * @param {Object} config The config object
21  */
22
23 Roo.bootstrap.MessageBar = function(config){
24     Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
25 };
26
27 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component,  {
28     
29     html: '',
30     weight: 'info',
31     closable: false,
32     fixed: false,
33     beforeClass: 'bootstrap-sticky-wrap',
34     
35     getAutoCreate : function(){
36         
37         var cfg = {
38             tag: 'div',
39             cls: 'alert alert-dismissable alert-' + this.weight,
40             cn: [
41                 {
42                     tag: 'span',
43                     cls: 'message',
44                     html: this.html || ''
45                 }
46             ]
47         };
48         
49         if(this.fixed){
50             cfg.cls += ' alert-messages-fixed';
51         }
52         
53         if(this.closable){
54             cfg.cn.push({
55                 tag: 'button',
56                 cls: 'close',
57                 html: 'x'
58             });
59         }
60         
61         return cfg;
62     },
63     
64     onRender : function(ct, position)
65     {
66         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
67         
68         if(!this.el){
69             var cfg = Roo.apply({},  this.getAutoCreate());
70             cfg.id = Roo.id();
71             
72             if (this.cls) {
73                 cfg.cls += ' ' + this.cls;
74             }
75             if (this.style) {
76                 cfg.style = this.style;
77             }
78             this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
79             
80             this.el.setVisibilityMode(Roo.Element.DISPLAY);
81         }
82         
83         this.el.select('>button.close').on('click', this.hide, this);
84         
85     },
86     
87     show : function()
88     {
89         if (!this.rendered) {
90             this.render();
91         }
92         
93         this.el.show();
94         
95         this.fireEvent('show', this);
96         
97     },
98     
99     hide : function()
100     {
101         if (!this.rendered) {
102             this.render();
103         }
104         
105         this.el.hide();
106         
107         this.fireEvent('hide', this);
108     },
109     
110     update : function()
111     {
112 //        var e = this.el.dom.firstChild;
113 //        
114 //        if(this.closable){
115 //            e = e.nextSibling;
116 //        }
117 //        
118 //        e.data = this.html || '';
119
120         this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
121     }
122    
123 });
124
125  
126
127