root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / common.js @ c997f7b6
History | View | Annotate | Download (28.7 kB)
1 |
/*
|
---|---|
2 |
* Various functions that will be used throughout all templates
|
3 |
* are inside ui Object
|
4 |
*/
|
5 |
|
6 |
ui = {}; |
7 |
/*
|
8 |
* ui.wizards get populated in vm-wizard.js
|
9 |
* here is the declaration only
|
10 |
*/
|
11 |
ui.wizard = {}; |
12 |
|
13 |
/* when closeEl el is clicked, its parent with class divToCloseClass slidesUp */
|
14 |
ui.closeDiv = function(closeEl, divToCloseClass) { |
15 |
closeEl.click(function(e){
|
16 |
e.preventDefault(); |
17 |
$(this).parents(divToCloseClass).slideUp('slow'); |
18 |
}); |
19 |
} |
20 |
|
21 |
|
22 |
ui.trimChars = function( str, chars) { |
23 |
if ( str.length>chars){
|
24 |
return $.trim(str).substring(0, chars)+ "..."; |
25 |
} else {
|
26 |
return str;
|
27 |
} |
28 |
} |
29 |
|
30 |
|
31 |
/* Sets element min-height
|
32 |
* Used for .details, .lt-bar divs
|
33 |
*/
|
34 |
ui.setElminHeight = function(el){ |
35 |
var WindowHeight = $(window).height(); |
36 |
var header = $('.header').outerHeight(); |
37 |
var actions = $('.actions-bar').height(); |
38 |
var h1= WindowHeight - (header+actions);
|
39 |
el.css('min-height', h1);
|
40 |
} |
41 |
|
42 |
/* Sets element height
|
43 |
* Used for .details, .lt-bar divs
|
44 |
*/
|
45 |
ui.setElHeight = function(el){ |
46 |
var WindowHeight = $(window).height(); |
47 |
var header = $('.header').outerHeight(); |
48 |
var actions = $('.actions-bar').height(); |
49 |
var h1= WindowHeight - (header+actions);
|
50 |
el.css('height', h1);
|
51 |
} |
52 |
|
53 |
/* Sets element max-height
|
54 |
* Used for div.storage-progress
|
55 |
*/
|
56 |
ui.setElmaxHeight = function(el){ |
57 |
var WindowHeight = $(window).height(); |
58 |
var header = $('.header').outerHeight(); |
59 |
var actions = $('.actions-bar').height(); |
60 |
var h1= WindowHeight - (header+actions);
|
61 |
el.css('max-height', h1);
|
62 |
} |
63 |
|
64 |
/*
|
65 |
* Logic for Entities actions. Present in items_list pages
|
66 |
* Available categories are :
|
67 |
* - both/single ( for multiple entities/single entities)
|
68 |
* - running/off ( for running/off entities)
|
69 |
* - permanent ( for entities always active )
|
70 |
* Can be used for pithos as well
|
71 |
* Available categories are :
|
72 |
* - files ( for files only actions)
|
73 |
* - folders ( for folders only actions)
|
74 |
* - all ( for files/folders actions)
|
75 |
*/
|
76 |
ui.entitiesActionsEnabled = function(){ |
77 |
var all = $('.snf-checkbox-checked').length; |
78 |
var running = $('.snf-checkbox-checked').parents('li.running').length; |
79 |
var off = $('.snf-checkbox-checked').parents('li.off').length; |
80 |
var files = $('.snf-checkbox-checked').parents('li.file').length; |
81 |
var folders = $('.snf-checkbox-checked').parents('li.folder').length; |
82 |
|
83 |
console.log(files,'files');
|
84 |
console.log(folders,'folders');
|
85 |
|
86 |
$('.lt-bar .lt-actions li:not(.permanent) a').removeClass('active'); |
87 |
|
88 |
if ( ( files * folders )>0 ) { |
89 |
$('.lt-actions li.all a').addClass('active'); |
90 |
} else {
|
91 |
if ( files>0 ) { |
92 |
$('.lt-actions li.files a').addClass('active'); |
93 |
} |
94 |
if ( folders>0 ){ |
95 |
$('.lt-actions li.folders a').addClass('active'); |
96 |
} |
97 |
} |
98 |
|
99 |
if ( (running*off) > 0 ){ |
100 |
$('.lt-actions li.both a').addClass('active'); |
101 |
$('.lt-actions li.single a').removeClass('active'); |
102 |
} else {
|
103 |
if (running > 0) { |
104 |
$('.lt-actions li.both a').addClass('active'); |
105 |
$('.lt-actions li.running a').addClass('active'); |
106 |
} else if (off>0) { |
107 |
$('.lt-actions li.both a').addClass('active'); |
108 |
$('.lt-actions li.off a').addClass('active'); |
109 |
} |
110 |
if ( all > 1 ) { |
111 |
$('.lt-actions li.single a').removeClass('active'); |
112 |
} |
113 |
} |
114 |
} |
115 |
|
116 |
ui.inactiveActions = function() { |
117 |
|
118 |
// Availble actions: connect, reboot, shut, destroy, start
|
119 |
// These actions will be DISABLED
|
120 |
var statesActions ={
|
121 |
'off' : ['connect', 'reboot', 'shut'], |
122 |
'error' : ['connect', 'reboot', 'shut', 'start'], |
123 |
'building' : ['reboot', 'start'], |
124 |
'running' : ['start'], |
125 |
'rebooting': ['start'], |
126 |
'starting' : ['start'], |
127 |
'shutting' : ['connect', 'reboot', 'shut'] |
128 |
} ; |
129 |
|
130 |
_.each (statesActions, function(val, key) {
|
131 |
_.each(val, function(value) {
|
132 |
var el = '.' + key + ' .' + value; |
133 |
$(el).addClass('inactive'); |
134 |
}); |
135 |
}) |
136 |
} |
137 |
|
138 |
ui.detailsCustom = function(area) { |
139 |
// position last connected item
|
140 |
var el = area.find('.item').last(); |
141 |
// -2 is the border width;
|
142 |
var moveY = el.find('.connections >li').last().outerHeight(true) - 2; |
143 |
el.css('top',moveY);
|
144 |
el.css('marginTop', -moveY);
|
145 |
} |
146 |
|
147 |
ui.firewallSetup = function(){ |
148 |
$('.firewall').each(function(){ |
149 |
$(this).removeClass('fully unprotected basic'); |
150 |
$(this).addClass($(this).data('firewall')); |
151 |
if($(this).hasClass('unprotected')){ |
152 |
$(this).find('p').first().find('em').html('off'); |
153 |
} else {
|
154 |
$(this).find('p').first().find('em').html('on'); |
155 |
} |
156 |
}); |
157 |
} |
158 |
|
159 |
ui.checkedListItems = function (){ |
160 |
$('.list-view .items-list').find('.snf-checkbox-checked').each(function(){ |
161 |
$(this).parents('li').addClass('selected'); |
162 |
}); |
163 |
$('.list-view .items-list').find('.snf-checkbox-unchecked').each(function(){ |
164 |
$(this).parents('li').removeClass('selected'); |
165 |
}); |
166 |
}; |
167 |
|
168 |
/*
|
169 |
* In order for the editable value functionality to work, the html markup
|
170 |
* should be:
|
171 |
<div class="editable">
|
172 |
<span class="input-txt">editable value</span>
|
173 |
<input type="text">
|
174 |
<a href="#" class="edit">edit</a>
|
175 |
<a href="#" class="save">save</a>
|
176 |
<a href="#" class="cancel">cancel</a>
|
177 |
</div>
|
178 |
*/
|
179 |
ui.editable = function(){ |
180 |
|
181 |
/*
|
182 |
* resetForm hides save and cancel buttons,
|
183 |
* text input and shows input-txt. resetForm does not alter
|
184 |
* input-txt content.
|
185 |
*/
|
186 |
|
187 |
function resetForm(e, elem) { |
188 |
var el = elem.parents('.editable'); |
189 |
el.find('input[type="text"]').hide();
|
190 |
el.find('a.cancel, a.save').hide();
|
191 |
el.find('a.edit, .input-txt').show();
|
192 |
} |
193 |
|
194 |
/*
|
195 |
* showForm hides input-txt, shows save and cancel buttons and
|
196 |
* sets input value to input-txt content.
|
197 |
*/
|
198 |
function showForm(e,elem) { |
199 |
e.stopPropagation(); |
200 |
e.preventDefault(); |
201 |
var el = elem.parents('.editable'); |
202 |
el.find('input[type="text"]').val(el.find('.input-txt').html()); |
203 |
el.find('input[type="text"]').show();
|
204 |
el.find('a.cancel, a.save').show();
|
205 |
elem.hide(); |
206 |
el.find('.input-txt').hide();
|
207 |
} |
208 |
|
209 |
/*
|
210 |
setValue sets input-txt value to the input value.
|
211 |
Makes sure that the input value is not empty.
|
212 |
TODO:
|
213 |
Ajax request to submit form
|
214 |
*/
|
215 |
|
216 |
function setValue(elem) { |
217 |
var el = elem.parents('.editable'); |
218 |
if( el.find('input[type="text"]').val() ) { |
219 |
el.find('.input-txt').html(el.find('input[type="text"]').val()); |
220 |
} |
221 |
} |
222 |
|
223 |
|
224 |
$('.editable .edit').click(function(e){ |
225 |
showForm(e, $(this)); |
226 |
}) |
227 |
|
228 |
$('.editable .cancel').click(function(e){ |
229 |
e.stopPropagation(); |
230 |
e.preventDefault(); |
231 |
resetForm(e, $(this)); |
232 |
}) |
233 |
|
234 |
$('.editable .save').click(function(e){ |
235 |
e.stopPropagation(); |
236 |
e.preventDefault(); |
237 |
setValue($(this)); |
238 |
resetForm(e, $(this)); |
239 |
|
240 |
}) |
241 |
|
242 |
|
243 |
$('.editable input[type="text"]').click(function(e){ |
244 |
e.stopPropagation(); |
245 |
}) |
246 |
|
247 |
$('.editable input[type="text"]').keyup(function(e){ |
248 |
if(e.keyCode == 13) { |
249 |
setValue($(this)); |
250 |
resetForm(e, $(this)); |
251 |
|
252 |
} |
253 |
|
254 |
}) |
255 |
|
256 |
$('html').click(function(e) { |
257 |
resetForm(e, $('.editable a.cancel')); |
258 |
}); |
259 |
|
260 |
} |
261 |
|
262 |
/* TODO: better overlay functionality */
|
263 |
ui.overlay = function() { |
264 |
$('[data-overlay-id]').click(function(e){ |
265 |
e.preventDefault(); |
266 |
var el = $(this); |
267 |
var id = '#'+el.data('overlay-id'); |
268 |
|
269 |
$('.overlay-area-custom').fadeIn(100); |
270 |
$('body').addClass('with-overlay'); |
271 |
$(id).fadeIn('slow'); |
272 |
if (id=='#network-wizard') { |
273 |
$(id).find('input').first().focus(); |
274 |
return false; |
275 |
} |
276 |
$(id).find('a').first().focus(); |
277 |
}); |
278 |
} |
279 |
|
280 |
function goToByScroll(id){ |
281 |
// Remove "link" from the ID
|
282 |
id = id.replace("link", ""); |
283 |
// Scroll
|
284 |
$('html,body').animate({ |
285 |
scrollTop: $("#"+id).offset().top}, |
286 |
'slow');
|
287 |
} |
288 |
|
289 |
|
290 |
/*
|
291 |
* functions concerning checkboxes and radiobuttons links
|
292 |
*/
|
293 |
|
294 |
ui.changeCheckboxState =function(checkbox_link) { |
295 |
$(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked'); |
296 |
ui.entitiesActionsEnabled(); |
297 |
ui.checkedListItems(); |
298 |
} |
299 |
|
300 |
// to use the above functions use first the ui.checkOneRadioButton and then ui.changeRadiobuttonState
|
301 |
ui.checkOneRadioButton = function(radiobtn_link) { |
302 |
$(radiobtn_link).closest('ul').find('span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked'); |
303 |
} |
304 |
ui.changeRadiobuttonState = function(radiobtn_link) { |
305 |
$(radiobtn_link).find('span.snf-radio-unchecked, span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked'); |
306 |
} |
307 |
|
308 |
|
309 |
|
310 |
// toggle expand arrrow and corresponding area
|
311 |
// todo: one function for all the areas we reveal
|
312 |
ui.expandDownArea = function(arrow_link, area) { |
313 |
var arrow_link = $(arrow_link); |
314 |
var area = $(area); |
315 |
arrow_link.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down'); |
316 |
// $('.wizard-content').removeAttr('style');
|
317 |
area.stop().slideToggle(600, function() { |
318 |
if (area.is(':visible')) { |
319 |
arrow_link.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up'); |
320 |
} else {
|
321 |
arrow_link.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down'); |
322 |
} |
323 |
|
324 |
}); |
325 |
} |
326 |
|
327 |
|
328 |
/* Tabs functionality
|
329 |
* tabsEl is the div/ul with the links to the sections and the sections that
|
330 |
* with toggle have class sectionEl.
|
331 |
* Markup needed is an href to each a with the id of the relative section.
|
332 |
*/
|
333 |
|
334 |
ui.tabsSection = function(link, sectionEl) { |
335 |
sectionEl.hide(); |
336 |
var el = $(link.attr('href')); |
337 |
el.stop(true, true).show(0); |
338 |
el.css('opacity',0); |
339 |
ui.detailsCustom(el); |
340 |
el.animate({ |
341 |
'opacity':1, |
342 |
}, 500)
|
343 |
} |
344 |
|
345 |
ui.tabs = function(tabsEl, sectionEl) { |
346 |
var tabLink = tabsEl.find('a'); |
347 |
ui.replaceClass(tabLink.find('.active'), 'outline', 'full', 'snf-'); |
348 |
function href(a) { |
349 |
return a.attr('href'); |
350 |
} |
351 |
tabLink.click(function(e){
|
352 |
e.preventDefault(); |
353 |
if ( $(this).hasClass('active')){ |
354 |
return false; |
355 |
} else {
|
356 |
window.location.hash = $(this).attr('href'); |
357 |
ui.replaceClass($(this).parents(tabsEl).find('.active'), 'full', 'outline', 'snf-'); |
358 |
$(this).parents(tabsEl).find('a').removeClass('active'); |
359 |
$(this).addClass('active'); |
360 |
ui.replaceClass($(this), 'outline', 'full', 'snf-'); |
361 |
ui.tabsSection( $(this), sectionEl); |
362 |
} |
363 |
}) |
364 |
} |
365 |
|
366 |
// the function replaces part of the class of a span that is placed inside an a element
|
367 |
// the class is a word with the form : firstSubStr+*+str1 and it will be converted to: firstSubStr+*+str2
|
368 |
// it must be uniquely recognized by the firstSubStr and the str1.
|
369 |
|
370 |
ui.replaceClass = function(elements, str1, str2, firstSubStr) { |
371 |
$.each($(elements), function() { |
372 |
var classOld = $(this).find('span').attr('class'); |
373 |
var classNew;
|
374 |
if(classOld != undefined && classOld.indexOf(str1) != -1) { |
375 |
if(classOld.indexOf(' ') == -1) { |
376 |
classNew = classOld.replace(str1, str2); |
377 |
$(this).find('.'+classOld).removeClass(classOld).addClass(classNew); |
378 |
} |
379 |
else {
|
380 |
// the string starts with the firstSubStr and after the end of the word there's a space
|
381 |
var expr1 = new RegExp('^'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g'); |
382 |
|
383 |
// the word is between spaces
|
384 |
var expr2 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g'); |
385 |
|
386 |
// before the word there's at least one space and the string ends with this word
|
387 |
var expr3 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'$', 'g'); |
388 |
|
389 |
// spaces all over the string
|
390 |
var spacesExp = new RegExp('\\s+', 'g'); |
391 |
|
392 |
if(classOld.match(expr1) != null) { |
393 |
classToReplace = classOld.match(expr1); |
394 |
} |
395 |
else if(classOld.match(expr2) != null) { |
396 |
classToReplace = classOld.match(expr2); |
397 |
} |
398 |
else if (classOld.match(expr3) != null) { |
399 |
classToReplace = classOld.match(expr3); |
400 |
} |
401 |
classToReplace = classToReplace.toString().replace(spacesExp,"");
|
402 |
classNew = classToReplace.replace(str1, str2); |
403 |
$(this).find('.'+classToReplace).removeClass(classToReplace).addClass(classNew); |
404 |
} |
405 |
} |
406 |
}); |
407 |
} |
408 |
|
409 |
// in a page with tabs, allow navigation with hash tags
|
410 |
ui.hashTabs = function(tabsEl, sectionEl){ |
411 |
var hash = window.location.hash;
|
412 |
if ($(hash).length<=0){ |
413 |
return;
|
414 |
} |
415 |
tabsEl.find('a').removeClass('active'); |
416 |
var link = tabsEl.find('a[href="'+hash+'"]'); |
417 |
link.addClass('active');
|
418 |
ui.tabsSection(link, sectionEl); |
419 |
|
420 |
} |
421 |
|
422 |
ui.ltBarToggle = function(speed){ |
423 |
|
424 |
var cmarg = parseInt($('.lt-bar').width()) - parseInt($('.toggle-lt-bar').outerWidth(true)); |
425 |
var ctemp = cmarg / parseInt($('.lt-bar').width()); |
426 |
var cvelocity = parseInt($('.lt-bar').width())/speed; |
427 |
var cdelay = parseInt($('.toggle-lt-bar').outerWidth(true))/cvelocity; |
428 |
|
429 |
$('.lt-bar').click(function(e) { |
430 |
e.stopPropagation(); |
431 |
}) |
432 |
$('.toggle-lt-bar').click(function(e){ |
433 |
e.preventDefault(); |
434 |
e.stopPropagation(); |
435 |
var self =this; |
436 |
if($(this).hasClass('fix-position')) { |
437 |
var marg = parseInt($(self).css('marginLeft')) - cmarg; |
438 |
$(this).animate({ |
439 |
'margin-left': marg,
|
440 |
}, ctemp * speed, 'linear', function(){ |
441 |
$(self).removeAttr('style'); |
442 |
$(self).removeClass('fix-position'); |
443 |
}); |
444 |
$('.lt-bar').animate({ |
445 |
width: 'toggle' |
446 |
}, speed, 'linear');
|
447 |
} |
448 |
else {
|
449 |
$(this).addClass('fix-position'); |
450 |
var scrollBarWidth = 14; |
451 |
var marg = parseInt($(self).css('marginLeft')) + cmarg - scrollBarWidth; |
452 |
tt = marg; |
453 |
setTimeout(function(){
|
454 |
$(self).animate({
|
455 |
'margin-left': marg,
|
456 |
}, speed, 'linear')
|
457 |
}, cdelay); |
458 |
$('.lt-bar').animate({ |
459 |
width: 'toggle' |
460 |
}, speed, 'linear', ui.setCustomScrollBar);
|
461 |
} |
462 |
}); |
463 |
} |
464 |
|
465 |
|
466 |
ui.setCustomScrollBar = function() { |
467 |
$('.scroll-pane-arrows').jScrollPane({ |
468 |
showArrows: true, |
469 |
horizontalGutter: 10, |
470 |
verticalDragMinHeight: 300, |
471 |
verticalDragMaxHeight: 300, |
472 |
mouseWheelSpeed: 50 |
473 |
}); |
474 |
} |
475 |
|
476 |
function bytesToSize(bytes) { |
477 |
var sizes = [ 'n/a', 'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
478 |
var i = +Math.floor(Math.log(bytes) / Math.log(1024)); |
479 |
return (bytes / Math.pow(1024, i)).toFixed( 0 ) + sizes[ isNaN( bytes ) ? 0 : i+1 ]; |
480 |
} |
481 |
function date_ddmmmyytime(date) |
482 |
{ |
483 |
var d = date.getDate();
|
484 |
var m = date.getMonth();
|
485 |
var y = date.getYear();
|
486 |
if(y >= 100) |
487 |
{ |
488 |
y -= 100;
|
489 |
y += 2000;
|
490 |
} |
491 |
|
492 |
var curr_hour = date.getHours();
|
493 |
|
494 |
if (curr_hour < 12){ |
495 |
a_p = "am";
|
496 |
} else {
|
497 |
a_p = "pm";
|
498 |
} |
499 |
|
500 |
if (curr_hour == 0) { |
501 |
curr_hour = 12;
|
502 |
} |
503 |
if (curr_hour > 12){ |
504 |
curr_hour = curr_hour - 12;
|
505 |
} |
506 |
|
507 |
var curr_min = date.getMinutes();
|
508 |
|
509 |
return "" + |
510 |
(d<10?"0"+d:d) + "/" +m + "/" + y + ' '+curr_hour + ":" + curr_min + a_p; |
511 |
} |
512 |
|
513 |
|
514 |
$(document).ready(function(){ |
515 |
|
516 |
$('html').click(function(e) { |
517 |
// not sure if we want to hide the error window after every click in the ui
|
518 |
if($('.communication-error').css('bottom') == '0px') { |
519 |
$('.communication-error').animate({bottom: "-151px"}); |
520 |
} |
521 |
if($('.details .lt-bar').is(':visible')) { |
522 |
$('.toggle-lt-bar').trigger('click'); |
523 |
} |
524 |
}); |
525 |
|
526 |
if($('.vms.entities').length!=0){ |
527 |
ui.inactiveActions(); |
528 |
}; |
529 |
ui.setElminHeight($('.main > .details')); |
530 |
ui.setElminHeight($('.lt-bar')); |
531 |
ui.setElmaxHeight($('.storage-progress')); |
532 |
ui.setElHeight($('.scroll-wrap')); |
533 |
$('#hd-search .hd-icon-search').click(function(e){ |
534 |
var that = this; |
535 |
$(this).parents('.hd-search').toggleClass('hd-open'); |
536 |
if ($(this).parents('.hd-search').hasClass('hd-open')) { |
537 |
$(that).parents('.hd-search').find('input[type="search"]').focus(); |
538 |
} else {
|
539 |
$(that).parents('.hd-search').find('input[type="search"]').val(''); |
540 |
} |
541 |
}) |
542 |
|
543 |
$('.header .login').mouseenter(function(e){ |
544 |
$(this).find('ul').stop(true, true).slideDown(200); |
545 |
}); |
546 |
$('.header .login').mouseleave(function(e){ |
547 |
$(this).find('ul').stop(true, true).slideUp(200); |
548 |
}); |
549 |
|
550 |
$('.entities a').click(function(){ |
551 |
if ($(this).attr('data-reveal-id') && !($(this).hasClass('inactive'))) { |
552 |
$('.entities li .more').hide(); |
553 |
} |
554 |
}); |
555 |
|
556 |
$('.inactive').click(function(e){ |
557 |
e.stopPropagation(); |
558 |
e.preventDefault(); |
559 |
}) |
560 |
|
561 |
|
562 |
$('.lt-actions a:not(.active)').click(function(e){ |
563 |
e.preventDefault(); |
564 |
}) |
565 |
|
566 |
if ($('.entities .items-list >li').length == 1) { |
567 |
$('.body-wrapper').addClass('no-vm'); |
568 |
}; |
569 |
$('.entities li .more').each(function(){ |
570 |
var width = $(this).parent('li').outerWidth() + 20; |
571 |
$(this).css('width', width); |
572 |
}); |
573 |
|
574 |
$('.items-list li .img-wrap').on("mouseenter", function(e) { |
575 |
var that = this; |
576 |
if ($(this).parents('.entities').hasClass('grid-view')) { |
577 |
if ($(that).parent('.container').siblings('.more').length>0) { |
578 |
$(that).parent('.container').fadeOut(50,'easeInCirc'); |
579 |
$(that).parent('.container').siblings('.more').fadeIn(150,'easeInCirc'); |
580 |
} |
581 |
} |
582 |
}); |
583 |
$('.entities li .more').mouseleave(function(e) { |
584 |
$(this).fadeOut(50, function() { |
585 |
$(this).siblings('.container').fadeIn(50); |
586 |
}); |
587 |
}); |
588 |
$('.grid-view .items-list > li').mouseleave(function(e){ |
589 |
var that = this; |
590 |
setTimeout(function(){
|
591 |
$(that).find('.more').fadeOut(200, function() { |
592 |
$(this).siblings('.container').fadeIn('fast'); |
593 |
}); |
594 |
},50)
|
595 |
}); |
596 |
|
597 |
ui.closeDiv($('.info .close'), '.info'); |
598 |
ui.editable(); |
599 |
ui.overlay(); |
600 |
ui.colorPickerVisible = 0;
|
601 |
|
602 |
$("a.disabled").each(function() { |
603 |
$(this).removeAttr('href'); |
604 |
}); |
605 |
|
606 |
$("a.disabled").click(function(e) { |
607 |
e.preventDefault(); |
608 |
}); |
609 |
|
610 |
// checkbox: basic reaction on click (checked, unchecked)
|
611 |
// see wizard
|
612 |
$('.check').on('click', function(e){ |
613 |
e.preventDefault(); |
614 |
e.stopPropagation(); |
615 |
ui.changeCheckboxState(this);
|
616 |
}); |
617 |
|
618 |
// for checkboxes created after document.ready
|
619 |
$('.items-list').on('click','.check', function(e){ |
620 |
e.preventDefault(); |
621 |
e.stopPropagation(); |
622 |
ui.changeCheckboxState(this);
|
623 |
}) |
624 |
|
625 |
|
626 |
$('.with-checkbox').click(function(e){ |
627 |
e.preventDefault(); |
628 |
e.stopPropagation(); |
629 |
var checkbox = self.find('.check'); |
630 |
ui.changeCheckboxState(checkbox); |
631 |
}); |
632 |
|
633 |
$('.radio_btn').click(function(e) { |
634 |
e.preventDefault(); |
635 |
var state = $(this).find('span'); |
636 |
if(state.hasClass('snf-radio-unchecked')) { |
637 |
ui.checkOneRadioButton(this);
|
638 |
ui.changeRadiobuttonState(this);
|
639 |
} |
640 |
}); |
641 |
|
642 |
$('.main-actions li a').click(function(e){ |
643 |
if (!($(this).hasClass('active'))) { |
644 |
e.preventDefault(); |
645 |
} |
646 |
}); |
647 |
|
648 |
$('.main-actions li a').click(function(e){ |
649 |
if (!($(this).hasClass('active'))) { |
650 |
e.preventDefault(); |
651 |
} |
652 |
}); |
653 |
$('.overlay-area-custom').children('.close').click(function(e){ |
654 |
e.preventDefault(); |
655 |
e.stopPropagation(); |
656 |
$(this).parents('.overlay-area-custom').hide(); |
657 |
$(this).parents('.overlay-area-custom').find($('.overlay-div')).hide(); |
658 |
$('body').removeClass('with-overlay'); |
659 |
}) |
660 |
|
661 |
$('.browse-files').click(function(e){ |
662 |
e.preventDefault(); |
663 |
}) |
664 |
|
665 |
Dropzone.options.filesDropzone = { |
666 |
dictDefaultMessage:'', |
667 |
clickable: '.browse-files', |
668 |
previewsContainer: '.dropzone-files', |
669 |
createImageThumbnails: false, |
670 |
dictRemoveFile: "snf-Remove file", |
671 |
}; |
672 |
|
673 |
|
674 |
$('.main .files').magnificPopup({ |
675 |
delegate: 'a.show.image', |
676 |
type: 'image', |
677 |
tLoading: 'Loading image #%curr%...', |
678 |
mainClass: 'mfp-img-mobile', |
679 |
gallery: {
|
680 |
enabled: true, |
681 |
navigateByImgClick: true, |
682 |
preload: [0,1] // Will preload 0 - before current, and 1 after the current image |
683 |
}, |
684 |
image: {
|
685 |
tError: 'The image could not be loaded.', |
686 |
titleSrc: function(item) { |
687 |
return item.el.data('title'); |
688 |
} |
689 |
} |
690 |
}); |
691 |
|
692 |
if($('#picker').length>0) { |
693 |
$('#picker').farbtastic('#color'); |
694 |
}; |
695 |
if($('#sb-search').length>0) { |
696 |
new UISearch( document.getElementById( 'sb-search' ) ); |
697 |
} |
698 |
|
699 |
if ($('.toggle-lt-bar').length>0) { |
700 |
ui.ltBarToggle(400);
|
701 |
} |
702 |
|
703 |
/* grid/list view for items-list */
|
704 |
|
705 |
$('.actions-bar .list, .actions-bar .grid').click(function(e){ |
706 |
e.preventDefault(); |
707 |
if (!($(this).find('span').hasClass('current'))) { |
708 |
$('.actions-bar .grid span, .actions-bar .list span').removeClass('current'); |
709 |
$(this).find('span').addClass('current'); |
710 |
$('.entities').toggleClass('grid-view list-view'); |
711 |
} |
712 |
}); |
713 |
|
714 |
$('.lt-bar .select').click(function(e){ |
715 |
$(this).find('span').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
716 |
$(this).find('em').toggle(); |
717 |
if ( $(this).find('span').hasClass('snf-checkbox-unchecked')){ |
718 |
$('.list-view li .check span').removeClass('snf-checkbox-checked'); |
719 |
$('.list-view li .check span').addClass('snf-checkbox-unchecked'); |
720 |
} else {
|
721 |
$('.list-view li .check span').addClass('snf-checkbox-checked'); |
722 |
$('.list-view li .check span').removeClass('snf-checkbox-unchecked'); |
723 |
} |
724 |
ui.entitiesActionsEnabled(); |
725 |
ui.checkedListItems(); |
726 |
}); |
727 |
|
728 |
// set filter visible
|
729 |
$('.filter-menu .filter').click(function(e) { |
730 |
e.preventDefault(); |
731 |
$(this).parents('.filter-menu').toggleClass('current'); |
732 |
}); |
733 |
|
734 |
// temp function used to demonstrate the visual effect of the building state of vm
|
735 |
$('[data-status="building"] .btn5.temp').click(function(e) { |
736 |
e.preventDefault(); |
737 |
$(this).siblings('.container').find('.complete').toggleClass('build-progress'); |
738 |
}); |
739 |
|
740 |
$('[data-status="rebooting"] .btn5.temp').click(function(e) { |
741 |
e.preventDefault(); |
742 |
$(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress'); |
743 |
}) |
744 |
|
745 |
// //temp function to preventDefault of links in modal
|
746 |
// $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
|
747 |
// e.preventDefault();
|
748 |
// $('a.close-reveal-modal').trigger('click');
|
749 |
// });
|
750 |
|
751 |
// temp btn to show communication error message
|
752 |
$('.temp-for-btns .communication-error-btn').click(function(e) { |
753 |
e.preventDefault(); |
754 |
e.stopPropagation(); |
755 |
$('.communication-error').animate({bottom: "0px"}); |
756 |
}); |
757 |
|
758 |
$('.communication-error a').click(function(e) { |
759 |
e.preventDefault(); |
760 |
e.stopPropagation(); |
761 |
$('.communication-error').animate({bottom: "-151px"}); |
762 |
|
763 |
}); |
764 |
$('.communication-error').click(function(e) { |
765 |
e.stopPropagation(); |
766 |
}); |
767 |
|
768 |
$('.show-add-tag').click(function(e) { |
769 |
e.preventDefault(); |
770 |
$(this).parents('.tags-area, .tags').find('.snf-color-picker').slideDown('slow', function() { |
771 |
$('#hide-add-tag-dummy').scrollintoview({ |
772 |
'duration': 'slow' |
773 |
}); |
774 |
}); |
775 |
ui.colorPickerVisible = 1;
|
776 |
}); |
777 |
|
778 |
$('.hide-add-tag').click(function(e) { |
779 |
e.preventDefault(); |
780 |
$(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() { |
781 |
$('.show-add-tag').first().scrollintoview({ |
782 |
'duration': 'slow' |
783 |
}); |
784 |
ui.colorPickerVisible = 0;
|
785 |
}); |
786 |
}); |
787 |
|
788 |
// connected details js
|
789 |
ui.detailsCustom($('#disk-connected')); |
790 |
ui.detailsCustom($('#network-connected')); |
791 |
ui.detailsCustom($('#vm-connected')); |
792 |
ui.firewallSetup(); |
793 |
$('.firewall .more a').click(function(e){ |
794 |
e.preventDefault(); |
795 |
if ($(this).find('span').hasClass('snf-radio-checked')) { |
796 |
return false; |
797 |
} |
798 |
$(this).parents('.firewall').removeAttr('data-firewall'); |
799 |
$(this).parents('.firewall').data('firewall', $(this).parent().attr('class')); |
800 |
$(this).find('span').toggleClass('snf-radio-unchecked snf-radio-checked'); |
801 |
$(this).parent('p').siblings('p').find('span').removeClass('snf-radio-checked'); |
802 |
$(this).parent('p').siblings('p').find('span').addClass('snf-radio-unchecked'); |
803 |
ui.firewallSetup(); |
804 |
}); |
805 |
$('.firewall').mouseenter(function(e){ |
806 |
$(this).css('z-index',2); |
807 |
$(this).find('.more').stop(true, true).slideDown(200); |
808 |
}); |
809 |
$('.firewall').mouseleave(function(e){ |
810 |
$(this).css('z-index',1); |
811 |
$(this).find('.more').stop(true, true).slideUp(200); |
812 |
}); |
813 |
ui.tabs($('.tabs'), $('.content')); |
814 |
ui.hashTabs($('.tabs'), $('.content')); |
815 |
|
816 |
$('.act').click(function(e) { |
817 |
$(this).addClass('pending last'); |
818 |
}); |
819 |
|
820 |
$('.remove .cancel').click(function(e) { |
821 |
e.preventDefault(); |
822 |
$('a.close-reveal-modal').trigger('click'); |
823 |
$('.last').removeClass('pending last'); |
824 |
}); |
825 |
|
826 |
$('.remove .ok').click(function(e) { |
827 |
e.preventDefault(); |
828 |
$('a.close-reveal-modal').trigger('click'); |
829 |
var connection_img = $('.connections').find('.last'); |
830 |
connection_img.addClass('open', 0); |
831 |
connection_img.removeClass('last');
|
832 |
var img = connection_img.closest('.item').find('.img-wrap .snf-font'); |
833 |
img.addClass('reboot-progress');
|
834 |
setTimeout(function() {
|
835 |
var connections_list = connection_img.closest('.connections').children('li:not(".hidden")'); |
836 |
if(connections_list.length>1) { |
837 |
connection_img.closest('li').slideUp(function(){ |
838 |
connection_img.closest('li').addClass('hidden'); |
839 |
if(connections_list.find('.pending').length == 0) { |
840 |
img.removeClass('reboot-progress');
|
841 |
} |
842 |
}); |
843 |
} |
844 |
else {
|
845 |
connection_img.closest('.item').slideUp(function(){ |
846 |
img.closest('li').addClass('hidden'); |
847 |
img.removeClass('reboot-progress');
|
848 |
img.removeClass('reboot-progress');
|
849 |
}); |
850 |
} |
851 |
connection_img.removeClass('pending');
|
852 |
}, 3000)
|
853 |
}); |
854 |
// end of connected details js
|
855 |
|
856 |
ui.replaceClass($('a.current, a.active'), 'outline', 'full', 'snf-'); |
857 |
|
858 |
// with the function below the sidebar in detailed views
|
859 |
// will not hide if we click something in a wizard
|
860 |
$('.wizard').click(function(e) { |
861 |
e.stopPropagation(); |
862 |
}) |
863 |
|
864 |
$('.tag-data').mouseover(function() { |
865 |
$(this).find('.delete').css({visibility: 'visible'}) |
866 |
}); |
867 |
$('.tag-data').mouseleave(function(){ |
868 |
$(this).find('.delete').css({visibility: 'hidden'}) |
869 |
}); |
870 |
$('.delete').click(function(e) { |
871 |
e.preventDefault(); |
872 |
$(this).closest('div').fadeOut('slow'); |
873 |
}); |
874 |
|
875 |
$('.storage-progress').hover( |
876 |
function(e){
|
877 |
$(this).find('.details').stop(false,true).slideDown(); |
878 |
}, |
879 |
function(e){
|
880 |
$(this).find('.details').stop(false,true).slideUp(); |
881 |
} |
882 |
); |
883 |
|
884 |
$('.btn-more').mouseenter(function(e) { |
885 |
$(this).find('.explain').stop(true, true).show('slow'); |
886 |
$(this).addClass('style-1'); |
887 |
$(this).find('.snf-arrow-down').removeClass('style-1'); |
888 |
// $(this).siblings('.available').stop(true, true).slideDown(200);
|
889 |
}); |
890 |
|
891 |
$('.btn-more').click(function(e) { |
892 |
e.preventDefault(); |
893 |
$(this).addClass('style-2'); |
894 |
$(this).closest('.project').css('z-index', 2); |
895 |
$(this).siblings('.available').stop(true, true).slideDown('slow'); |
896 |
}) |
897 |
|
898 |
$('.project').mouseleave(function(e) { |
899 |
$(this).find('.available').stop(true, true).slideUp(200); |
900 |
var btn = $(this).find('.btn-more'); |
901 |
btn.find('.explain').stop(true, true).hide('slow'); |
902 |
$(btn).find('.snf-arrow-down').addClass('style-1'); |
903 |
btn.removeClass('style-2');
|
904 |
$(btn).removeClass('style-1'); |
905 |
$(this).closest('.project').css('z-index',1); |
906 |
}) |
907 |
}) |
908 |
|
909 |
|
910 |
$(window).resize(function(e){ |
911 |
ui.setElminHeight($('.main > .details')); |
912 |
ui.setElminHeight($('.lt-bar')); |
913 |
ui.setElHeight($('.scroll-wrap')); |
914 |
ui.setCustomScrollBar(); |
915 |
ui.setElmaxHeight($('.storage-progress')); |
916 |
|
917 |
}) |