Roo/bootstrap/Alert.js
[roojs1] / Roo / bootstrap / Alert.js
1 /*
2  * - LGPL
3  *
4  * Alert
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.Alert
10  * @extends Roo.bootstrap.Component
11  * Bootstrap Alert class
12  * @cfg {String} title The title of alert
13  * @cfg {String} html The content of alert
14  * @cfg {String} weight (  success | info | warning | danger )
15  * @cfg {String} faicon font-awesomeicon
16  * 
17  * @constructor
18  * Create a new alert
19  * @param {Object} config The config object
20  */
21
22
23 Roo.bootstrap.Alert = function(config){
24     Roo.bootstrap.Alert.superclass.constructor.call(this, config);
25     
26 };
27
28 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component,  {
29     
30     title: '',
31     html: '',
32     weight: false,
33     faicon: false,
34     
35     getAutoCreate : function()
36     {
37         
38         var cfg = {
39             tag : 'div',
40             cls : 'alert',
41             cn : [
42                 {
43                     tag : 'i',
44                     cls : 'roo-alert-icon'
45                     
46                 },
47                 {
48                     tag : 'b',
49                     cls : 'roo-alert-title',
50                     html : this.title
51                 },
52                 {
53                     tag : 'span',
54                     cls : 'roo-alert-text',
55                     html : this.html
56                 }
57             ]
58         };
59         
60         if(this.faicon){
61             cfg.cn[0].cls += ' fa ' + this.faicon;
62         }
63         
64         if(this.weight){
65             cfg.cls += ' alert-' + this.weight;
66         }
67         
68         return cfg;
69     },
70     
71     initEvents: function() 
72     {
73         this.el.setVisibilityMode(Roo.Element.DISPLAY);
74     },
75     
76     setTitle : function(str)
77     {
78         this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
79     },
80     
81     setText : function(str)
82     {
83         this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
84     },
85     
86     setWeight : function(weight)
87     {
88         if(this.weight){
89             this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
90         }
91         
92         this.weight = weight;
93         
94         this.el.select('.alert',true).first().addClass('alert-' + this.weight);
95     },
96     
97     setIcon : function(icon)
98     {
99         if(this.faicon){
100             this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
101         }
102         
103         this.faicon = icon;
104         
105         this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
106     },
107     
108     hide: function() 
109     {
110         this.el.hide();   
111     },
112     
113     show: function() 
114     {  
115         this.el.show();   
116     }
117     
118 });
119
120