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