better support for mailchimp emails
[roojs1] / Roo / bootstrap / NavProgressBar.js
1 /*
2  * - LGPL
3  *
4  * nav progress bar
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.NavProgressBar
10  * @extends Roo.bootstrap.Component
11  * Bootstrap NavProgressBar class
12  * 
13  * @constructor
14  * Create a new nav progress bar
15  * @param {Object} config The config object
16  */
17
18 Roo.bootstrap.NavProgressBar = function(config){
19     Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
20
21     this.bullets = this.bullets || [];
22    
23 //    Roo.bootstrap.NavProgressBar.register(this);
24      this.addEvents({
25         /**
26              * @event changed
27              * Fires when the active item changes
28              * @param {Roo.bootstrap.NavProgressBar} this
29              * @param {Roo.bootstrap.NavProgressItem} selected The item selected
30              * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item 
31          */
32         'changed': true
33      });
34     
35 };
36
37 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component,  {
38     
39     bullets : [],
40     barItems : [],
41     
42     getAutoCreate : function()
43     {
44         var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
45         
46         cfg = {
47             tag : 'div',
48             cls : 'roo-navigation-bar-group',
49             cn : [
50                 {
51                     tag : 'div',
52                     cls : 'roo-navigation-top-bar'
53                 },
54                 {
55                     tag : 'div',
56                     cls : 'roo-navigation-bullets-bar',
57                     cn : [
58                         {
59                             tag : 'ul',
60                             cls : 'roo-navigation-bar'
61                         }
62                     ]
63                 },
64                 
65                 {
66                     tag : 'div',
67                     cls : 'roo-navigation-bottom-bar'
68                 }
69             ]
70             
71         };
72         
73         return cfg;
74         
75     },
76     
77     initEvents: function() 
78     {
79         
80     },
81     
82     onRender : function(ct, position) 
83     {
84         Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
85         
86         if(this.bullets.length){
87             Roo.each(this.bullets, function(b){
88                this.addItem(b);
89             }, this);
90         }
91         
92         this.format();
93         
94     },
95     
96     addItem : function(cfg)
97     {
98         var item = new Roo.bootstrap.NavProgressItem(cfg);
99         
100         item.parentId = this.id;
101         item.render(this.el.select('.roo-navigation-bar', true).first(), null);
102         
103         if(cfg.html){
104             var top = new Roo.bootstrap.Element({
105                 tag : 'div',
106                 cls : 'roo-navigation-bar-text'
107             });
108             
109             var bottom = new Roo.bootstrap.Element({
110                 tag : 'div',
111                 cls : 'roo-navigation-bar-text'
112             });
113             
114             top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
115             bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
116             
117             var topText = new Roo.bootstrap.Element({
118                 tag : 'span',
119                 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
120             });
121             
122             var bottomText = new Roo.bootstrap.Element({
123                 tag : 'span',
124                 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
125             });
126             
127             topText.onRender(top.el, null);
128             bottomText.onRender(bottom.el, null);
129             
130             item.topEl = top;
131             item.bottomEl = bottom;
132         }
133         
134         this.barItems.push(item);
135         
136         return item;
137     },
138     
139     getActive : function()
140     {
141         var active = false;
142         
143         Roo.each(this.barItems, function(v){
144             
145             if (!v.isActive()) {
146                 return;
147             }
148             
149             active = v;
150             return false;
151             
152         });
153         
154         return active;
155     },
156     
157     setActiveItem : function(item)
158     {
159         var prev = false;
160         
161         Roo.each(this.barItems, function(v){
162             if (v.rid == item.rid) {
163                 return ;
164             }
165             
166             if (v.isActive()) {
167                 v.setActive(false);
168                 prev = v;
169             }
170         });
171
172         item.setActive(true);
173         
174         this.fireEvent('changed', this, item, prev);
175     },
176     
177     getBarItem: function(rid)
178     {
179         var ret = false;
180         
181         Roo.each(this.barItems, function(e) {
182             if (e.rid != rid) {
183                 return;
184             }
185             
186             ret =  e;
187             return false;
188         });
189         
190         return ret;
191     },
192     
193     indexOfItem : function(item)
194     {
195         var index = false;
196         
197         Roo.each(this.barItems, function(v, i){
198             
199             if (v.rid != item.rid) {
200                 return;
201             }
202             
203             index = i;
204             return false
205         });
206         
207         return index;
208     },
209     
210     setActiveNext : function()
211     {
212         var i = this.indexOfItem(this.getActive());
213         
214         if (i > this.barItems.length) {
215             return;
216         }
217         
218         this.setActiveItem(this.barItems[i+1]);
219     },
220     
221     setActivePrev : function()
222     {
223         var i = this.indexOfItem(this.getActive());
224         
225         if (i  < 1) {
226             return;
227         }
228         
229         this.setActiveItem(this.barItems[i-1]);
230     },
231     
232     format : function()
233     {
234         if(!this.barItems.length){
235             return;
236         }
237      
238         var width = 100 / this.barItems.length;
239         
240         Roo.each(this.barItems, function(i){
241             i.el.setStyle('width', width + '%');
242             i.topEl.el.setStyle('width', width + '%');
243             i.bottomEl.el.setStyle('width', width + '%');
244         }, this);
245         
246     }
247     
248 });