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