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 {Boolean} active (true|false) Is item active default false
13  * @cfg {Boolean} disabled (true|false) Is item active default false
14  * @cfg {String} html
15  * @cfg {String} position (top|bottom) text position default bottom
16  * @cfg {String} icon show icon instead of number
17  * @cfg {Boolean} forceIcon (true|false) true to force show icon..if set to false, Roo.isTouch showing icon, otherwish number
18  * 
19  * @constructor
20  * Create a new NavProgressItem
21  * @param {Object} config The config object
22  */
23 Roo.bootstrap.NavProgressItem = function(config){
24     Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
25     this.addEvents({
26         // raw events
27         /**
28          * @event click
29          * The raw click event for the entire grid.
30          * @param {Roo.bootstrap.NavProgressItem} this
31          * @param {Roo.EventObject} e
32          */
33         "click" : true
34     });
35    
36 };
37
38 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component,  {
39     
40     active : false,
41     disabled : false,
42     html : '',
43     position : 'bottom',
44     icon : false,
45     forceIcon : false,
46     
47     getAutoCreate : function()
48     {
49         var iconCls = 'roo-navigation-bar-item-icon';
50         
51         if((this.forceIcon && this.icon) || !this.forceIcon && Roo.isTouch){
52             iconCls += ' ' + this.icon;
53         }
54         
55         var cfg = {
56             tag: 'li',
57             cls: 'roo-navigation-bar-item',
58             cn : [
59                 {
60                     tag : 'i',
61                     cls : iconCls
62                 },
63                 {
64                     tag : 'span',
65                     cls : 'roo-navigation-bar-item-text ' + this.position,
66                     html : this.html
67                 }
68             ]
69         }
70         
71         if(this.active){
72             cfg.cls += ' active';
73         }
74         if(this.disabled){
75             cfg.cls += ' disabled';
76         }
77         
78         return cfg;
79     },
80     
81     initEvents: function() 
82     {
83         this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
84         this.textEl = this.el.select('.roo-navigation-bar-item-text', true).first();
85         
86         if(Roo.isTouch){
87             this.textEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
88         }
89         
90         this.iconEl.on('click', this.onClick, this);
91         
92     },
93     
94     onClick : function(e)
95     {
96         e.preventDefault();
97         
98         if(this.disabled){
99             return;
100         }
101         
102         Roo.log(this.parent());
103         
104         Roo.log(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         // show a panel if it's registered and related..
131         
132         if (!this.navId || !this.tabId || !state || is_was_active) {
133             return;
134         }
135         
136         var tg = Roo.bootstrap.TabGroup.get(this.navId);
137         if (!tg) {
138             return;
139         }
140         var pan = tg.getPanelByName(this.tabId);
141         if (!pan) {
142             return;
143         }
144         // if we can not flip to new panel - go back to old nav highlight..
145         if (false == tg.showPanel(pan)) {
146             var nv = Roo.bootstrap.NavGroup.get(this.navId);
147             if (nv) {
148                 var onav = nv.getWasActive();
149                 if (onav) {
150                     onav.setActive(true, false, true);
151                 }
152             }
153             
154         }
155         
156         
157         
158     }
159     
160     
161     
162 //    
163 //    onClick : function(e)
164 //    {
165 //        if(
166 //                this.preventDefault || 
167 //                this.href == '#' 
168 //        ){
169 //            
170 //            e.preventDefault();
171 //        }
172 //        
173 //        if (this.disabled) {
174 //            return;
175 //        }
176 //        
177 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
178 //        if (tg && tg.transition) {
179 //            Roo.log("waiting for the transitionend");
180 //            return;
181 //        }
182 //        
183 //        
184 //        
185 //        //Roo.log("fire event clicked");
186 //        if(this.fireEvent('click', this, e) === false){
187 //            return;
188 //        };
189 //        
190 //        if(this.tagtype == 'span'){
191 //            return;
192 //        }
193 //        
194 //        //Roo.log(this.href);
195 //        var ael = this.el.select('a',true).first();
196 //        //Roo.log(ael);
197 //        
198 //        if(ael && this.animateRef && this.href.indexOf('#') > -1){
199 //            //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
200 //            if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
201 //                return; // ignore... - it's a 'hash' to another page.
202 //            }
203 //            
204 //            e.preventDefault();
205 //            this.scrollToElement(e);
206 //        }
207 //        
208 //        
209 //        var p =  this.parent();
210 //   
211 //        if (['tabs','pills'].indexOf(p.type)!==-1) {
212 //            if (typeof(p.setActiveItem) !== 'undefined') {
213 //                p.setActiveItem(this);
214 //            }
215 //        }
216 //        
217 //        // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
218 //        if (p.parentType == 'NavHeaderbar' && !this.menu) {
219 //            // remove the collapsed menu expand...
220 //            p.parent().el.select('.navbar-collapse',true).removeClass('in');  
221 //        }
222 //    },
223 //    
224 //    isActive: function () {
225 //        return this.active
226 //    },
227 //    setActive : function(state, fire, is_was_active)
228 //    {
229 //        if (this.active && !state && this.navId) {
230 //            this.was_active = true;
231 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
232 //            if (nv) {
233 //                nv.clearWasActive(this);
234 //            }
235 //            
236 //        }
237 //        this.active = state;
238 //        
239 //        if (!state ) {
240 //            this.el.removeClass('active');
241 //        } else if (!this.el.hasClass('active')) {
242 //            this.el.addClass('active');
243 //        }
244 //        if (fire) {
245 //            this.fireEvent('changed', this, state);
246 //        }
247 //        
248 //        // show a panel if it's registered and related..
249 //        
250 //        if (!this.navId || !this.tabId || !state || is_was_active) {
251 //            return;
252 //        }
253 //        
254 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
255 //        if (!tg) {
256 //            return;
257 //        }
258 //        var pan = tg.getPanelByName(this.tabId);
259 //        if (!pan) {
260 //            return;
261 //        }
262 //        // if we can not flip to new panel - go back to old nav highlight..
263 //        if (false == tg.showPanel(pan)) {
264 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
265 //            if (nv) {
266 //                var onav = nv.getWasActive();
267 //                if (onav) {
268 //                    onav.setActive(true, false, true);
269 //                }
270 //            }
271 //            
272 //        }
273 //        
274 //        
275 //      
276 //    },
277 //     // this should not be here...
278 //    setDisabled : function(state)
279 //    {
280 //        this.disabled = state;
281 //        if (!state ) {
282 //            this.el.removeClass('disabled');
283 //        } else if (!this.el.hasClass('disabled')) {
284 //            this.el.addClass('disabled');
285 //        }
286 //        
287 //    },
288 //    
289 //    /**
290 //     * Fetch the element to display the tooltip on.
291 //     * @return {Roo.Element} defaults to this.el
292 //     */
293 //    tooltipEl : function()
294 //    {
295 //        return this.el.select('' + this.tagtype + '', true).first();
296 //    },
297 //    
298 //    scrollToElement : function(e)
299 //    {
300 //        var c = document.body;
301 //        
302 //        /*
303 //         * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
304 //         */
305 //        if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
306 //            c = document.documentElement;
307 //        }
308 //        
309 //        var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
310 //        
311 //        if(!target){
312 //            return;
313 //        }
314 //
315 //        var o = target.calcOffsetsTo(c);
316 //        
317 //        var options = {
318 //            target : target,
319 //            value : o[1]
320 //        }
321 //        
322 //        this.fireEvent('scrollto', this, options, e);
323 //        
324 //        Roo.get(c).scrollTo('top', options.value, true);
325 //        
326 //        return;
327 //    }
328 });
329  
330
331