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