Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ 8b3ba816

History | View | Annotate | Download (3.8 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 = $('.overlay-wrapper').width();
12
                console.log(ui.wizard.relocation);
13
                $('.vm-wizard-carousel').children('div').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
                // when the button "next" is pressed show the next step (if there is a next step)
38
                next_btn.click(function(){
39
                        event.preventDefault();
40
                        console.log('you clicked next!')
41
                        if(ui.wizard.current_step < ui.wizard.vm.total_step){
42
                                prev_btn.find('span').html('PREVIOUS');
43
                                ui.wizard.current_step++;
44
                                ui.wizard.current_position -=ui.wizard.relocation;
45
                                $('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
46
                                ui.wizard.indicate_step(ui.wizard.current_step);
47
                                ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
48

    
49
                                if(ui.wizard.current_step == 3) {
50
                                        setTimeout(function() { $('.vm-name').find('input').focus() }, speed/2);
51
                                }
52

    
53
                        }
54
                        else {
55
                                console.log('This is the last step.');
56
                        }
57
                })
58

    
59
                // when the button "previous" is pressed show the previous step (if there is a previous step)
60
                prev_btn.click(function(){
61
                        event.preventDefault();
62
                        if(ui.wizard.current_step > 1){
63
                                ui.wizard.current_step--;
64
                                ui.wizard.current_position +=ui.wizard.relocation;
65
                                $('.vm-wizard-carousel').animate({left: ui.wizard.current_position+'px'}, speed);
66
                                ui.wizard.indicate_step(ui.wizard.current_step);
67
                                ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
68
                        }
69
                        else {
70
                                console.log('This is the 1st step.')
71
                        }
72
                })
73
        },
74

    
75
        // sets the width and height of the steps and of the carousel (in PIXELS)
76
        initialize_relocation: function(start_btns){
77
                start_btns.click(function() {
78
                        event.preventDefault();
79
                        console.log('initialize_relocation');
80
                        ui.wizard.adjust_to_resized_screen();
81
                        ui.wizard.set_dimensions();
82
                })
83
        },
84
        // for the carousel index
85
        indicate_step: function(step) {
86
                $('.wizard .top .sub-menu[data-step]').hide();
87
                $('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
88
                $('.nums').children().removeClass('current');
89
                $('.nums').children().find('a:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current');
90
        },
91

    
92

    
93
        set_movement_tags: function(step, left_btn, right_btn) {
94
                if (step==1) {
95
                        left_btn.find('span').html('CANCEL');
96
                }
97
                else if(step==ui.wizard.vm.total_step) {
98
                        right_btn.find('span').html('CREATE');
99
                }
100
                else {
101
                        left_btn.find('span').html('PREVIOUS');
102
                        right_btn.find('span').html('NEXT');
103
                }
104
        }
105
}
106

    
107

    
108
$(document).ready(function(){
109

    
110
        ui.wizard.current_step =1;
111
        ui.wizard.current_position =0;
112

    
113
        var new_vm_btn =$('.new-btn, .add-new');
114
        var prev_btn = $('.bottom').find('.nav.prev');
115
        var next_btn = $('.bottom').find('.nav.next');
116
        $('.wizard .nums').click(function(e){
117
                e.preventDefault();
118
        })
119

    
120
        ui.wizard.initialize_relocation(new_vm_btn);
121
        ui.wizard.move_to_step(prev_btn, next_btn);
122
        ui.wizard.set_movement_tags(ui.wizard.current_step, prev_btn, next_btn);
123

    
124

    
125
});