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  * 
16  * @constructor
17  * Create a new Element
18  * @param {Object} config The config object
19  */
20
21 Roo.bootstrap.MessageBar = function(config){
22     Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
23 };
24
25 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component,  {
26     
27     html: '',
28     weight: 'info',
29     closable: true,
30     
31     getAutoCreate : function(){
32         
33         var cfg = {
34             tag: 'div',
35             cls: 'alert alert-dismissable alert-messages alert-' + this.weight,
36             html: this.html || ''
37         }
38         
39         if(this.closable){
40             cfg.cn = {
41                 tag: 'button',
42                 cls: 'close',
43                 html: 'x'
44             }
45         }
46         
47         return cfg;
48     },
49     
50     onRender : function(ct, position)
51     {
52         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
53         
54         if(!this.el){
55             var cfg = Roo.apply({},  this.getAutoCreate());
56             cfg.id = Roo.id();
57             //if(!cfg.name){
58             //    cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
59             //}
60             //if (!cfg.name.length) {
61             //    delete cfg.name;
62            // }
63             if (this.cls) {
64                 cfg.cls += ' ' + this.cls;
65             }
66             if (this.style) {
67                 cfg.style = this.style;
68             }
69 //            this.el = Roo.get(document.body).createChild(cfg, position);
70             this.el = Roo.select('.bootstrap-sticky-wrap', true).first().createChild(cfg, position);
71         }
72         
73         this.el.select('>button.close').on('click', this.hide, this);
74     },
75     
76     show : function()
77     {
78         if (!this.rendered) {
79             this.render();
80         }
81     },
82     
83     hide : function()
84     {
85         this.el.hide();
86     }
87    
88 });
89
90  
91
92