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