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