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             cn: [
37                 {
38                     tag: 'div',
39                     cls: 'message',
40                     html: this.html || ''
41                 }
42             ]
43         }
44         
45         if(this.closable){
46             cfg.cn.push({
47                 tag: 'button',
48                 cls: 'close',
49                 html: 'x'
50             });
51         }
52         
53         return cfg;
54     },
55     
56     onRender : function(ct, position)
57     {
58         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
59         
60         if(!this.el){
61             var cfg = Roo.apply({},  this.getAutoCreate());
62             cfg.id = Roo.id();
63             //if(!cfg.name){
64             //    cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
65             //}
66             //if (!cfg.name.length) {
67             //    delete cfg.name;
68            // }
69             if (this.cls) {
70                 cfg.cls += ' ' + this.cls;
71             }
72             if (this.style) {
73                 cfg.style = this.style;
74             }
75             this.el = Roo.get(document.body).createChild(cfg, position);
76         }
77         
78         this.el.select('>button.close').on('click', this.hide, this);
79         
80     },
81     
82     show : function()
83     {
84         if (!this.rendered) {
85             this.render();
86         }
87         
88         Roo.select('.bootstrap-sticky-wrap', true).first().setStyle('margin-top', this.el.getHeight() + 'px');
89         
90         var navbar_fixed_top = Roo.select('.navbar-fixed-top', true).first();
91         
92         if(navbar_fixed_top != null){
93             navbar_fixed_top.setStyle('margin-top', this.el.getHeight() + 'px');
94         }
95         
96     },
97     
98     hide : function()
99     {
100         this.el.hide();
101         
102         Roo.select('.bootstrap-sticky-wrap', true).first().setStyle('margin-top', '0px');
103         
104         var navbar_fixed_top = Roo.select('.navbar-fixed-top', true).first();
105         
106         if(navbar_fixed_top != null){
107             navbar_fixed_top.setStyle('margin-top', '0px');
108         }
109     }
110    
111 });
112
113  
114
115