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