Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (9.6 kB)

1
// all functions use pixels
2
ui.wizard ={
3
        current_step: undefined,
4
        total_step:  $('.wizard-content .step').length,
5
        current_position: undefined,
6
        relocation: undefined,
7
        btns: {
8
                start: undefined,
9
                close: undefined,
10
                next: undefined,
11
                previous: undefined,
12
                expand_down: undefined
13
        },
14
        speed: 500,
15

    
16
        set_dimensions: function (){
17
                $('.vm-wizard-carousel').css('width', 100*ui.wizard.total_step+'%');
18
                $('.vm-wizard-carousel .step').css('width', 100/ui.wizard.total_step+'%');
19
                ui.wizard.set_step_height('.step', '.top', '.bottom', '.header');
20
        },
21

    
22
        submit_data: function (){
23
                console.log('submit data dummy function');
24
        },
25

    
26
        data_next_array: ['test1','el2','el4','el7'],
27

    
28
        focus_fun: function(){
29
                // $('.nav.next').attr('data-step',ui.wizard.current_step);
30
                // $('.nav.next').removeAttr('data-next');
31
                // $('.nav.next').attr('data-next', ui.wizard.data_next_array[ui.wizard.current_step]);
32
                // $('.'+ui.wizard.data_next_array[ui.wizard.current_step]+'').first().focus();
33
                // console.log('focus_fun',ui.wizard.data_next_array[ui.wizard.current_step]);
34
        },
35

    
36
        move: function () {
37
                var percentage = -(ui.wizard.current_step-1)*100+'%';
38
                $('.vm-wizard-carousel').stop().animate({ 'left': percentage }, ui.wizard.speed);
39
                ui.wizard.focus_fun();
40
                ui.wizard.indicate_step(ui.wizard.current_step);
41
                ui.wizard.set_movement_tags(ui.wizard.current_step, ui.wizard.btns.previous, ui.wizard.btns.next);
42

    
43
        },
44

    
45
        go_next: function () {
46
                if(ui.wizard.current_step < ui.wizard.total_step){
47
                        ui.wizard.current_step++;
48
                        ui.wizard.move();
49
                }
50
                else {
51
                        ui.wizard.submit_data();
52
                        ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area');
53
                }
54
        },
55

    
56
        go_prev:function() {
57
                if(ui.wizard.current_step > 1){
58
                        ui.wizard.current_step--;
59
                        ui.wizard.move();
60
                }
61
                else {
62
                        ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area');
63
                }
64
        },
65

    
66
        init_events: function(){
67
                ui.wizard.set_dimensions();
68

    
69
                $(document).keydown(function(e) {
70
                        // right arrow keyCode == 39
71
                        // ui.wizard.total_step+1 because current_step has not changed yet
72
                        if(e.keyCode==39 && ui.wizard.current_step!=(ui.wizard.total_step+1)) {
73
                                ui.wizard.go_next();
74
                                return false;
75
                        }
76
                        // left arrow keyCode == 37
77
                        else if(e.keyCode==37 && ui.wizard.current_step!=1) {
78
                                ui.wizard.go_prev();
79
                                return false;
80
                        }
81
                        // ESC
82
                        else if(e.keyCode== 27 && ui.wizard.current_step==1) {
83
                                ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area')
84
                        }
85
                });
86
                
87
                ui.wizard.btns.next.click(function(e){
88
                        ui.wizard.go_next();
89
                })
90

    
91
                ui.wizard.btns.previous.click(function(e){
92
                        ui.wizard.go_prev();
93
                });
94
        },
95

    
96
        // for the carousel index
97
        indicate_step: function(step) {
98
                $('.wizard .top .sub-menu[data-step]').hide();
99
                $('.wizard .top .sub-menu[data-step='+step+']').fadeIn();
100
                $('.nums').children().removeClass('current');
101
                $('.nums li').show();
102
                $('.nums li:nth-child('+ui.wizard.current_step+')').addClass('current');
103
                $('.nums .current').prevAll('li').hide();
104
        },
105

    
106
        // changes the text of next and previous buttons
107
        set_movement_tags: function() {
108
                if (ui.wizard.current_step==1) {
109
                        ui.wizard.btns.previous.find('span').html('CANCEL');
110
                        ui.wizard.btns.next.find('span').html('NEXT');
111
                }
112
                else if(ui.wizard.current_step==ui.wizard.total_step) {
113
                        ui.wizard.btns.previous.find('span').html('PREVIOUS');
114
                        ui.wizard.btns.next.find('span').html('CREATE');
115
                }
116
                else {
117
                        ui.wizard.btns.previous.find('span').html('PREVIOUS');
118
                        ui.wizard.btns.next.find('span').html('NEXT');
119
                }
120
        },
121

    
122
        close: function(bottom_area, main_area, total_area) {
123
                $(bottom_area).hide();
124
                $(main_area).slideUp();
125
                $(total_area).slideUp('slow', function(){
126
                        ui.wizard.reset();
127
                });
128
                 ui.wizard.preselect_elements(bottom_area);
129
            ui.wizard.preselect_elements(main_area);
130
            ui.wizard.preselect_elements(total_area);
131
        },
132

    
133
        // manually sets elements to a initial state
134
        reset: function() {
135
                  ui.wizard.current_step = 1;
136
        $('.vm-wizard-carousel').css('left',0);
137
        $('.bottom').show();
138
        ui.wizard.indicate_step(ui.wizard.current_step);
139
        ui.wizard.set_movement_tags();
140
        $('.networks-area .more').show();
141
        $('.details').hide();
142
        $('.vm-name input').val('');
143
        $('.advanced-conf-options').hide();
144
        $('.snf-color-picker').hide();
145
        $('.step').scrollTop(0);
146
        },
147

    
148
        expand_area: function() {
149
                ui.wizard.btns.expand_down.click(function(e){
150
                // e.preventDefault();
151
                      ui.expandArrow(ui.wizard.btns.expand_down);
152
                ui.wizard.btns.expand_down.parents('div.advanced-conf-step').find('.advanced-conf-options').stop().slideToggle();
153
            })
154
        },
155
        focus_custom: function(el, step) {
156
                el.focus();
157
                el.attr('data-step',step);
158
        },
159

    
160
        preselect_elements: function(area) {
161
        $(area).find('.current').not('.preselected').removeClass('current');
162
        $(area).find('.preselected').not('.current').addClass('current'); //needs improvement
163
        $(area).find('.snf-radio-checked').not('.preselected').toggleClass('snf-radio-checked snf-radio-unchecked');
164
        $(area).find('.snf-radio-unchecked.preselected').toggleClass('snf-radio-checked snf-radio-unchecked');
165
        $(area).find('.snf-checkbox-checked').not('.preselected').toggleClass('snf-checkbox-checked snf-checkbox-unchecked');
166
        $(area).find('.snf-checkbox-unchecked.preselected').toggleClass('snf-checkbox-checked snf-checkbox-unchecked');
167
        $('.expand-link').find('.snf-arrow-up').toggleClass('snf-arrow-up snf-arrow-down'); //needs improvement
168
     },
169

    
170
     set_step_height: function(stepEl, fixedTopEl, fixedBottomEl, headerEl) {
171
                topHeight = $(fixedTopEl).height();
172
                bottomHeight = $('.bottom .row').height();
173
                totalHeight        = $(window).height();
174
                headerHeight = $(headerEl).height();
175
                stepHeight = totalHeight-topHeight-bottomHeight-headerHeight;
176
                console.log('stepHeight: ', stepHeight)
177
                tt=stepEl;
178
                $(stepEl).outerHeight(stepHeight);
179
                $('.wizard-content').outerHeight(stepHeight);        
180
        },
181

    
182

    
183

    
184
}
185

    
186

    
187
$(document).ready(function(){
188

    
189
/*
190
Various functions for vm creation wizard
191
*/
192

    
193
/* step functions */
194
/* step-1: Pick OS */
195
         $('.wizard .os > li').click(function(e){
196
        e.preventDefault();
197
        $('.wizard .os >li').removeClass('current');
198
        $(this).addClass('current');
199
    });
200

    
201
    $('.os .btn-col a').click( function(e){
202
        e.preventDefault();
203
        e.stopPropagation();
204
        $(this).toggleClass('current');
205
        $(this).parents('li').find('.details').stop().slideToggle();
206
    });
207

    
208

    
209
/* step-2: Select flavor */
210
    $('.wizard .sub-menu a[data-size]').on( "click", function(e) {
211
        e.preventDefault();
212
        $(this).parents('.sub-menu').find('a').removeClass('current');
213
        $(this).addClass('current');
214
        ui.pickResources($(this).data('size')); 
215
    });
216

    
217
    $('.wizard .flavor .options a').click(function(e){
218
        e.preventDefault();
219
        $('.wizard .sub-menu a[data-size]').removeClass('current');
220
        $(this).parents('.options').find('a').removeClass('current');
221
        $(this).addClass('current');
222
    });
223

    
224
/* step-3: Advanced options */
225
   
226
    $('.advanced-conf-options .checkbox').click(function(e){
227
        e.preventDefault();
228
        var checkbox = $(this).find('.check');
229
        ui.changeCheckboxState(checkbox);
230
        if($(this).hasClass('has-more')) {
231
            $(this).next('.more').slideToggle();
232
        }
233
    });
234

    
235
           $('.show-add-tag').click(function(e){
236
        e.preventDefault();
237
        $(this).parents('.tags-area').find('.snf-color-picker').slideDown();
238
        goToByScroll('hide-add-tag');
239
        ui.colorPickerVisible =1;
240
    });
241

    
242
    $('.hide-add-tag').click(function(e){
243
        e.preventDefault();
244
        $(this).parents('.snf-color-picker').slideUp('400', function(){
245
            ui.colorPickerVisible = 0;
246
        });
247
    });
248

    
249
    $('.checkbox .check').click(function(e) {
250
                e.stopPropagation();
251

    
252
                if($(this).closest('.checkbox').hasClass('has-more')) {
253
            $(this).parent().next('.more').slideToggle();
254
        }
255
        })
256
/* end of step functions */
257

    
258
/* navigation and numbers functions */
259
$('.nav.previous').focus(function(e){
260
        $(this).addClass('active');
261
});
262

    
263
$('.nav.previous').focusout(function(e){
264
        $(this).removeClass('active');
265

    
266
});
267

    
268
$('.sub-menu[data-step=2] li:last').find('a').focusout(function(e) {
269
        $('.step-2').find('.dropdown a:first').focus();
270

    
271
});
272

    
273
$('.os .name-col').focus(function(e){
274
        $(this).parents('li').addClass('hover');
275
});
276

    
277
$('.os .name-col').focusout(function(e){
278
        $(this).parents('li').removeClass('hover');
279
});
280

    
281

    
282
/* end of navigation and numbers functions */
283

    
284

    
285
/* focus and tabs functionality */
286

    
287
$('a').keyup(function(e){
288
        var self = this;
289
        if (e.keyCode==9||e.which==9){
290
                if ($(self).attr('data-next')) {
291
                        $(self).focusout(function(e){
292
                                var classname = $(self).data('next');
293
                                console.log('tab goes to ',classname);
294
                                $('.'+classname+'').first().focus();
295
                        })
296
                }
297
        }
298
})
299

    
300

    
301
// make sure that is always correctly moved
302
/*$('a, input').focus(function(e){
303
        if ($(this).parents('.step').data('step')> 0) {
304
                if ( ui.wizard.current_step == ($(this).parents('.step').data('step'))) {
305
                } else {
306
                        ui.wizard.current_step = $(this).parents('.step').data('step');
307
                        ui.wizard.move();
308
                }
309
        }
310
})
311
*//* end of focus and tabs functionality */
312

    
313
        $('#vm-wizard').find('a').click(function(e) {
314
                e.preventDefault();
315
        });
316
        ui.wizard.current_step =1;
317
        ui.wizard.btns.previous = $('.bottom').find('.nav.prev');
318
        ui.wizard.btns.next = $('.bottom').find('.nav.next');
319
        ui.wizard.btns.expand_down =$('.adv-main').find('.expand-link');
320
        ui.wizard.btns.close =$('#vm-wizard').find('.close');
321
        ui.wizard.init_events();
322
        ui.wizard.set_movement_tags();
323
        ui.wizard.expand_area();
324
        ui.wizard.btns.close.click(function(e) {
325
                ui.wizard.close('.bottom', '#vm-wizard', '.overlay-area')
326
        });
327

    
328
        $(window).resize(function() {
329
                ui.wizard.set_step_height('.step', '.top', '.bottom', '.header')
330
        });
331
});