Revision eba2aada

b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/vm-wizard.js
1 1
// all functions use pixels
2 2
ui.wizard ={
3 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
	
4
	total_step: 4,
15 5
	current_position: undefined,
16 6
	relocation: undefined,
7
	btns: {
8
		start: undefined,
9
		close: undefined,
10
		next: undefined,
11
		previous: undefined,
12
		expand_down: undefined
13
	},
17 14

  
18 15

  
19 16
	// sets the width and height of the carousel and its divs
......
48 45

  
49 46
		// carousel movement when right or left arrow is pressed
50 47
		$(document).keydown(function(e) {
51
			if(e.keyCode==39 && ui.wizard.current_step!=ui.wizard.vm.total_step) {
48

  
49
			// right arrow keyCode == 39
50
			if(e.keyCode==39 && ui.wizard.current_step!=ui.wizard.total_step) {
52 51
				go_next();
53 52
				return false;
54 53
			}
54
			// left arrow keyCode == 37
55 55
			else if(e.keyCode==37 && ui.wizard.current_step!=1) {
56 56
				go_prev();
57 57
				return false;
58 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
			}
65
			// esc keyCode == 27
66
			else if(e.keyCode== 27 && ui.wizard.current_step==1) {
67
				ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area')
68
			}
59 69
		});
60 70
		
61 71
		// 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){
72
		ui.wizard.btns.next.click(function(e){
63 73
			e.preventDefault();
64 74
			go_next();
65 75
		})
66 76

  
67 77
		// 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){
78
		ui.wizard.btns.previous.click(function(e){
69 79
			e.preventDefault();
70 80
			go_prev();
71 81
			
72 82
		});
73 83

  
74
		ui.wizard.vm.btns.next.focusout(function(e) {
75
			if(ui.wizard.current_step!=ui.wizard.vm.total_step) {
84
		ui.wizard.btns.next.focusout(function(e) {
85
			if(ui.wizard.current_step!=ui.wizard.total_step) {
76 86
				$(this).removeClass('active');
77 87
				go_next();
78 88
			}
79 89
		
80 90
		});
81 91
		
82
		ui.wizard.vm.btns.previous.focusout(function(e) {
92
		ui.wizard.btns.previous.focusout(function(e) {
83 93
			if(ui.wizard.current_step!=1) {
84 94
				$(this).removeClass('active');
85 95
				go_prev();
......
90 100
		function go_next() {
91 101
			console.log('going next!');
92 102
			console.log('you clicked next!')
93
			if(ui.wizard.current_step < ui.wizard.vm.total_step){
103
			if(ui.wizard.current_step < ui.wizard.total_step){
94 104
				ui.wizard.current_step++;
95 105
				ui.wizard.current_position -=ui.wizard.relocation;
96 106
				$('.vm-wizard-carousel').finish();
97 107
				$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
98 108
				ui.wizard.indicate_step(ui.wizard.current_step);
99
				ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.vm.btns.previous, ui.wizard.vm.btns.next);
109
				ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.btns.previous, ui.wizard.btns.next);
100 110
				if(ui.wizard.current_step == 2) {
101 111
					$('.sub-menu[data-step=2] li:first').find('a').focus();
102 112
				}
......
118 128
				$('.vm-wizard-carousel').finish();
119 129
				$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
120 130
				ui.wizard.indicate_step(ui.wizard.current_step);
121
				ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.vm.btns.previous, ui.wizard.vm.btns.next);
131
				ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.btns.previous, ui.wizard.btns.next);
122 132

  
123 133
				if(ui.wizard.current_step == 2) {
124 134
					$('.sub-menu[data-step=2] li:first').find('a').focus();
......
137 147
	// sets the width and height of the steps and of the carousel (in PIXELS)
138 148
	initialize_relocation: function(){
139 149
			console.log('initialize_relocation');
140
			ui.wizard.vm.btns.start.click(function(e) {
150
			ui.wizard.btns.start.click(function(e) {
141 151
				e.preventDefault();	
142 152
				ui.wizard.reset();
143 153
				ui.wizard.adjust_to_resized_screen();
......
158 168
	// changes the text of next and previous buttons
159 169
	set_movement_tags: function() {
160 170
		if (ui.wizard.current_step==1) {
161
			ui.wizard.vm.btns.previous.find('span').html('CANCEL');
162
			ui.wizard.vm.btns.next.find('span').html('NEXT');
171
			ui.wizard.btns.previous.find('span').html('CANCEL');
172
			ui.wizard.btns.next.find('span').html('NEXT');
163 173
		}
164
		else if(ui.wizard.current_step==ui.wizard.vm.total_step) {
165
			ui.wizard.vm.btns.previous.find('span').html('PREVIOUS');
166
			ui.wizard.vm.btns.next.find('span').html('CREATE');
174
		else if(ui.wizard.current_step==ui.wizard.total_step) {
175
			ui.wizard.btns.previous.find('span').html('PREVIOUS');
176
			ui.wizard.btns.next.find('span').html('CREATE');
167 177
		}
168 178
		else {
169
			ui.wizard.vm.btns.previous.find('span').html('PREVIOUS');
170
			ui.wizard.vm.btns.next.find('span').html('NEXT');
179
			ui.wizard.btns.previous.find('span').html('PREVIOUS');
180
			ui.wizard.btns.next.find('span').html('NEXT');
171 181
		}
172 182
	},
173 183

  
......
201 211
	},
202 212

  
203 213
	expand_area: function() {
204
		ui.wizard.vm.btns.expand_down.click(function(e){
214
		ui.wizard.btns.expand_down.click(function(e){
205 215
	        e.preventDefault();
206
	      	ui.expand_arrow(ui.wizard.vm.btns.expand_down);
207
	        ui.wizard.vm.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle();
216
	      	ui.expand_arrow(ui.wizard.btns.expand_down);
217
	        ui.wizard.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle();
208 218
	    })
209 219
	},
210 220

  
......
216 226
	ui.wizard.current_step =1;
217 227
	ui.wizard.current_position =0;
218 228

  
219
	ui.wizard.vm.btns.start =$('.new-btn, .add-new');
220
	ui.wizard.vm.btns.previous = $('.bottom').find('.nav.prev');
221
	ui.wizard.vm.btns.next = $('.bottom').find('.nav.next');
222
	ui.wizard.vm.btns.expand_down =$('.adv-main').find('.expand-link');
229
	ui.wizard.btns.start =$('.new-btn, .add-new');
230
	ui.wizard.btns.previous = $('.bottom').find('.nav.prev');
231
	ui.wizard.btns.next = $('.bottom').find('.nav.next');
232
	ui.wizard.btns.expand_down =$('.adv-main').find('.expand-link');
223 233
	
224 234
	$('.wizard .nums').click(function(e){
225 235
		e.preventDefault();
......
249 259
	});
250 260

  
251 261

  
262
	$('.sub-menu[data-step=2] li:last').find('a').focusout(function(e) {
263
		e.preventDefault();
264
		$('.step-2').find('.dropdown a:first').focus();
265

  
266
	})
267

  
268

  
252 269

  
253 270
	
254 271

  

Also available in: Unified diff