Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / common.js @ a18bd0ed

History | View | Annotate | Download (4.7 kB)

1
ui = {};
2

    
3

    
4
ui.closeDiv = function(closeEl, divToCloseClass) {
5
        closeEl.click(function(e){
6
                e.preventDefault();
7
                $(this).parents(divToCloseClass).slideUp('slow');
8
        });
9
}
10

    
11

    
12
// set lt-sidebar height 
13
ui.setSidebarHeight = function(){
14
        var WindowHeight = $(window).height();
15
        var h1= WindowHeight - $('.header').outerHeight();
16
        var h2= $('.main.details').outerHeight();
17
        if (h2>h1) {
18
                var ltSidebarHeight = h2;
19
        } else {
20
                var ltSidebarHeight = h1;
21
        }
22
        $('.lt-sidebar').height(ltSidebarHeight);
23
}
24

    
25
ui.cntCheckbox = function(){ 
26
        var all = $('.options .checkbox-checked').length;
27
        var running = $('.options .checkbox-checked').parents('.container').find('.img.running').length;
28
        var stopped = $('.options .checkbox-checked').parents('.container').find('.img.stopped').length;
29
    $('.header .main-actions li a').removeClass('active');  
30
    if ( (running*stopped) > 0 ){          
31
         $('.header .main-actions li.both a').addClass('active');   
32
         $('.header .main-actions li.single a').removeClass('active');   
33
    } else {
34
        if (running > 0) {
35
                 $('.header .main-actions li.both a').addClass('active');   
36
                 $('.header .main-actions li.running a').addClass('active');   
37
        } else if (stopped>0) {
38
                $('.header .main-actions li.both a').addClass('active');   
39
                $('.header .main-actions li.stopped a').addClass('active');   
40

    
41
        } else {
42

    
43
        }
44
        if ( all > 1 ) {
45
                $('.header .main-actions li.single a').removeClass('active');   
46
        }
47

    
48
    }
49
}
50

    
51
ui.setCheckedVMBgColor = function(){
52
    console.log('test');
53
    if ($('.more_checkbox span').length >0) {
54
        $('.more_checkbox .checkbox-checked').parents('.container').addClass('set-bg');
55
    } else {
56
        $('.more_checkbox').parents('.container').removeClass('set-bg');    
57
    }
58

    
59
}
60

    
61

    
62
ui.VMactionsInit = function(){
63

    
64
        // if VM is stopped hide connect option 
65
        $('.vms li .container .stopped').parents('.container').find('.options .connect').hide();
66

    
67
        var vm_container = $('.vms li .container');
68
        var vm_img = vm_container.find('.img-wrap');
69

    
70
        $('.vms li .container .img').mouseenter(
71
      function (e) {
72
        $(this).parents('.container').find('.options').fadeIn();
73
      }
74
    );
75

    
76
    $('li .container .options').mouseleave(
77
        function(e){
78
            $('li .container .options').fadeOut();
79
        }
80
    );
81

    
82
    $('li .container .check').click(function(e){
83
        e.preventDefault();
84
        var checkbox = $(this).find('.custom_checkbox');
85

    
86
        checkbox.toggleClass('checkbox-checked');
87
        
88
        if(checkbox.hasClass('checkbox-checked')){
89
            checkbox.html('b');
90
            $(this).parents('.container').find('.options').fadeOut();
91
            
92
        }
93
        else{
94
            checkbox.html('a'); 
95
      
96
        }
97
        if (checkbox.hasClass('checkbox-checked')){
98
            checkbox.parents('.container').find('.more_checkbox').html(checkbox.clone());
99
            
100
        } else {
101
                 checkbox.parents('.container').find('.more_checkbox').html('');
102
        }
103
        ui.setCheckedVMBgColor();
104
        ui.cntCheckbox();
105
    })
106
    $('.more_checkbox').on('click', function(e){
107
            
108
        var checkbox = $(this).find('span');
109
        checkbox.toggleClass('checkbox-checked');
110
        var self = $(this);
111
        if(checkbox.hasClass('checkbox-checked')){
112
            checkbox.html('b');
113
            $(this).parents('.container').find('.options').fadeOut();
114
            self.parents('.container').find('.custom_checkbox').addClass('checkbox-checked');
115
            self.parents('.container').find('.custom_checkbox').html('b');
116
            
117
        }
118
        else{
119
            checkbox.html('a'); 
120
            self.parents('.container').find('.custom_checkbox').removeClass('checkbox-checked');
121
            self.parents('.container').find('.custom_checkbox').html('a');
122
      
123
        }
124

    
125
        
126
        if (!(checkbox.hasClass('checkbox-checked'))){
127
                 self.html('');
128
        }
129
        ui.setCheckedVMBgColor();
130
        ui.cntCheckbox();
131
    })
132
}
133

    
134

    
135
$(document).ready(function(){
136

    
137
        ui.closeDiv($('.info .close'), '.info');
138
        ui.closeDiv($('.dummy-navigation .close'), '.dummy-navigation');
139

    
140
        $('.dummy-navigation .our').click(function(e){
141
                e.preventDefault();
142
                $('.ours.'+$(this).data('our')).toggle();
143
                $(this).toggleClass('open');
144
        });
145

    
146
        ui.setSidebarHeight();
147
        $('.select-os li').click(function(e){
148
                $('.select-os li').removeClass('selected');
149
                $(this).addClass('selected');
150
        })
151

    
152
        
153
        if ($('.overlay').length >0 ){
154
                $('body').addClass('with-overlay');
155
        }
156

    
157
        $('.new-btn a.current').click(function(e){
158
                e.preventDefault();
159
        })
160

    
161
        ui.VMactionsInit();
162
        $('.main-actions li a').click(function(e){
163
                if (!($(this).hasClass('active'))) {
164
                        e.preventDefault();
165
                }
166
        })
167

    
168
})
169

    
170
$(window).resize(function(e){
171
        ui.setSidebarHeight();
172

    
173
})