Roo/bootstrap/NavSidebarItem.js
[roojs1] / Roo / bootstrap / NavSidebarItem.js
1 /*
2  * - LGPL
3  *
4  * sidebar item
5  *
6  *  li
7  *    <span> icon </span>
8  *    <span> text </span>
9  *    <span>badge </span>
10  */
11
12 /**
13  * @class Roo.bootstrap.NavSidebarItem
14  * @extends Roo.bootstrap.NavItem
15  * Bootstrap Navbar.NavSidebarItem class
16  * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
17  * @constructor
18  * Create a new Navbar Button
19  * @param {Object} config The config object
20  */
21 Roo.bootstrap.NavSidebarItem = function(config){
22     Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
23     this.addEvents({
24         // raw events
25         /**
26          * @event click
27          * The raw click event for the entire grid.
28          * @param {Roo.EventObject} e
29          */
30         "click" : true,
31          /**
32             * @event changed
33             * Fires when the active item active state changes
34             * @param {Roo.bootstrap.NavSidebarItem} this
35             * @param {boolean} state the new state
36              
37          */
38         'changed': true
39     });
40    
41 };
42
43 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem,  {
44     
45     badgeWeight : 'default',
46     
47     getAutoCreate : function(){
48         
49         
50         var a = {
51                 tag: 'a',
52                 href : this.href || '#',
53                 cls: '',
54                 html : '',
55                 cn : []
56         };
57         var cfg = {
58             tag: 'li',
59             cls: '',
60             cn: [ a ]
61         };
62         var span = {
63             tag: 'span',
64             html : this.html || ''
65         };
66         
67         
68         if (this.active) {
69             cfg.cls += ' active';
70         }
71         
72         if (this.disabled) {
73             cfg.cls += ' disabled';
74         }
75         
76         // left icon..
77         if (this.glyphicon || this.icon) {
78             var c = this.glyphicon  ? ('glyphicon glyphicon-'+this.glyphicon)  : this.icon;
79             a.cn.push({ tag : 'i', cls : c }) ;
80         }
81         // html..
82         a.cn.push(span);
83         // then badge..
84         if (this.badge !== '') {
85             
86             a.cn.push({ tag: 'span',  cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge }); 
87         }
88         // fi
89         if (this.menu) {
90             a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
91             a.cls += 'dropdown-toggle treeview' ;
92             
93         }
94         
95         
96         
97         return cfg;
98          
99            
100     },
101   
102     
103     onClick : function(e)
104     {
105         if(this.disabled){
106             e.preventDefault();
107             return;
108         }
109         
110         if(this.preventDefault){
111             e.preventDefault();
112         }
113         
114         this.fireEvent('click', this);
115     },
116     
117     disable : function()
118     {
119         this.setDisabled(true);
120     },
121     
122     enable : function()
123     {
124         this.setDisabled(false);
125     },
126     
127     setDisabled : function(state)
128     {
129         if(this.disabled == state){
130             return;
131         }
132         
133         this.disabled = state;
134         
135         if (state) {
136             this.el.addClass('disabled');
137             return;
138         }
139         
140         this.el.removeClass('disabled');
141         
142         return;
143     },
144     
145     setActive : function(state)
146     {
147         if(this.active == state){
148             return;
149         }
150         
151         this.active = state;
152         
153         if (state) {
154             this.el.addClass('active');
155             return;
156         }
157         
158         this.el.removeClass('active');
159         
160         return;
161     },
162     
163     isActive: function () 
164     {
165         return this.active;
166     },
167     
168     setBadge : function(str)
169     {
170         if(!this.badgeEl){
171             return;
172         }
173         
174         this.badgeEl.dom.innerHTML = str;
175     },
176     
177    
178       
179     initEvents : function()
180     { 
181         this.el.on('click', this.onClick, this);
182        
183     
184         if(this.badge !== ''){
185  
186             this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
187         }
188         
189     }
190  
191 });
192  
193
194