Revision d3bfabe8 snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/common.js

b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/common.js
2 2

  
3 3

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

  
11 11

  
12 12
// set lt-sidebar height 
13 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);
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 23
}
24 24

  
25 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;
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 29
    $('.header .main-actions li a').removeClass('active');  
30 30
    if ( (running*stopped) > 0 ){          
31 31
         $('.header .main-actions li.both a').addClass('active');   
32 32
         $('.header .main-actions li.single a').removeClass('active');   
33 33
    } else {
34 34
        if (running > 0) {
35
         	$('.header .main-actions li.both a').addClass('active');   
36
         	$('.header .main-actions li.running a').addClass('active');   
35
            $('.header .main-actions li.both a').addClass('active');   
36
            $('.header .main-actions li.running a').addClass('active');   
37 37
        } else if (stopped>0) {
38
        	$('.header .main-actions li.both a').addClass('active');   
39
        	$('.header .main-actions li.stopped a').addClass('active');   
38
            $('.header .main-actions li.both a').addClass('active');   
39
            $('.header .main-actions li.stopped a').addClass('active');   
40 40

  
41 41
        } else {
42 42

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

  
48 48
    }
......
50 50

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

  
62 62
ui.VMactionsInit = function(){
63 63

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

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

  
70
	$('.vms li .container .img').mouseenter(
70
    $('.vms li .container').mouseenter(
71 71
      function (e) {
72
        $(this).parents('.container').find('.options').fadeIn();
72
        $(this).find('.img').css('visibility','hidden');
73
        $(this).find('.options, .check').fadeIn('slow');
74
        $(this).addClass('set-border');
75
        $(this).find('.editable input').show();
76
        $(this).find('.editable em').hide();
77
        $(this).find('.visible-info em').each(function(){
78
            var emLeft = $(this).position();
79
            $(this).animate({
80
            left: -emLeft.left,
81
            }, 'slow');        
82
        }) 
73 83
      }
74 84
    );
75 85

  
76
    $('li .container .options').mouseleave(
86
    $('.vms li .container').mouseleave(
77 87
        function(e){
78
            $('li .container .options').fadeOut();
79
        }
88
            $(this).removeClass('set-border');
89
            $(this).find('.img').css('visibility','visible');
90
            $(this).find('.options').hide(); 
91
            $(this).find('.custom_checkbox:not(.checkbox-checked)').parents('.check').hide();
92
            $(this).find('.editable input').hide();
93
            $(this).find('.editable em').show();
94
            $(this).find('.visible-info em').each(function(){
95
                $(this).removeAttr('style');   
96
            }) 
97
         }
80 98
    );
81 99

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

  
......
87 105
        
88 106
        if(checkbox.hasClass('checkbox-checked')){
89 107
            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
            
108
            $(this).parents('.container').addClass('set-bg');
117 109
        }
118 110
        else{
119 111
            checkbox.html('a'); 
120
            self.parents('.container').find('.custom_checkbox').removeClass('checkbox-checked');
121
            self.parents('.container').find('.custom_checkbox').html('a');
112
            $(this).parents('.container').removeClass('set-bg');
122 113
      
123 114
        }
115
        $(this).parents('.container').removeClass('set-border');
116
        $(this).parents('.container').find('.img').css('visibility','visible');
117
        $(this).parents('.container').find('.options').hide(); 
124 118

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

  
134 124

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

  
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
	})
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
    })
167 158

  
168 159
})
169 160

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

  
173 164
})

Also available in: Unified diff