Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ 1102774c

History | View | Annotate | Download (6.5 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
                        $('.step-1 .os li:first').find('.btn-col a').focus();
127
        },
128

    
129
        // for the carousel index
130
        indicate_step: function(step) {
131
                $('.wizard .top .sub-menu[data-step]').hide();
132
                $('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
133
                $('.nums').children().removeClass('current');
134
                //$('.nums li:nth-child('+ui.wizard.current_step+'').addClass('current');
135
                $('.nums').children().find('a:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current');
136
        },
137

    
138
        // changes the text of next and previous buttons
139
        set_movement_tags: function() {
140
                if (ui.wizard.current_step==1) {
141
                        ui.wizard.vm.btns.previous.find('span').html('CANCEL');
142
                        ui.wizard.vm.btns.next.find('span').html('NEXT');
143
                }
144
                else if(ui.wizard.current_step==ui.wizard.vm.total_step) {
145
                        ui.wizard.vm.btns.previous.find('span').html('PREVIOUS');
146
                        ui.wizard.vm.btns.next.find('span').html('CREATE');
147
                }
148
                else {
149
                        ui.wizard.vm.btns.previous.find('span').html('PREVIOUS');
150
                        ui.wizard.vm.btns.next.find('span').html('NEXT');
151
                }
152
        },
153

    
154
        close: function(bottom_area, main_area, total_area) {
155
                $(bottom_area).hide();
156
                $(main_area).slideUp();
157
                $(total_area).slideUp();
158
        },
159

    
160
        // manually sets elements to a initial state
161
        reset: function() {
162
                ui.wizard.current_step = 1;
163
                ui.wizard.current_position = 0;
164
                
165
                $('.vm-wizard-carousel').css({left: ui.wizard.current_position+'px'});
166
                $('.bottom').show();
167
                //$('.step-1').find('.current').removeClass('current');
168
                ui.wizard.indicate_step(ui.wizard.current_step);
169
                ui.wizard.set_movement_tags();
170
                $('#vm-wizard').find('.snf-checkbox-checked').addClass('snf-checkbox-unchecked').removeClass('snf-checkbox-checked');
171
                $('#vm-wizard').find('.default').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked');
172
                $('.details').hide();
173
                $('.wizard .top .sub-menu[data-step="1"] ul li:first-child a').addClass('current');
174
                ui.pickResources('small');
175
                //$('.wizard .step-2 .options li a:contains(DRBD)').addClass('current')
176
                $('.vm-name input').val('');
177
                $('.advanced-conf-options').hide();
178
                $('.snf-color-picker').hide();
179

    
180

    
181
        },
182

    
183
        expand_area: function() {
184
                ui.wizard.vm.btns.expand_down.click(function(e){
185
                e.preventDefault();
186
                      ui.expand_arrow(ui.wizard.vm.btns.expand_down);
187
                ui.wizard.vm.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle();
188
            })
189
        }
190

    
191
}
192

    
193

    
194
$(document).ready(function(){
195

    
196
        ui.wizard.current_step =1;
197
        ui.wizard.current_position =0;
198

    
199
        ui.wizard.vm.btns.start =$('.new-btn, .add-new');
200
        ui.wizard.vm.btns.previous = $('.bottom').find('.nav.prev');
201
        ui.wizard.vm.btns.next = $('.bottom').find('.nav.next');
202
        ui.wizard.vm.btns.expand_down =$('.adv-main').find('.expand-link');
203
        
204
        $('.wizard .nums').click(function(e){
205
                e.preventDefault();
206
        })
207

    
208
        ui.wizard.initialize_relocation();
209
        ui.wizard.move_to_step();
210
        ui.wizard.set_movement_tags();
211
        ui.wizard.expand_area();
212

    
213
        $('.step-1 .os li:last').find('.btn-col a').focusout(function(e) {
214
                e.preventDefault();
215
                $('.nav.next').focus();
216
                $('.nav.next').addClass('active');
217
        })
218
});