root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / common.js @ c2c9975a
History | View | Annotate | Download (4.5 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 |
ui.VMactionsInit = function(){ |
51 |
|
52 |
// if VM is stopped hide connect option
|
53 |
$('.vms li .container .stopped').parents('.container').find('.options .connect').hide(); |
54 |
|
55 |
var vm_container = $('.vms li .container'); |
56 |
var vm_img = vm_container.find('.img-wrap'); |
57 |
|
58 |
$('.vms li .container .img').mouseenter( |
59 |
function (e) {
|
60 |
$(this).parents('.container').find('.options').fadeIn(); |
61 |
} |
62 |
); |
63 |
|
64 |
$('li .container .options').mouseleave( |
65 |
function(e){
|
66 |
$('li .container .options').fadeOut(); |
67 |
} |
68 |
); |
69 |
|
70 |
$('li .container .check').click(function(e){ |
71 |
e.preventDefault(); |
72 |
var checkbox = $(this).find('.custom_checkbox'); |
73 |
|
74 |
checkbox.toggleClass('checkbox-checked');
|
75 |
|
76 |
if(checkbox.hasClass('checkbox-checked')){ |
77 |
checkbox.html('b');
|
78 |
$(this).parents('.container').find('.options').fadeOut(); |
79 |
|
80 |
} |
81 |
else{
|
82 |
checkbox.html('a');
|
83 |
|
84 |
} |
85 |
if (checkbox.hasClass('checkbox-checked')){ |
86 |
checkbox.parents('.container').find('.more_checkbox').html(checkbox.clone()); |
87 |
|
88 |
} else {
|
89 |
checkbox.parents('.container').find('.more_checkbox').html(''); |
90 |
} |
91 |
ui.cntCheckbox(); |
92 |
}) |
93 |
$('.more_checkbox').on('click', function(e){ |
94 |
|
95 |
var checkbox = $(this).find('span'); |
96 |
checkbox.toggleClass('checkbox-checked');
|
97 |
var self = $(this); |
98 |
if(checkbox.hasClass('checkbox-checked')){ |
99 |
checkbox.html('b');
|
100 |
$(this).parents('.container').find('.options').fadeOut(); |
101 |
self.parents('.container').find('.custom_checkbox').addClass('checkbox-checked'); |
102 |
self.parents('.container').find('.custom_checkbox').html('b'); |
103 |
|
104 |
} |
105 |
else{
|
106 |
checkbox.html('a');
|
107 |
self.parents('.container').find('.custom_checkbox').removeClass('checkbox-checked'); |
108 |
self.parents('.container').find('.custom_checkbox').html('a'); |
109 |
|
110 |
} |
111 |
|
112 |
|
113 |
if (!(checkbox.hasClass('checkbox-checked'))){ |
114 |
self.html('');
|
115 |
} |
116 |
ui.cntCheckbox(); |
117 |
}) |
118 |
} |
119 |
|
120 |
|
121 |
$(document).ready(function(){ |
122 |
|
123 |
ui.closeDiv($('.info .close'), '.info'); |
124 |
ui.closeDiv($('.dummy-navigation .close'), '.dummy-navigation'); |
125 |
|
126 |
$('.dummy-navigation .our').click(function(e){ |
127 |
e.preventDefault(); |
128 |
$('.ours.'+$(this).data('our')).toggle(); |
129 |
$(this).toggleClass('open'); |
130 |
}); |
131 |
|
132 |
ui.setSidebarHeight(); |
133 |
$('.select-os li').click(function(e){ |
134 |
$('.select-os li').removeClass('selected'); |
135 |
$(this).addClass('selected'); |
136 |
}) |
137 |
|
138 |
$('.select-flavor dl span').click(function(e){ |
139 |
console.log('test');
|
140 |
$(this).parents('dl').find('span').removeClass('current'); |
141 |
$(this).addClass('current'); |
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.VMactionsInit(); |
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 |
}) |