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     initEvents: function() 
84     {
85         this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
86         this.textEl = this.el.select('.roo-navigation-bar-item-text', true).first();
87         
88         if(Roo.isTouch){
89             this.textEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
90         }
91         
92         this.iconEl.on('click', this.onClick, this);
93         
94     },
95     
96     onClick : function(e)
97     {
98         e.preventDefault();
99         
100         if(this.disabled){
101             return;
102         }
103         
104         this.parent().setActiveItem(this);
105         
106         this.fireEvent('click', this, e);
107     },
108     
109     isActive: function () 
110     {
111         return this.active;
112     },
113     
114     setActive : function(state)
115     {
116         if(this.active == state){
117             return;
118         }
119         
120         this.active = state;
121         
122         if (this.el.hasClass('active')) {
123             this.el.removeClass('active');
124         }
125         
126         if (state) {
127             this.el.addClass('active');
128         }
129         
130         return;
131     }
132     
133     
134     
135 //    
136 //    onClick : function(e)
137 //    {
138 //        if(
139 //                this.preventDefault || 
140 //                this.href == '#' 
141 //        ){
142 //            
143 //            e.preventDefault();
144 //        }
145 //        
146 //        if (this.disabled) {
147 //            return;
148 //        }
149 //        
150 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
151 //        if (tg && tg.transition) {
152 //            Roo.log("waiting for the transitionend");
153 //            return;
154 //        }
155 //        
156 //        
157 //        
158 //        //Roo.log("fire event clicked");
159 //        if(this.fireEvent('click', this, e) === false){
160 //            return;
161 //        };
162 //        
163 //        if(this.tagtype == 'span'){
164 //            return;
165 //        }
166 //        
167 //        //Roo.log(this.href);
168 //        var ael = this.el.select('a',true).first();
169 //        //Roo.log(ael);
170 //        
171 //        if(ael && this.animateRef && this.href.indexOf('#') > -1){
172 //            //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
173 //            if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
174 //                return; // ignore... - it's a 'hash' to another page.
175 //            }
176 //            
177 //            e.preventDefault();
178 //            this.scrollToElement(e);
179 //        }
180 //        
181 //        
182 //        var p =  this.parent();
183 //   
184 //        if (['tabs','pills'].indexOf(p.type)!==-1) {
185 //            if (typeof(p.setActiveItem) !== 'undefined') {
186 //                p.setActiveItem(this);
187 //            }
188 //        }
189 //        
190 //        // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
191 //        if (p.parentType == 'NavHeaderbar' && !this.menu) {
192 //            // remove the collapsed menu expand...
193 //            p.parent().el.select('.navbar-collapse',true).removeClass('in');  
194 //        }
195 //    },
196 //    
197 //    isActive: function () {
198 //        return this.active
199 //    },
200 //    setActive : function(state, fire, is_was_active)
201 //    {
202 //        if (this.active && !state && this.navId) {
203 //            this.was_active = true;
204 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
205 //            if (nv) {
206 //                nv.clearWasActive(this);
207 //            }
208 //            
209 //        }
210 //        this.active = state;
211 //        
212 //        if (!state ) {
213 //            this.el.removeClass('active');
214 //        } else if (!this.el.hasClass('active')) {
215 //            this.el.addClass('active');
216 //        }
217 //        if (fire) {
218 //            this.fireEvent('changed', this, state);
219 //        }
220 //        
221 //        // show a panel if it's registered and related..
222 //        
223 //        if (!this.navId || !this.tabId || !state || is_was_active) {
224 //            return;
225 //        }
226 //        
227 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
228 //        if (!tg) {
229 //            return;
230 //        }
231 //        var pan = tg.getPanelByName(this.tabId);
232 //        if (!pan) {
233 //            return;
234 //        }
235 //        // if we can not flip to new panel - go back to old nav highlight..
236 //        if (false == tg.showPanel(pan)) {
237 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
238 //            if (nv) {
239 //                var onav = nv.getWasActive();
240 //                if (onav) {
241 //                    onav.setActive(true, false, true);
242 //                }
243 //            }
244 //            
245 //        }
246 //        
247 //        
248 //      
249 //    },
250 //     // this should not be here...
251 //    setDisabled : function(state)
252 //    {
253 //        this.disabled = state;
254 //        if (!state ) {
255 //            this.el.removeClass('disabled');
256 //        } else if (!this.el.hasClass('disabled')) {
257 //            this.el.addClass('disabled');
258 //        }
259 //        
260 //    },
261 //    
262 //    /**
263 //     * Fetch the element to display the tooltip on.
264 //     * @return {Roo.Element} defaults to this.el
265 //     */
266 //    tooltipEl : function()
267 //    {
268 //        return this.el.select('' + this.tagtype + '', true).first();
269 //    },
270 //    
271 //    scrollToElement : function(e)
272 //    {
273 //        var c = document.body;
274 //        
275 //        /*
276 //         * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
277 //         */
278 //        if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
279 //            c = document.documentElement;
280 //        }
281 //        
282 //        var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
283 //        
284 //        if(!target){
285 //            return;
286 //        }
287 //
288 //        var o = target.calcOffsetsTo(c);
289 //        
290 //        var options = {
291 //            target : target,
292 //            value : o[1]
293 //        }
294 //        
295 //        this.fireEvent('scrollto', this, options, e);
296 //        
297 //        Roo.get(c).scrollTo('top', options.value, true);
298 //        
299 //        return;
300 //    }
301 });
302  
303
304