Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.6 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 = $('.checkbox-checked').length;
27
    var running = $('.checkbox-checked').parents('.container').find('.img.running').length;
28
    var stopped = $('.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 ($('.check 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 .container .stopped').parents('.container').find('.options .connect').hide();
66
    
67
    $('.vms li .container').mouseenter(
68
      function (e) {
69
        $(this).find('.img').stop(true, true).fadeOut({
70
            'duration':200,
71
        });
72
        $(this).find('.options, .check').stop(true, true).addClass('active');
73
        $(this).find('.options').stop(true, true).fadeIn(500); 
74
        $(this).stop(true, true).addClass('set-border');
75
        $(this).find('.visible-info em').stop(true, true).each(function(){
76
            var emLeft = $(this).position();
77
            $(this).animate({
78
            left: -emLeft.left,
79
            }, 300);        
80
        }) 
81
      }
82
    );
83

    
84
    $('.vms li .container').mouseleave(
85
        function(e){
86
            $(this).stop(true, true).removeClass('set-border');
87
            $(this).find('.options').stop(true, true).fadeOut(200); 
88
            $(this).find('.img').stop(true, true).fadeIn('slow');
89
            $(this).find('.custom_checkbox:not(.checkbox-checked)').parents('.check').stop(true, true).removeClass('active');
90
            $(this).find('.visible-info em').stop(true, true).each(function(){
91
                $(this).animate({
92
                 left: 0,
93
                }, 300);        
94
            }) 
95
         }
96
    );
97

    
98
    $('.vms .container .check').click(function(e){
99
        e.preventDefault();
100

    
101
        var checkbox = $(this).find('.custom_checkbox');
102

    
103
        checkbox.toggleClass('checkbox-checked');
104
        
105
        if(checkbox.hasClass('checkbox-checked')){
106
            checkbox.html('b');
107
            $(this).parents('.container').addClass('set-bg');
108
            $(this).addClass('active');
109
        }
110
        else{
111
            checkbox.html('a'); 
112
            $(this).parents('.container').removeClass('set-bg');
113
            $(this).removeClass('active');
114
      
115
        }
116

    
117
        
118

    
119
        ui.cntCheckbox();
120
    })
121
   
122
}
123

    
124

    
125
$(document).ready(function(){
126

    
127
    ui.closeDiv($('.info .close'), '.info');
128
    ui.closeDiv($('.dummy-navigation .close'), '.dummy-navigation');
129

    
130
    $('.dummy-navigation .our').click(function(e){
131
        e.preventDefault();
132
        $('.ours.'+$(this).data('our')).toggle();
133
        $(this).toggleClass('open');
134
    });
135

    
136
    ui.setSidebarHeight();
137
    $('.select-os li').click(function(e){
138
        $('.select-os li').removeClass('selected');
139
        $(this).addClass('selected');
140
    })
141

    
142
    
143
    if ($('.overlay').length >0 ){
144
        $('body').addClass('with-overlay');
145
    }
146

    
147
    $('.new-btn a.current').click(function(e){
148
        e.preventDefault();
149
    })
150

    
151
    ui.VMactionsInit();
152

    
153
    $('.main-actions li a').click(function(e){
154
        if (!($(this).hasClass('active'))) {
155
            e.preventDefault();
156
        }
157
    })
158

    
159
})
160

    
161
$(window).resize(function(e){
162
    ui.setSidebarHeight();
163

    
164
})