root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ f5321878
History | View | Annotate | Download (9 kB)
1 |
// all functions use pixels
|
---|---|
2 |
ui.wizard ={ |
3 |
current_step: undefined, |
4 |
total_step: 4, |
5 |
current_position: undefined, |
6 |
relocation: undefined, |
7 |
btns: {
|
8 |
start: undefined, |
9 |
close: undefined, |
10 |
next: undefined, |
11 |
previous: undefined, |
12 |
expand_down: undefined |
13 |
}, |
14 |
|
15 |
set_container_height: function(step) { |
16 |
if (step === true) { |
17 |
step =0;
|
18 |
} else {
|
19 |
step = ui.wizard.current_step; |
20 |
} |
21 |
var topHeight = $('.top').height(); |
22 |
var stepHeight = $('.step-'+(step+1)+'').height(); |
23 |
var res = topHeight+stepHeight;
|
24 |
console.log('step', step);
|
25 |
if (step == 2) { |
26 |
$('.wizard-content').removeAttr('style'); |
27 |
} else {
|
28 |
$('.wizard-content').height(res); |
29 |
} |
30 |
}, |
31 |
set_container_height_back: function(step) { |
32 |
if (step === true) { |
33 |
step =1;
|
34 |
} else {
|
35 |
step = ui.wizard.current_step; |
36 |
} |
37 |
var topHeight = $('.top').height(); |
38 |
var stepHeight = $('.step-'+step+'').height(); |
39 |
var res = topHeight+stepHeight;
|
40 |
console.log('step', step);
|
41 |
if (step == 3) { |
42 |
$('.wizard-content').removeAttr('style'); |
43 |
} else {
|
44 |
$('.wizard-content').height(res); |
45 |
} |
46 |
}, |
47 |
|
48 |
|
49 |
// sets the width and height of the carousel and its divs
|
50 |
set_dimensions: function() { |
51 |
console.log('set dimentions');
|
52 |
ui.wizard.relocation = $(window).width();
|
53 |
console.log(ui.wizard.relocation); |
54 |
$('.vm-wizard-carousel').children('div.step').width(ui.wizard.relocation); |
55 |
ui.wizard.set_container_height(true);
|
56 |
}, |
57 |
|
58 |
// sets the width and height of the carousel and its divs when the screen is resized (in PIXELS)
|
59 |
adjust_to_resized_screen: function() { |
60 |
$(window).resize(function() { |
61 |
console.log('resized');
|
62 |
ui.wizard.set_dimensions(); |
63 |
|
64 |
if(ui.wizard.current_position<=0) { |
65 |
// the carousel moves to left -> this is the case that acts on resize
|
66 |
ui.wizard.current_position = -((ui.wizard.current_step-1)*ui.wizard.relocation);
|
67 |
} |
68 |
else
|
69 |
ui.wizard.current_position = (ui.wizard.current_step-1)*ui.wizard.relocation;
|
70 |
|
71 |
$('.vm-wizard-carousel').css('left', ui.wizard.current_position+'px'); |
72 |
}) |
73 |
}, |
74 |
|
75 |
|
76 |
|
77 |
move_to_step: function() { |
78 |
var speed =500; |
79 |
|
80 |
// carousel movement when right or left arrow is pressed
|
81 |
$(document).keydown(function(e) { |
82 |
|
83 |
// right arrow keyCode == 39
|
84 |
if(e.keyCode==39 && ui.wizard.current_step!=ui.wizard.total_step) { |
85 |
console.log('right arrow');
|
86 |
go_next(); |
87 |
return false; |
88 |
} |
89 |
// left arrow keyCode == 37
|
90 |
else if(e.keyCode==37 && ui.wizard.current_step!=1) { |
91 |
console.log('left arrow');
|
92 |
go_prev(); |
93 |
return false; |
94 |
} |
95 |
// enter keyCode == 13
|
96 |
else if (e.keyCode==13 && ui.wizard.current_step==ui.wizard.total_step) { |
97 |
console.log('enter -> close');
|
98 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area') |
99 |
} |
100 |
// esc keyCode == 27
|
101 |
else if(e.keyCode== 27 && ui.wizard.current_step==1) { |
102 |
console.log('esc -> close');
|
103 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area') |
104 |
} |
105 |
}); |
106 |
|
107 |
// when the button "next" is pressed show the next step (if there is a next step)
|
108 |
ui.wizard.btns.next.click(function(e){
|
109 |
e.preventDefault(); |
110 |
go_next(); |
111 |
}) |
112 |
|
113 |
// when the button "previous" is pressed show the previous step (if there is a previous step)
|
114 |
ui.wizard.btns.previous.click(function(e){
|
115 |
e.preventDefault(); |
116 |
go_prev(); |
117 |
}); |
118 |
|
119 |
// ui.wizard.btns.next.focusout(function(e) {
|
120 |
// if(ui.wizard.current_step!=ui.wizard.total_step) {
|
121 |
// $(this).removeClass('active');
|
122 |
// go_next();
|
123 |
// }
|
124 |
// });
|
125 |
|
126 |
// ui.wizard.btns.previous.focusout(function(e) {
|
127 |
// if(ui.wizard.current_step!=1) {
|
128 |
// $(this).removeClass('active');
|
129 |
// go_prev();
|
130 |
// }
|
131 |
// });
|
132 |
|
133 |
function go_next() { |
134 |
console.log('you clicked next!')
|
135 |
ui.wizard.set_container_height(); |
136 |
if(ui.wizard.current_step < ui.wizard.total_step){
|
137 |
ui.wizard.current_step++; |
138 |
ui.wizard.current_position -=ui.wizard.relocation; |
139 |
$('.vm-wizard-carousel').finish(); |
140 |
$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed); |
141 |
ui.wizard.indicate_step(ui.wizard.current_step); |
142 |
ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.btns.previous, ui.wizard.btns.next); |
143 |
if(ui.wizard.current_step == 2) { |
144 |
$('.sub-menu[data-step=2] li:first').find('a').focus(); |
145 |
} |
146 |
else if(ui.wizard.current_step == 3) { |
147 |
setTimeout(function() { $('.vm-name').find('input').focus() }, speed/2); |
148 |
} |
149 |
} |
150 |
else {
|
151 |
console.log('This is the last step.');
|
152 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area'); |
153 |
} |
154 |
} |
155 |
|
156 |
function go_prev() { |
157 |
if(ui.wizard.current_step > 1){ |
158 |
--ui.wizard.current_step; |
159 |
ui.wizard.set_container_height_back(); |
160 |
ui.wizard.current_position +=ui.wizard.relocation; |
161 |
$('.vm-wizard-carousel').finish(); |
162 |
$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed); |
163 |
ui.wizard.indicate_step(ui.wizard.current_step); |
164 |
ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.btns.previous, ui.wizard.btns.next); |
165 |
|
166 |
if(ui.wizard.current_step == 2) { |
167 |
$('.sub-menu[data-step=2] li:first').find('a').focus(); |
168 |
} |
169 |
else if(ui.wizard.current_step == 3) { |
170 |
setTimeout(function() { $('.vm-name').find('input').focus() }, speed/2); |
171 |
} |
172 |
} |
173 |
else {
|
174 |
console.log('This is the 1st step.')
|
175 |
ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area'); |
176 |
} |
177 |
} |
178 |
}, |
179 |
|
180 |
// sets the width and height of the steps and of the carousel (in PIXELS)
|
181 |
initialize_relocation: function(){ |
182 |
console.log('initialize_relocation');
|
183 |
ui.wizard.btns.start.click(function(e) {
|
184 |
e.preventDefault(); |
185 |
ui.wizard.reset(); |
186 |
ui.wizard.adjust_to_resized_screen(); |
187 |
ui.wizard.set_dimensions(); |
188 |
}) |
189 |
}, |
190 |
|
191 |
// for the carousel index
|
192 |
indicate_step: function(step) { |
193 |
$('.wizard .top .sub-menu[data-step]').hide(); |
194 |
$('.wizard .top .sub-menu[data-step='+step+']').fadeIn(); |
195 |
$('.nums').children().removeClass('current'); |
196 |
$('.nums li').show(); |
197 |
//$('.nums li:nth-child('+ui.wizard.current_step+'').addClass('current');
|
198 |
$('.nums').children().find('*:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current'); |
199 |
$('.nums .current').prevAll('li').hide(); |
200 |
}, |
201 |
|
202 |
// changes the text of next and previous buttons
|
203 |
set_movement_tags: function() { |
204 |
if (ui.wizard.current_step==1) { |
205 |
ui.wizard.btns.previous.find('span').html('CANCEL'); |
206 |
ui.wizard.btns.next.find('span').html('NEXT'); |
207 |
} |
208 |
else if(ui.wizard.current_step==ui.wizard.total_step) { |
209 |
ui.wizard.btns.previous.find('span').html('PREVIOUS'); |
210 |
ui.wizard.btns.next.find('span').html('CREATE'); |
211 |
} |
212 |
else {
|
213 |
ui.wizard.btns.previous.find('span').html('PREVIOUS'); |
214 |
ui.wizard.btns.next.find('span').html('NEXT'); |
215 |
} |
216 |
}, |
217 |
|
218 |
close: function(bottom_area, main_area, total_area) { |
219 |
$(bottom_area).hide();
|
220 |
$(main_area).slideUp();
|
221 |
$(total_area).slideUp();
|
222 |
}, |
223 |
|
224 |
// manually sets elements to a initial state
|
225 |
reset: function() { |
226 |
ui.wizard.current_step = 1;
|
227 |
ui.wizard.current_position = 0;
|
228 |
|
229 |
$('.vm-wizard-carousel').css({left: ui.wizard.current_position+'px'}); |
230 |
$('.bottom').show(); |
231 |
//$('.step-1').find('.current').removeClass('current');
|
232 |
ui.wizard.indicate_step(ui.wizard.current_step); |
233 |
ui.wizard.set_movement_tags(); |
234 |
$('#vm-wizard').find('.snf-checkbox-checked').addClass('snf-checkbox-unchecked').removeClass('snf-checkbox-checked'); |
235 |
$('#vm-wizard').find('.default').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
236 |
$('.details').hide(); |
237 |
$('.wizard .top .sub-menu[data-step="1"] ul li:first-child a').addClass('current'); |
238 |
ui.pickResources('small');
|
239 |
//$('.wizard .step-2 .options li a:contains(DRBD)').addClass('current')
|
240 |
$('.vm-name input').val(''); |
241 |
$('.advanced-conf-options').hide(); |
242 |
$('.snf-color-picker').hide(); |
243 |
|
244 |
|
245 |
}, |
246 |
|
247 |
expand_area: function() { |
248 |
ui.wizard.btns.expand_down.click(function(e){
|
249 |
e.preventDefault(); |
250 |
ui.expand_arrow(ui.wizard.btns.expand_down); |
251 |
ui.wizard.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle(); |
252 |
}) |
253 |
}, |
254 |
|
255 |
} |
256 |
|
257 |
|
258 |
$(document).ready(function(){ |
259 |
|
260 |
ui.wizard.current_step =1;
|
261 |
ui.wizard.current_position =0;
|
262 |
|
263 |
ui.wizard.btns.start =$('.new-btn, .add-new'); |
264 |
ui.wizard.btns.previous = $('.bottom').find('.nav.prev'); |
265 |
ui.wizard.btns.next = $('.bottom').find('.nav.next'); |
266 |
ui.wizard.btns.expand_down =$('.adv-main').find('.expand-link'); |
267 |
|
268 |
$('.wizard .nums').click(function(e){ |
269 |
e.preventDefault(); |
270 |
}) |
271 |
|
272 |
ui.wizard.initialize_relocation(); |
273 |
ui.wizard.move_to_step(); |
274 |
ui.wizard.set_movement_tags(); |
275 |
ui.wizard.expand_area(); |
276 |
|
277 |
$('.step-1 .os li:last').find('.btn-col a').focusout(function(e) { |
278 |
e.preventDefault(); |
279 |
$('.nav.next').focus(); |
280 |
$('.nav.next').addClass('active'); |
281 |
}); |
282 |
|
283 |
|
284 |
$('.nav.previous').focus(function(e){ |
285 |
$(this).addClass('active'); |
286 |
}); |
287 |
|
288 |
$('.nav.previous').focusout(function(e){ |
289 |
e.preventDefault(); |
290 |
$(this).addClass('active'); |
291 |
$(this).removeClass('active'); |
292 |
|
293 |
}); |
294 |
|
295 |
|
296 |
$('.sub-menu[data-step=2] li:last').find('a').focusout(function(e) { |
297 |
e.preventDefault(); |
298 |
$('.step-2').find('.dropdown a:first').focus(); |
299 |
|
300 |
}) |
301 |
|
302 |
$('.os .name-col').focus(function(e){ |
303 |
$(this).parents('li').addClass('hover'); |
304 |
}) |
305 |
$('.os .name-col').focusout(function(e){ |
306 |
$(this).parents('li').removeClass('hover'); |
307 |
}) |
308 |
|
309 |
|
310 |
}); |