Revision 148aeffe
b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/vm-wizard.js | ||
---|---|---|
1 |
// all functions use pixels |
|
2 |
ui.wizard ={ |
|
3 |
current_step: undefined, |
|
4 |
vm: {total_step: 4}, |
|
5 |
current_position: undefined, |
|
6 |
relocation: undefined, |
|
7 |
|
|
8 |
// sets the width and height of the carousel and its divs |
|
9 |
set_dimensions: function() { |
|
10 |
console.log('set dimentions'); |
|
11 |
ui.wizard.relocation = $('.wizard-content').width(); |
|
12 |
$('.vm-wizard-carousel').children('div').width(ui.wizard.relocation+'px'); |
|
13 |
$('.vm-wizard-carousel').children('div').height($('.wizard-content').height()+'px'); |
|
14 |
}, |
|
15 |
|
|
16 |
// sets the width and height of the carousel and its divs when the screen is resized (in PIXELS) |
|
17 |
adjust_to_resized_screen: function() { |
|
18 |
$(window).resize(function() { |
|
19 |
console.log('resized'); |
|
20 |
ui.wizard.set_dimensions(); |
|
21 |
|
|
22 |
if(ui.wizard.current_position<=0) { |
|
23 |
// the carousel moves to left -> this is the case that acts on resize |
|
24 |
ui.wizard.current_position = -((ui.wizard.current_step-1)*ui.wizard.relocation); |
|
25 |
} |
|
26 |
else |
|
27 |
ui.wizard.current_position = (ui.wizard.current_step-1)*ui.wizard.relocation; |
|
28 |
|
|
29 |
$('.vm-wizard-carousel').css('left', ui.wizard.current_position+'px'); |
|
30 |
}) |
|
31 |
}, |
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
move_to_step: function(prev_btn, next_btn) { |
|
36 |
// when the button "next" is pressed show the next step (if there is a next step) |
|
37 |
next_btn.click(function(){ |
|
38 |
event.preventDefault(); |
|
39 |
console.log('you clicked next!') |
|
40 |
if(ui.wizard.current_step < ui.wizard.vm.total_step){ |
|
41 |
ui.wizard.current_step++; |
|
42 |
ui.wizard.current_position -=ui.wizard.relocation; |
|
43 |
$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, 1000); |
|
44 |
ui.wizard.indicate_step(ui.wizard.current_step); |
|
45 |
} |
|
46 |
else { |
|
47 |
console.log('This is the last step.'); |
|
48 |
} |
|
49 |
}) |
|
50 |
|
|
51 |
// when the button "previous" is pressed show the previous step (if there is a previous step) |
|
52 |
prev_btn.click(function(){ |
|
53 |
event.preventDefault(); |
|
54 |
console.log('you clicked previous!'); |
|
55 |
if(ui.wizard.current_step > 1){ |
|
56 |
ui.wizard.current_step--; |
|
57 |
ui.wizard.current_position +=ui.wizard.relocation; |
|
58 |
$('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, 1000); |
|
59 |
ui.wizard.indicate_step(ui.wizard.current_step); |
|
60 |
} |
|
61 |
else { |
|
62 |
console.log('This is the 1st step.') |
|
63 |
} |
|
64 |
}) |
|
65 |
}, |
|
66 |
|
|
67 |
// sets the width and height of the steps and of the carousel (in PIXELS) |
|
68 |
initialize_relocation: function(start_btns){ |
|
69 |
start_btns.click(function() { |
|
70 |
event.preventDefault(); |
|
71 |
console.log('initialize_relocation'); |
|
72 |
ui.wizard.adjust_to_resized_screen(); |
|
73 |
ui.wizard.set_dimensions(); |
|
74 |
}) |
|
75 |
}, |
|
76 |
// for the carousel index |
|
77 |
indicate_step: function(step) { |
|
78 |
$('.nums').children().removeClass('current'); |
|
79 |
$('.nums').children().find('a:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current'); |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
$(document).ready(function(){ |
|
85 |
|
|
86 |
ui.wizard.current_step =1; |
|
87 |
ui.wizard.current_position =0; |
|
88 |
|
|
89 |
var new_vm_btn =$('.new-btn, .add-new'); |
|
90 |
var prev_btn = $('.bottom').find('.nav.prev'); |
|
91 |
var next_btn = $('.bottom').find('.nav.next'); |
|
92 |
|
|
93 |
ui.wizard.initialize_relocation(new_vm_btn); |
|
94 |
ui.wizard.move_to_step(prev_btn, next_btn); |
|
95 |
|
|
96 |
|
|
97 |
}); |
Also available in: Unified diff