root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ 0c26d55c
History | View | Annotate | Download (11.8 kB)
1 |
// all functions use pixels
|
---|---|
2 |
ui.wizard ={ |
3 |
current_step: undefined, |
4 |
total_step: $('.wizard-content .step').length, |
5 |
current_position: undefined, |
6 |
relocation: undefined, |
7 |
btns: {
|
8 |
start: undefined, |
9 |
close: undefined, |
10 |
next: undefined, |
11 |
previous: undefined, |
12 |
expand_down: undefined |
13 |
}, |
14 |
speed: 500, |
15 |
|
16 |
setDimensions: function (){ |
17 |
$('.vm-wizard-carousel').css('width', 100*ui.wizard.total_step+'%'); |
18 |
$('.vm-wizard-carousel .step').css('width', 100/ui.wizard.total_step+'%'); |
19 |
ui.wizard.setStepHeight('.step', '.top', '.bottom', '.header'); |
20 |
}, |
21 |
|
22 |
submitData: function (){ |
23 |
console.log('submit data dummy function');
|
24 |
}, |
25 |
|
26 |
data_next_array: ['test1','el2','el4','el7'], |
27 |
|
28 |
focusFun: function(){ |
29 |
// $('.nav.next').attr('data-step',ui.wizard.current_step);
|
30 |
// $('.nav.next').removeAttr('data-next');
|
31 |
// $('.nav.next').attr('data-next', ui.wizard.data_next_array[ui.wizard.current_step]);
|
32 |
// $('.'+ui.wizard.data_next_array[ui.wizard.current_step]+'').first().focus();
|
33 |
// console.log('focusFun',ui.wizard.data_next_array[ui.wizard.current_step]);
|
34 |
}, |
35 |
|
36 |
move: function () { |
37 |
var percentage = -(ui.wizard.current_step-1)*100+'%'; |
38 |
$('.step').css('overflow-y', 'hidden'); |
39 |
$('.vm-wizard-carousel').stop(true, true).animate({ 'left': percentage }, ui.wizard.speed, function() { |
40 |
$('.step').css('overflow-y', 'scroll'); |
41 |
}); |
42 |
ui.wizard.focusFun(); |
43 |
ui.wizard.indicateStep(ui.wizard.current_step); |
44 |
ui.wizard.setMovementTags(ui.wizard.current_step, ui.wizard.btns.previous, ui.wizard.btns.next); |
45 |
if(ui.wizard.current_step == 3 && $('.step-3 .advanced-conf-options:visible').length == 0) { |
46 |
setTimeout(function() { $('.vm-name').find('input').focus() }, ui.wizard.speed/2); |
47 |
} |
48 |
|
49 |
}, |
50 |
|
51 |
goNext: function () { |
52 |
if(ui.wizard.current_step < ui.wizard.total_step){
|
53 |
ui.wizard.current_step++; |
54 |
ui.wizard.move(); |
55 |
} |
56 |
else {
|
57 |
ui.wizard.submitData(); |
58 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area'); |
59 |
} |
60 |
}, |
61 |
|
62 |
goPrev:function() { |
63 |
if(ui.wizard.current_step > 1){ |
64 |
ui.wizard.current_step--; |
65 |
ui.wizard.move(); |
66 |
} |
67 |
else {
|
68 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area'); |
69 |
} |
70 |
}, |
71 |
|
72 |
initEvents: function(){ |
73 |
ui.wizard.setDimensions(); |
74 |
|
75 |
$(document).keydown(function(e) { |
76 |
// right arrow keyCode == 39
|
77 |
if($('.vm-wizard-carousel:visible').length != 0) { |
78 |
if(e.keyCode==39 && ui.wizard.current_step!=(ui.wizard.total_step)) { |
79 |
ui.wizard.goNext(); |
80 |
return false; |
81 |
} |
82 |
// left arrow keyCode == 37
|
83 |
else if(e.keyCode==37 && ui.wizard.current_step!=1) { |
84 |
ui.wizard.goPrev(); |
85 |
return false; |
86 |
} |
87 |
// ESC
|
88 |
else if(e.keyCode== 27 && ui.wizard.current_step==1) { |
89 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area') |
90 |
} |
91 |
} |
92 |
}); |
93 |
|
94 |
ui.wizard.btns.next.click(function(e){
|
95 |
ui.wizard.goNext(); |
96 |
}) |
97 |
|
98 |
ui.wizard.btns.previous.click(function(e){
|
99 |
ui.wizard.goPrev(); |
100 |
}); |
101 |
}, |
102 |
|
103 |
// for the carousel index
|
104 |
indicateStep: function(step) { |
105 |
$('.wizard .top .sub-menu[data-step]').hide(); |
106 |
$('.wizard .top .sub-menu[data-step='+step+']').fadeIn(); |
107 |
$('.nums').children().removeClass('current'); |
108 |
$('.nums li').show(); |
109 |
$('.nums li:nth-child('+ui.wizard.current_step+')').addClass('current'); |
110 |
$('.nums .current').prevAll('li').hide(); |
111 |
}, |
112 |
|
113 |
// changes the text of next and previous buttons
|
114 |
setMovementTags: function() { |
115 |
if (ui.wizard.current_step==1) { |
116 |
ui.wizard.btns.previous.find('span').html('CANCEL'); |
117 |
ui.wizard.btns.next.find('span').html('NEXT'); |
118 |
} |
119 |
else if(ui.wizard.current_step==ui.wizard.total_step) { |
120 |
ui.wizard.btns.previous.find('span').html('PREVIOUS'); |
121 |
ui.wizard.btns.next.find('span').html('CREATE'); |
122 |
} |
123 |
else {
|
124 |
ui.wizard.btns.previous.find('span').html('PREVIOUS'); |
125 |
ui.wizard.btns.next.find('span').html('NEXT'); |
126 |
} |
127 |
}, |
128 |
|
129 |
close: function(bottom_area, main_area, total_area) { |
130 |
$('.step').animate({ |
131 |
scrollTop: 0}, 1400, 'swing', function() { |
132 |
$(bottom_area).hide();
|
133 |
$(main_area).slideUp(600); |
134 |
$(total_area).slideUp(600, function(){ |
135 |
ui.wizard.reset(); |
136 |
ui.wizard.preselectElements(bottom_area); |
137 |
ui.wizard.preselectElements(main_area); |
138 |
ui.wizard.preselectElements(total_area); |
139 |
}); |
140 |
}); |
141 |
}, |
142 |
|
143 |
// manually sets elements to a initial state
|
144 |
reset: function() { |
145 |
ui.wizard.current_step = 1;
|
146 |
$('.vm-wizard-carousel').css('left',0); |
147 |
$('.bottom').show(); |
148 |
ui.wizard.indicateStep(ui.wizard.current_step); |
149 |
ui.wizard.setMovementTags(); |
150 |
$('.networks-area .more').show(); |
151 |
$('.details').hide(); |
152 |
$('.vm-name input').val(''); |
153 |
$('.advanced-conf-options').hide(); |
154 |
$('.snf-color-picker').hide(); |
155 |
}, |
156 |
|
157 |
expandArea: function() { |
158 |
ui.wizard.btns.expand_down.click(function(e){
|
159 |
// e.preventDefault();
|
160 |
ui.expandArrow(ui.wizard.btns.expand_down); |
161 |
ui.wizard.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle(600, function() { |
162 |
if($('.advanced-conf-options:visible').length != 0) { |
163 |
ui.wizard.btns.expand_down.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up'); |
164 |
} |
165 |
else {
|
166 |
ui.wizard.btns.expand_down.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down'); |
167 |
} |
168 |
}); |
169 |
}) |
170 |
}, |
171 |
focusCustom: function(el, step) { |
172 |
el.focus(); |
173 |
el.attr('data-step',step);
|
174 |
}, |
175 |
|
176 |
preselectElements: function(area) { |
177 |
$(area).find('.current').not('.preselected').removeClass('current'); |
178 |
$(area).find('.preselected').not('.current').addClass('current'); |
179 |
$(area).find('.custom.dropdown.medium a:first').addClass('current'); // to fix |
180 |
$(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
181 |
$(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
182 |
$(area).find('.snf-checkbox-checked').not('.prechecked').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
183 |
$(area).find('.snf-checkbox-unchecked.prechecked').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
184 |
$('.expand-link').find('.snf-arrow-up.preselected').toggleClass('snf-arrow-up snf-arrow-down'); |
185 |
}, |
186 |
|
187 |
setStepHeight: function(stepEl, fixedTopEl, fixedBottomEl, headerEl) { |
188 |
var topHeight = $(fixedTopEl).height(); |
189 |
var bottomHeight = $('.bottom .row').height(); |
190 |
var totalHeight = $(window).height(); |
191 |
var headerHeight = $(headerEl).height(); |
192 |
var stepHeight = totalHeight-topHeight-bottomHeight-headerHeight;
|
193 |
$(stepEl).outerHeight(stepHeight);
|
194 |
$('.wizard-content').outerHeight(stepHeight); |
195 |
}, |
196 |
|
197 |
pickResources: function(resource) { |
198 |
$('.flavor .with-flavor a:not(.'+resource+')').removeClass('current'); |
199 |
$('.flavor .with-flavor a.'+resource+'').addClass('current'); |
200 |
} |
201 |
|
202 |
} |
203 |
|
204 |
|
205 |
$(document).ready(function(){ |
206 |
|
207 |
/*
|
208 |
Various functions for vm creation wizard
|
209 |
*/
|
210 |
|
211 |
/* step functions */
|
212 |
/* step-1: Pick OS */
|
213 |
$('.wizard .os > li').click(function(e){ |
214 |
e.preventDefault(); |
215 |
$('.wizard .os >li').removeClass('current'); |
216 |
$(this).addClass('current'); |
217 |
}); |
218 |
|
219 |
$('.os .btn-col a').click( function(e){ |
220 |
e.preventDefault(); |
221 |
e.stopPropagation(); |
222 |
$(this).toggleClass('current'); |
223 |
$(this).parents('li').find('.details').stop().slideToggle(); |
224 |
}); |
225 |
|
226 |
|
227 |
/* step-2: Select flavor */
|
228 |
$('.wizard .sub-menu a[data-size]').on( "click", function(e) { |
229 |
// e.preventDefault();
|
230 |
$(this).parents('.sub-menu').find('a').removeClass('current'); |
231 |
$(this).addClass('current'); |
232 |
ui.wizard.pickResources($(this).data('size')); |
233 |
}); |
234 |
|
235 |
$('.wizard .flavor .options:not(".vm-storage-selection") a').click(function(e){ |
236 |
// e.preventDefault();
|
237 |
$('.wizard .sub-menu a[data-size]').removeClass('current'); |
238 |
$(this).parents('.options').find('a').removeClass('current'); |
239 |
$(this).addClass('current'); |
240 |
}); |
241 |
|
242 |
$('.wizard .flavor .options.vm-storage-selection a').click(function(e){ |
243 |
// e.preventDefault();
|
244 |
$(this).parents('.options').find('a').removeClass('current'); |
245 |
$(this).addClass('current'); |
246 |
}); |
247 |
|
248 |
/* step-3: Advanced options */
|
249 |
|
250 |
// reaction li.click
|
251 |
$('.advanced-conf-options .checkbox').click(function(e){ |
252 |
e.preventDefault(); |
253 |
var self = this; |
254 |
var checkbox = $(this).find('.check'); |
255 |
ui.changeCheckboxState(checkbox); |
256 |
console.log('a1');
|
257 |
if($(this).hasClass('has-more')) { |
258 |
$(this).next('.more').stop().slideToggle(400, function() { |
259 |
console.log('a2');
|
260 |
if($(self).next('.more:visible').length != 0) { |
261 |
$(checkbox).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
262 |
console.log('a3');
|
263 |
} |
264 |
else {
|
265 |
$(checkbox).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
266 |
} |
267 |
}); |
268 |
} |
269 |
}); |
270 |
// reaction a.click
|
271 |
$('.checkbox .check').click(function(e) { |
272 |
e.stopPropagation(); |
273 |
var self = this; |
274 |
if($(this).closest('.checkbox').hasClass('has-more')) { |
275 |
console.log('hi');
|
276 |
$(this).parent().next('.more').stop().slideToggle(400, function() { |
277 |
console.log('a2');
|
278 |
if($(self).parent().next('.more:visible').length != 0) { |
279 |
$(self).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
280 |
console.log('a3');
|
281 |
} |
282 |
else {
|
283 |
$(self).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
284 |
} |
285 |
}); |
286 |
} |
287 |
}); |
288 |
|
289 |
$('.show-add-tag').click(function(e){ |
290 |
e.preventDefault(); |
291 |
$(this).parents('.tags-area').find('.snf-color-picker').slideDown(); |
292 |
goToByScroll('hide-add-tag');
|
293 |
ui.colorPickerVisible =1;
|
294 |
}); |
295 |
|
296 |
$('.hide-add-tag').click(function(e){ |
297 |
e.preventDefault(); |
298 |
$(this).parents('.snf-color-picker').slideUp('400', function(){ |
299 |
ui.colorPickerVisible = 0;
|
300 |
}); |
301 |
}); |
302 |
|
303 |
/* end of step functions */
|
304 |
|
305 |
/* navigation and numbers functions */
|
306 |
$('.nav.previous').focus(function(e){ |
307 |
$(this).addClass('active'); |
308 |
}); |
309 |
|
310 |
$('.nav.previous').focusout(function(e){ |
311 |
$(this).removeClass('active'); |
312 |
|
313 |
}); |
314 |
|
315 |
$('.sub-menu[data-step=2] li:last').find('a').focusout(function(e) { |
316 |
$('.step-2').find('.dropdown a:first').focus(); |
317 |
|
318 |
}); |
319 |
|
320 |
$('.os .name-col').focus(function(e){ |
321 |
$(this).parents('li').addClass('hover'); |
322 |
}); |
323 |
|
324 |
$('.os .name-col').focusout(function(e){ |
325 |
$(this).parents('li').removeClass('hover'); |
326 |
}); |
327 |
|
328 |
|
329 |
/* end of navigation and numbers functions */
|
330 |
|
331 |
|
332 |
/* focus and tabs functionality */
|
333 |
|
334 |
$('a').keyup(function(e){ |
335 |
var self = this; |
336 |
if (e.keyCode==9||e.which==9){ |
337 |
if ($(self).attr('data-next')) { |
338 |
$(self).focusout(function(e){ |
339 |
var classname = $(self).data('next'); |
340 |
console.log('tab goes to ',classname);
|
341 |
$('.'+classname+'').first().focus(); |
342 |
}) |
343 |
} |
344 |
} |
345 |
}) |
346 |
|
347 |
|
348 |
// make sure that is always correctly moved
|
349 |
/*$('a, input').focus(function(e){
|
350 |
if ($(this).parents('.step').data('step')> 0) {
|
351 |
if ( ui.wizard.current_step == ($(this).parents('.step').data('step'))) {
|
352 |
} else {
|
353 |
ui.wizard.current_step = $(this).parents('.step').data('step');
|
354 |
ui.wizard.move();
|
355 |
}
|
356 |
}
|
357 |
})
|
358 |
*//* end of focus and tabs functionality */ |
359 |
|
360 |
$('#vm-wizard').find('a').click(function(e) { |
361 |
e.preventDefault(); |
362 |
}); |
363 |
ui.wizard.current_step =1;
|
364 |
ui.wizard.btns.previous = $('.bottom').find('.nav.prev'); |
365 |
ui.wizard.btns.next = $('.bottom').find('.nav.next'); |
366 |
ui.wizard.btns.expand_down =$('.adv-main').find('.expand-link'); |
367 |
ui.wizard.btns.close =$('#vm-wizard').find('.close'); |
368 |
ui.wizard.initEvents(); |
369 |
ui.wizard.setMovementTags(); |
370 |
ui.wizard.expandArea(); |
371 |
ui.wizard.btns.close.click(function(e) {
|
372 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area') |
373 |
}); |
374 |
|
375 |
$(window).resize(function() { |
376 |
ui.wizard.setStepHeight('.step', '.top', '.bottom', '.header') |
377 |
}); |
378 |
}); |