root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ 770ad9fa
History | View | Annotate | Download (11.7 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-name input').val(''); |
147 |
$('.advanced-conf-options').hide(); |
148 |
$('.snf-color-picker').hide(); |
149 |
}, |
150 |
|
151 |
expandArea: function() { |
152 |
ui.wizard.btns.expand_down.click(function(e){
|
153 |
ui.expandArrow(ui.wizard.btns.expand_down); |
154 |
$('.wizard-content').removeAttr('style'); |
155 |
ui.wizard.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle(600, function() { |
156 |
;ui.wizard.setStepHeight($('.step-3')); |
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 |
}); |
164 |
}) |
165 |
}, |
166 |
focusCustom: function(el, step) { |
167 |
el.focus(); |
168 |
el.attr('data-step',step);
|
169 |
}, |
170 |
|
171 |
preselectElements: function(area) { |
172 |
$(area).find('.current').not('.preselected').removeClass('current'); |
173 |
$(area).find('.preselected').not('.current').addClass('current'); |
174 |
$(area).find('.custom.dropdown.medium a:first').addClass('current'); // to fix |
175 |
$(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
176 |
$(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
177 |
$(area).find('.snf-checkbox-checked').not('.prechecked').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
178 |
$(area).find('.snf-checkbox-unchecked.prechecked').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
179 |
$('.expand-link').find('.snf-arrow-up.preselected').toggleClass('snf-arrow-up snf-arrow-down'); |
180 |
}, |
181 |
|
182 |
setStepHeight: function(stepEl) { |
183 |
var h1 = stepEl.height();
|
184 |
var h2 = $('.wizard .top').height(); |
185 |
var res = h1 +h2;
|
186 |
$('.wizard-content').css('height',res); |
187 |
}, |
188 |
|
189 |
returnStepHeight: function(stepEl) { |
190 |
var h1 = stepEl.height();
|
191 |
var h2 = $('.wizard .top').height(); |
192 |
var res = h1 +h2;
|
193 |
return res;
|
194 |
}, |
195 |
|
196 |
pickResources: function(resource) { |
197 |
$('.flavor .with-flavor a:not(.'+resource+')').removeClass('current'); |
198 |
$('.flavor .with-flavor a.'+resource+'').addClass('current'); |
199 |
} |
200 |
|
201 |
} |
202 |
|
203 |
|
204 |
$(document).ready(function(){ |
205 |
|
206 |
/*
|
207 |
Various functions for vm creation wizard
|
208 |
*/
|
209 |
|
210 |
/* step functions */
|
211 |
/* step-1: Pick OS */
|
212 |
$('.wizard .os > li').click(function(e){ |
213 |
e.preventDefault(); |
214 |
$('.wizard .os >li').removeClass('current'); |
215 |
$(this).addClass('current'); |
216 |
}); |
217 |
|
218 |
$('.os .btn-col a').click( function(e){ |
219 |
e.preventDefault(); |
220 |
e.stopPropagation(); |
221 |
$(this).toggleClass('current'); |
222 |
var self = this; |
223 |
$(this).parents('li').find('.details').stop().slideToggle('slow', function(){ |
224 |
ui.wizard.setStepHeight($('.step-1')); |
225 |
}); |
226 |
}); |
227 |
|
228 |
|
229 |
/* step-2: Select flavor */
|
230 |
$('.wizard .sub-menu a[data-size]').on( "click", function(e) { |
231 |
// e.preventDefault();
|
232 |
$(this).parents('.sub-menu').find('a').removeClass('current'); |
233 |
$(this).addClass('current'); |
234 |
ui.wizard.pickResources($(this).data('size')); |
235 |
}); |
236 |
|
237 |
$('.wizard .flavor .options:not(".vm-storage-selection") a').click(function(e){ |
238 |
// e.preventDefault();
|
239 |
$('.wizard .sub-menu a[data-size]').removeClass('current'); |
240 |
$(this).parents('.options').find('a').removeClass('current'); |
241 |
$(this).addClass('current'); |
242 |
}); |
243 |
|
244 |
$('.wizard .flavor .options.vm-storage-selection a').click(function(e){ |
245 |
// e.preventDefault();
|
246 |
$(this).parents('.options').find('a').removeClass('current'); |
247 |
$(this).addClass('current'); |
248 |
}); |
249 |
|
250 |
$('.flavor .options a').hover( |
251 |
function(){
|
252 |
var paragraph = $(this).parents('.options-bar').siblings('.title').find('p'); |
253 |
var text = $(this).data('help'); |
254 |
paragraph.html(text); |
255 |
paragraph.css('visibility','visible'); |
256 |
}, function() {
|
257 |
var paragraph = $(this).parents('.options-bar').siblings('.title').find('p'); |
258 |
paragraph.css('visibility','hidden'); |
259 |
} |
260 |
); |
261 |
/* step-3: Advanced options */
|
262 |
|
263 |
// reaction li.click
|
264 |
$('.advanced-conf-options .checkbox').click(function(e){ |
265 |
e.preventDefault(); |
266 |
var self = this; |
267 |
var checkbox = $(this).find('.check'); |
268 |
ui.changeCheckboxState(checkbox); |
269 |
if($(this).hasClass('has-more')) { |
270 |
$(this).next('.more').stop().slideToggle(400, function() { |
271 |
ui.wizard.setStepHeight($('.step-3')); |
272 |
if($(self).next('.more:visible').length != 0) { |
273 |
$(checkbox).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
274 |
} |
275 |
else {
|
276 |
$(checkbox).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
277 |
} |
278 |
}); |
279 |
} |
280 |
}); |
281 |
|
282 |
|
283 |
|
284 |
// reaction a.click
|
285 |
$('.checkbox .check').click(function(e) { |
286 |
e.stopPropagation(); |
287 |
var self = this; |
288 |
if($(this).closest('.checkbox').hasClass('has-more')) { |
289 |
console.log('hi');
|
290 |
$(this).parent().next('.more').stop().slideToggle(400, function() { |
291 |
console.log('a2');
|
292 |
if($(self).parent().next('.more:visible').length != 0) { |
293 |
$(self).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
294 |
console.log('a3');
|
295 |
} |
296 |
else {
|
297 |
$(self).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
298 |
} |
299 |
}); |
300 |
} |
301 |
}); |
302 |
|
303 |
$('.show-add-tag').click(function(e){ |
304 |
e.preventDefault(); |
305 |
$(this).parents('.tags-area').find('.snf-color-picker').slideDown('slow', function(){ |
306 |
ui.wizard.setStepHeight($('.step-3')); |
307 |
$('#hide-add-tag-dummy').scrollintoview({'duration':'slow'}); |
308 |
}); |
309 |
ui.colorPickerVisible =1;
|
310 |
}); |
311 |
|
312 |
$('.hide-add-tag').click(function(e){ |
313 |
e.preventDefault(); |
314 |
$(this).parents('.tags-area').find('.snf-color-picker').slideUp(400, function(){ |
315 |
$('.show-add-tag').first().scrollintoview({'duration':'slow'}); |
316 |
ui.colorPickerVisible = 0;
|
317 |
ui.wizard.setStepHeight($('.step-3')); |
318 |
}); |
319 |
}); |
320 |
|
321 |
/* end of step functions */
|
322 |
|
323 |
/* navigation and numbers functions */
|
324 |
$('.nav.previous').focus(function(e){ |
325 |
$(this).addClass('active'); |
326 |
}); |
327 |
|
328 |
$('.nav.previous').focusout(function(e){ |
329 |
$(this).removeClass('active'); |
330 |
|
331 |
}); |
332 |
|
333 |
$('.sub-menu[data-step=2] li:last').find('a').focusout(function(e) { |
334 |
$('.step-2').find('.dropdown a:first').focus(); |
335 |
|
336 |
}); |
337 |
|
338 |
$('.os .name-col').focus(function(e){ |
339 |
$(this).parents('li').addClass('hover'); |
340 |
}); |
341 |
|
342 |
$('.os .name-col').focusout(function(e){ |
343 |
$(this).parents('li').removeClass('hover'); |
344 |
}); |
345 |
|
346 |
|
347 |
/* end of navigation and numbers functions */
|
348 |
|
349 |
|
350 |
/* focus and tabs functionality */
|
351 |
|
352 |
$('a').keyup(function(e){ |
353 |
var self = this; |
354 |
if (e.keyCode==9||e.which==9){ |
355 |
if(e.shiftKey) {
|
356 |
} else {
|
357 |
//Focus next input
|
358 |
if ($(self).attr('data-next')) { |
359 |
$(self).focusout(function(e){ |
360 |
var classname = $(self).data('next'); |
361 |
console.log('tab goes to ',classname);
|
362 |
$('.'+classname+'').first().focus(); |
363 |
}); |
364 |
} |
365 |
} |
366 |
} |
367 |
}) |
368 |
|
369 |
/* end of focus and tabs functionality */
|
370 |
|
371 |
$('#vm-wizard').find('a').click(function(e) { |
372 |
e.preventDefault(); |
373 |
}); |
374 |
ui.wizard.current_step =1;
|
375 |
ui.wizard.btns.previous = $('.bottom').find('.nav.prev'); |
376 |
ui.wizard.btns.next = $('.bottom').find('.nav.next'); |
377 |
ui.wizard.btns.expand_down =$('.adv-main').find('.expand-link'); |
378 |
ui.wizard.btns.close =$('#vm-wizard').find('.close'); |
379 |
ui.wizard.initEvents(); |
380 |
ui.wizard.setMovementTags(); |
381 |
ui.wizard.expandArea(); |
382 |
ui.wizard.btns.close.click(function() {
|
383 |
ui.wizard.close(); |
384 |
}); |
385 |
|
386 |
$(window).resize(function() { |
387 |
ui.wizard.setStepHeight($('.step-'+ui.wizard.current_step+'')); |
388 |
}); |
389 |
}); |