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