Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ 6d7b9bc4

History | View | Annotate | Download (5.5 kB)

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 = $(window).width();
12
                console.log(ui.wizard.relocation);
13
                $('.vm-wizard-carousel').children('div.step').width(ui.wizard.relocation);
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
                var speed =500;
37

    
38
                // carousel movement when right or left arrow is pressed
39
                $(document).keydown(function(e) {
40
                        if(e.keyCode==39) {
41
                                go_next();
42
                                return false;
43
                        }
44
                        else if(e.keyCode==37) {
45
                                go_prev();
46
                                return false;
47
                        }
48
                });
49
                
50
                // when the button "next" is pressed show the next step (if there is a next step)
51
                next_btn.click(function(e){
52
                        e.preventDefault();
53
                        go_next();
54
                })
55

    
56
                // when the button "previous" is pressed show the previous step (if there is a previous step)
57
                prev_btn.click(function(e){
58
                        e.preventDefault();
59
                        go_prev();
60
                        
61
                });
62

    
63

    
64
                function go_next() {
65
                        console.log('going next!');
66
                        console.log('you clicked next!')
67
                        if(ui.wizard.current_step < ui.wizard.vm.total_step){
68
                                ui.wizard.current_step++;
69
                                ui.wizard.current_position -=ui.wizard.relocation;
70
                                $('.vm-wizard-carousel').finish();
71
                                $('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
72
                                ui.wizard.indicate_step(ui.wizard.current_step);
73
                                ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
74

    
75
                                if(ui.wizard.current_step == 3) {
76
                                        setTimeout(function() { $('.vm-name').find('input').focus() }, speed/2);
77
                                }
78

    
79
                        }
80
                        else {
81
                                console.log('This is the last step.');
82
                                ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area');
83
                        }
84
                }
85

    
86
                function go_prev() {
87
                        if(ui.wizard.current_step > 1){
88
                                ui.wizard.current_step--;
89
                                ui.wizard.current_position +=ui.wizard.relocation;
90
                                $('.vm-wizard-carousel').finish();
91
                                $('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
92
                                ui.wizard.indicate_step(ui.wizard.current_step);
93
                                ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
94

    
95
                                if(ui.wizard.current_step == 3) {
96
                                        setTimeout(function() { $('.vm-name').find('input').focus() }, speed/2);
97
                                }
98
                        }
99
                        else {
100
                                console.log('This is the 1st step.')
101
                                ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area');
102
                        }
103
                }
104
        },
105

    
106
        // sets the width and height of the steps and of the carousel (in PIXELS)
107
        initialize_relocation: function(start_btns){
108
                        console.log('initialize_relocation');
109
                        start_btns.click(function(e) {
110
                                e.preventDefault();        
111
                                ui.wizard.reset();
112
                                ui.wizard.adjust_to_resized_screen();
113
                                ui.wizard.set_dimensions();
114
                        })
115
        },
116

    
117
        // for the carousel index
118
        indicate_step: function(step) {
119
                $('.wizard .top .sub-menu[data-step]').hide();
120
                $('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
121
                $('.nums').children().removeClass('current');
122
                $('.nums').children().find('a:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current');
123
        },
124

    
125
        // changes the text of next and previous buttons
126
        set_movement_tags: function(step, left_btn, right_btn) {
127
                if (step==1) {
128
                        left_btn.find('span').html('CANCEL');
129
                        right_btn.find('span').html('NEXT');
130
                }
131
                else if(step==ui.wizard.vm.total_step) {
132
                        left_btn.find('span').html('PREVIOUS');
133
                        right_btn.find('span').html('CREATE');
134
                }
135
                else {
136
                        left_btn.find('span').html('PREVIOUS');
137
                        right_btn.find('span').html('NEXT');
138
                }
139
        },
140

    
141
        close: function(bottom_area, main_area, total_area) {
142
                $(bottom_area).hide();
143
                $(main_area).slideUp();
144
                $(total_area).slideUp();
145
        },
146

    
147
        // manually sets elements to a initial state
148
        reset: function() {
149
                ui.wizard.current_step = 1;
150
                ui.wizard.current_position = 0;
151
                
152
                $('.vm-wizard-carousel').css({left: ui.wizard.current_position+'px'});
153
                $('.bottom').show();
154
                $('.step-1').find('.current').removeClass('current');
155
                ui.wizard.indicate_step(ui.wizard.current_step);
156
                $('#vm-wizard').find('.snf-checkbox-checked').addClass('snf-checkbox-unchecked').removeClass('snf-checkbox-checked');
157
                $('#vm-wizard').find('.default').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked');
158
                $('.details').hide();
159
                $('.wizard .top .sub-menu[data-step="1"] ul li:first-child a').addClass('current');
160
                ui.pickResources('small');
161
                //$('.wizard .step-2 .options li a:contains(DRBD)').addClass('current')
162
                $('.vm-name input').val('');
163
                $('.advanced-conf-options').hide();
164
                $('.snf-color-picker').hide();
165

    
166

    
167
        }
168

    
169
}
170

    
171

    
172
$(document).ready(function(){
173

    
174
        ui.wizard.current_step =1;
175
        ui.wizard.current_position =0;
176

    
177
        var new_vm_btn =$('.new-btn, .add-new');
178
        var prev_btn = $('.bottom').find('.nav.prev');
179
        var next_btn = $('.bottom').find('.nav.next');
180
        $('.wizard .nums').click(function(e){
181
                e.preventDefault();
182
        })
183

    
184
        ui.wizard.initialize_relocation(new_vm_btn);
185
        ui.wizard.move_to_step(prev_btn, next_btn);
186
        ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
187
        
188

    
189
});