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