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