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