Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / vm-wizard.js @ 188fe5d9

History | View | Annotate | Download (3.1 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
                // 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
                $('.wizard .top .sub-menu[data-step]').hide();
79
                $('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
80
                $('.nums').children().removeClass('current');
81
                $('.nums').children().find('a:contains("'+ui.wizard.current_step+'")').parent('li').addClass('current');
82
        }
83
}
84

    
85

    
86
$(document).ready(function(){
87

    
88
ui.wizard.current_step =1;
89
ui.wizard.current_position =0;
90

    
91
var new_vm_btn =$('.new-btn, .add-new');
92
var prev_btn = $('.bottom').find('.nav.prev');
93
var next_btn = $('.bottom').find('.nav.next');
94
$('.wizard .nums').click(function(e){
95
        e.preventDefault();
96
})
97

    
98
ui.wizard.initialize_relocation(new_vm_btn);
99
ui.wizard.move_to_step(prev_btn, next_btn);
100

    
101

    
102
});