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