Roo/bootstrap/NavProgressItem.js
[roojs1] / Roo / bootstrap / NavProgressItem.js
1 /*
2  * - LGPL
3  *
4  * Nav Progress Item
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.NavProgressItem
10  * @extends Roo.bootstrap.Component
11  * Bootstrap NavProgressItem class
12  * @cfg {String} rid the reference id
13  * @cfg {Boolean} active (true|false) Is item active default false
14  * @cfg {Boolean} disabled (true|false) Is item active default false
15  * @cfg {String} html
16  * @cfg {String} position (top|bottom) text position default bottom
17  * @cfg {String} icon show icon instead of number
18  * @cfg {Boolean} forceIcon (true|false) true to force show icon..if set to false, Roo.isTouch showing icon, otherwish number
19  * 
20  * @constructor
21  * Create a new NavProgressItem
22  * @param {Object} config The config object
23  */
24 Roo.bootstrap.NavProgressItem = function(config){
25     Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
26     this.addEvents({
27         // raw events
28         /**
29          * @event click
30          * The raw click event for the entire grid.
31          * @param {Roo.bootstrap.NavProgressItem} this
32          * @param {Roo.EventObject} e
33          */
34         "click" : true
35     });
36    
37 };
38
39 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component,  {
40     
41     rid : '',
42     active : false,
43     disabled : false,
44     html : '',
45     position : 'bottom',
46     icon : false,
47     forceIcon : false,
48     
49     getAutoCreate : function()
50     {
51         var iconCls = 'roo-navigation-bar-item-icon';
52         
53         if((this.forceIcon && this.icon) || !this.forceIcon && Roo.isTouch){
54             iconCls += ' ' + this.icon;
55         }
56         
57         var cfg = {
58             tag: 'li',
59             cls: 'roo-navigation-bar-item',
60             cn : [
61                 {
62                     tag : 'i',
63                     cls : iconCls
64                 },
65                 {
66                     tag : 'span',
67                     cls : 'roo-navigation-bar-item-text ' + this.position,
68                     html : this.html
69                 }
70             ]
71         }
72         
73         if(this.active){
74             cfg.cls += ' active';
75         }
76         if(this.disabled){
77             cfg.cls += ' disabled';
78         }
79         
80         return cfg;
81     },
82     
83     disable : function()
84     {
85         this.setDisabled(true);
86     },
87     
88     initEvents: function() 
89     {
90         this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
91         this.textEl = this.el.select('.roo-navigation-bar-item-text', true).first();
92         
93         if(Roo.isTouch){
94             this.textEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
95         }
96         
97         this.iconEl.on('click', this.onClick, this);
98         
99     },
100     
101     onClick : function(e)
102     {
103         e.preventDefault();
104         
105         if(this.disabled){
106             return;
107         }
108         
109         if(this.fireEvent('click', this, e) === false){
110             return;
111         };
112         
113         this.parent().setActiveItem(this);
114     },
115     
116     isActive: function () 
117     {
118         return this.active;
119     },
120     
121     setActive : function(state)
122     {
123         if(this.active == state){
124             return;
125         }
126         
127         this.active = state;
128         
129         if (state) {
130             this.el.addClass('active');
131             return;
132         }
133         
134         this.el.removeClass('active');
135         
136         return;
137     },
138     
139     setDisabled : function(state)
140     {
141         if(this.disabled == state){
142             return;
143         }
144         
145         this.disabled = state;
146         
147         if (state) {
148             this.el.addClass('disabled');
149             return;
150         }
151         
152         this.el.removeClass('disabled');
153     },
154     
155     tooltipEl : function()
156     {
157         return this.el.select('.roo-navigation-bar-item-icon', true).first();;
158     }
159 });
160  
161
162