Statistics
| Branch: | Tag: | Revision:

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

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
    
18
    if (h2>h1) {
19
        var ltSidebarHeight = h2;
20
    } else {
21
        var ltSidebarHeight = h1;
22
    }
23
    $('.lt-sidebar').height(ltSidebarHeight);
24
}
25

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

    
42
        } else {
43

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

    
49
    }
50
}
51

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

    
60
}
61

    
62

    
63
ui.EntitiesActionsInit = function(){
64

    
65
    // if VM is stopped hide connect option 
66
    $('.vms .container .stopped').parents('.container').find('.options .connect').hide();
67
    
68
    $('.entities li .container').mouseenter(
69
      function (e) {
70
        $(this).find('.img').stop(true, true).fadeOut({
71
            'duration':200,
72
        });
73
        $(this).find('.options, .check').stop(true, true).addClass('active');
74
        $(this).find('.options').stop(true, true).fadeIn(500); 
75
        $(this).stop(true, true).addClass('set-border');
76
        $(this).find('.visible-info em').stop(true, true).each(function(){
77
            var emLeft = $(this).position();
78
            $(this).animate({
79
            left: -emLeft.left,
80
            }, 300);        
81
        }) 
82
      }
83
    );
84

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

    
99
    $('.entities .container .check').click(function(e){
100
        e.preventDefault();
101

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

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

    
118
        
119

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

    
125

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

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

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

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

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

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

    
152
    ui.EntitiesActionsInit();
153

    
154
    $('.main-actions li a').click(function(e){
155
        if (!($(this).hasClass('active'))) {
156
            e.preventDefault();
157
        }
158
    })
159
    $('.scroll-pane').jScrollPane();
160
})
161

    
162
$(window).resize(function(e){
163
    ui.setSidebarHeight();
164
    $('.scroll-pane').jScrollPane();
165
})