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