root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / common.js @ 4cb1fbf9
History | View | Annotate | Download (29.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 |
console.log(checkbox_link); |
296 |
$(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked'); |
297 |
ui.entitiesActionsEnabled(); |
298 |
ui.checkedListItems(); |
299 |
} |
300 |
|
301 |
// to use the above functions use first the ui.checkOneRadioButton and then ui.changeRadiobuttonState
|
302 |
ui.checkOneRadioButton = function(radiobtn_link) { |
303 |
$(radiobtn_link).closest('ul').find('span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked'); |
304 |
} |
305 |
ui.changeRadiobuttonState = function(radiobtn_link) { |
306 |
$(radiobtn_link).find('span.snf-radio-unchecked, span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked'); |
307 |
} |
308 |
|
309 |
|
310 |
|
311 |
// toggle expand arrrow and corresponding area
|
312 |
// todo: one function for all the areas we reveal
|
313 |
ui.expandDownArea = function(arrow_link, area) { |
314 |
var arrow_link = $(arrow_link); |
315 |
var area = $(area); |
316 |
arrow_link.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down'); |
317 |
// $('.wizard-content').removeAttr('style');
|
318 |
area.stop().slideToggle(600, function() { |
319 |
if (area.is(':visible')) { |
320 |
arrow_link.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up'); |
321 |
} else {
|
322 |
arrow_link.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down'); |
323 |
} |
324 |
|
325 |
}); |
326 |
} |
327 |
|
328 |
|
329 |
/* Tabs functionality
|
330 |
* tabsEl is the div/ul with the links to the sections and the sections that
|
331 |
* with toggle have class sectionEl.
|
332 |
* Markup needed is an href to each a with the id of the relative section.
|
333 |
*/
|
334 |
|
335 |
ui.tabsSection = function(link, sectionEl) { |
336 |
sectionEl.hide(); |
337 |
var el = $(link.attr('href')); |
338 |
el.stop(true, true).show(0); |
339 |
el.css('opacity',0); |
340 |
ui.detailsCustom(el); |
341 |
el.animate({ |
342 |
'opacity':1, |
343 |
}, 500)
|
344 |
} |
345 |
|
346 |
ui.tabs = function(tabsEl, sectionEl) { |
347 |
var tabLink = tabsEl.find('a'); |
348 |
ui.replaceClass(tabLink.find('.active'), 'outline', 'full', 'snf-'); |
349 |
function href(a) { |
350 |
return a.attr('href'); |
351 |
} |
352 |
tabLink.click(function(e){
|
353 |
e.preventDefault(); |
354 |
if ( $(this).hasClass('active')){ |
355 |
return false; |
356 |
} else {
|
357 |
window.location.hash = $(this).attr('href'); |
358 |
ui.replaceClass($(this).parents(tabsEl).find('.active'), 'full', 'outline', 'snf-'); |
359 |
$(this).parents(tabsEl).find('a').removeClass('active'); |
360 |
$(this).addClass('active'); |
361 |
ui.replaceClass($(this), 'outline', 'full', 'snf-'); |
362 |
ui.tabsSection( $(this), sectionEl); |
363 |
} |
364 |
}) |
365 |
} |
366 |
|
367 |
// the function replaces part of the class of a span that is placed inside an a element
|
368 |
// the class is a word with the form : firstSubStr+*+str1 and it will be converted to: firstSubStr+*+str2
|
369 |
// it must be uniquely recognized by the firstSubStr and the str1.
|
370 |
|
371 |
ui.replaceClass = function(elements, str1, str2, firstSubStr) { |
372 |
$.each($(elements), function() { |
373 |
var classOld = $(this).find('span').attr('class'); |
374 |
var classNew;
|
375 |
if(classOld != undefined && classOld.indexOf(str1) != -1) { |
376 |
if(classOld.indexOf(' ') == -1) { |
377 |
classNew = classOld.replace(str1, str2); |
378 |
$(this).find('.'+classOld).removeClass(classOld).addClass(classNew); |
379 |
} |
380 |
else {
|
381 |
// the string starts with the firstSubStr and after the end of the word there's a space
|
382 |
var expr1 = new RegExp('^'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g'); |
383 |
|
384 |
// the word is between spaces
|
385 |
var expr2 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g'); |
386 |
|
387 |
// before the word there's at least one space and the string ends with this word
|
388 |
var expr3 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'$', 'g'); |
389 |
|
390 |
// spaces all over the string
|
391 |
var spacesExp = new RegExp('\\s+', 'g'); |
392 |
|
393 |
if(classOld.match(expr1) != null) { |
394 |
classToReplace = classOld.match(expr1); |
395 |
} |
396 |
else if(classOld.match(expr2) != null) { |
397 |
classToReplace = classOld.match(expr2); |
398 |
} |
399 |
else if (classOld.match(expr3) != null) { |
400 |
classToReplace = classOld.match(expr3); |
401 |
} |
402 |
classToReplace = classToReplace.toString().replace(spacesExp,"");
|
403 |
classNew = classToReplace.replace(str1, str2); |
404 |
$(this).find('.'+classToReplace).removeClass(classToReplace).addClass(classNew); |
405 |
} |
406 |
} |
407 |
}); |
408 |
} |
409 |
|
410 |
// in a page with tabs, allow navigation with hash tags
|
411 |
ui.hashTabs = function(tabsEl, sectionEl){ |
412 |
var hash = window.location.hash;
|
413 |
if ($(hash).length<=0){ |
414 |
return;
|
415 |
} |
416 |
tabsEl.find('a').removeClass('active'); |
417 |
var link = tabsEl.find('a[href="'+hash+'"]'); |
418 |
link.addClass('active');
|
419 |
ui.tabsSection(link, sectionEl); |
420 |
|
421 |
} |
422 |
|
423 |
// in a page with tabs, allow navigation with hash tags
|
424 |
ui.hashViews = function(viewsEl, sectionEl){ |
425 |
var hash = window.location.hash;
|
426 |
if (!(hash)){
|
427 |
return;
|
428 |
} |
429 |
var link = viewsEl.find('a[href="'+hash+'"]'); |
430 |
console.log('link', link);
|
431 |
if (link.length<=0){ |
432 |
return;
|
433 |
} |
434 |
viewsEl.find('a span').removeClass('current'); |
435 |
link.find('span').addClass('current'); |
436 |
sectionEl.removeClass('grid-view list-view');
|
437 |
var sectionClass = hash.slice(1) + '-view'; |
438 |
sectionEl.addClass(sectionClass); |
439 |
} |
440 |
|
441 |
ui.ltBarToggle = function(speed){ |
442 |
|
443 |
var cmarg = parseInt($('.lt-bar').width()) - parseInt($('.toggle-lt-bar').outerWidth(true)); |
444 |
var ctemp = cmarg / parseInt($('.lt-bar').width()); |
445 |
var cvelocity = parseInt($('.lt-bar').width())/speed; |
446 |
var cdelay = parseInt($('.toggle-lt-bar').outerWidth(true))/cvelocity; |
447 |
|
448 |
$('.lt-bar').click(function(e) { |
449 |
e.stopPropagation(); |
450 |
}) |
451 |
$('.toggle-lt-bar').click(function(e){ |
452 |
e.preventDefault(); |
453 |
e.stopPropagation(); |
454 |
var self =this; |
455 |
if($(this).hasClass('fix-position')) { |
456 |
var marg = parseInt($(self).css('marginLeft')) - cmarg; |
457 |
$(this).animate({ |
458 |
'margin-left': marg,
|
459 |
}, ctemp * speed, 'linear', function(){ |
460 |
$(self).removeAttr('style'); |
461 |
$(self).removeClass('fix-position'); |
462 |
}); |
463 |
$('.lt-bar').animate({ |
464 |
width: 'toggle' |
465 |
}, speed, 'linear');
|
466 |
} |
467 |
else {
|
468 |
$(this).addClass('fix-position'); |
469 |
var scrollBarWidth = 14; |
470 |
var marg = parseInt($(self).css('marginLeft')) + cmarg - scrollBarWidth; |
471 |
tt = marg; |
472 |
setTimeout(function(){
|
473 |
$(self).animate({
|
474 |
'margin-left': marg,
|
475 |
}, speed, 'linear')
|
476 |
}, cdelay); |
477 |
$('.lt-bar').animate({ |
478 |
width: 'toggle' |
479 |
}, speed, 'linear', ui.setCustomScrollBar);
|
480 |
} |
481 |
}); |
482 |
} |
483 |
|
484 |
|
485 |
ui.setCustomScrollBar = function() { |
486 |
$('.scroll-pane-arrows').jScrollPane({ |
487 |
showArrows: true, |
488 |
horizontalGutter: 10, |
489 |
verticalDragMinHeight: 300, |
490 |
verticalDragMaxHeight: 300, |
491 |
mouseWheelSpeed: 50 |
492 |
}); |
493 |
} |
494 |
|
495 |
function bytesToSize(bytes) { |
496 |
var sizes = [ 'n/a', 'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
497 |
var i = +Math.floor(Math.log(bytes) / Math.log(1024)); |
498 |
return (bytes / Math.pow(1024, i)).toFixed( 0 ) + sizes[ isNaN( bytes ) ? 0 : i+1 ]; |
499 |
} |
500 |
function date_ddmmmyytime(date) |
501 |
{ |
502 |
var d = date.getDate();
|
503 |
var m = date.getMonth();
|
504 |
var y = date.getYear();
|
505 |
if(y >= 100) |
506 |
{ |
507 |
y -= 100;
|
508 |
y += 2000;
|
509 |
} |
510 |
|
511 |
var curr_hour = date.getHours();
|
512 |
|
513 |
if (curr_hour < 12){ |
514 |
a_p = "am";
|
515 |
} else {
|
516 |
a_p = "pm";
|
517 |
} |
518 |
|
519 |
if (curr_hour == 0) { |
520 |
curr_hour = 12;
|
521 |
} |
522 |
if (curr_hour > 12){ |
523 |
curr_hour = curr_hour - 12;
|
524 |
} |
525 |
|
526 |
var curr_min = date.getMinutes();
|
527 |
|
528 |
return "" + |
529 |
(d<10?"0"+d:d) + "/" +m + "/" + y + ' '+curr_hour + ":" + curr_min + a_p; |
530 |
} |
531 |
|
532 |
// returns the file class/extension of a file
|
533 |
ui.mimeToExt = function( mimetype) { |
534 |
var mimeExt = {
|
535 |
'image/jpeg': 'jpg', |
536 |
'image/png': 'png', |
537 |
'application/pdf': 'pdf', |
538 |
'text/plain': 'txt', |
539 |
}; |
540 |
console.log(mimetype); |
541 |
return mimeExt[mimetype] || 'unknown'; |
542 |
} |
543 |
|
544 |
$(document).ready(function(){ |
545 |
|
546 |
$('html').click(function(e) { |
547 |
// not sure if we want to hide the error window after every click in the ui
|
548 |
if($('.communication-error').css('bottom') == '0px') { |
549 |
$('.communication-error').animate({bottom: "-151px"}); |
550 |
} |
551 |
if($('.details .lt-bar').is(':visible')) { |
552 |
$('.toggle-lt-bar').trigger('click'); |
553 |
} |
554 |
}); |
555 |
|
556 |
if($('.vms.entities').length!=0){ |
557 |
ui.inactiveActions(); |
558 |
}; |
559 |
ui.setElminHeight($('.main > .details')); |
560 |
ui.setElminHeight($('.lt-bar')); |
561 |
ui.setElmaxHeight($('.storage-progress')); |
562 |
ui.setElHeight($('.scroll-wrap')); |
563 |
$('#hd-search .hd-icon-search').click(function(e){ |
564 |
var that = this; |
565 |
$(this).parents('.hd-search').toggleClass('hd-open'); |
566 |
if ($(this).parents('.hd-search').hasClass('hd-open')) { |
567 |
$(that).parents('.hd-search').find('input[type="search"]').focus(); |
568 |
} else {
|
569 |
$(that).parents('.hd-search').find('input[type="search"]').val(''); |
570 |
} |
571 |
}) |
572 |
|
573 |
$('.header .login').mouseenter(function(e){ |
574 |
$(this).find('ul').stop(true, true).slideDown(200); |
575 |
}); |
576 |
$('.header .login').mouseleave(function(e){ |
577 |
$(this).find('ul').stop(true, true).slideUp(200); |
578 |
}); |
579 |
|
580 |
$('.entities a').click(function(){ |
581 |
if ($(this).attr('data-reveal-id') && !($(this).hasClass('inactive'))) { |
582 |
$('.entities li .more').hide(); |
583 |
} |
584 |
}); |
585 |
|
586 |
$('.inactive').click(function(e){ |
587 |
e.stopPropagation(); |
588 |
e.preventDefault(); |
589 |
}) |
590 |
|
591 |
|
592 |
$('.lt-actions a:not(.active)').click(function(e){ |
593 |
e.preventDefault(); |
594 |
}) |
595 |
|
596 |
if ($('.entities .items-list >li').length == 1) { |
597 |
$('.body-wrapper').addClass('no-vm'); |
598 |
}; |
599 |
$('.entities li .more').each(function(){ |
600 |
var width = $(this).parent('li').outerWidth() + 20; |
601 |
$(this).css('width', width); |
602 |
}); |
603 |
|
604 |
$('.items-list li .img-wrap').on("mouseenter", function(e) { |
605 |
var that = this; |
606 |
if ($(this).parents('.entities').hasClass('grid-view')) { |
607 |
if ($(that).parent('.container').siblings('.more').length>0) { |
608 |
$(that).parent('.container').fadeOut(50,'easeInCirc'); |
609 |
$(that).parent('.container').siblings('.more').fadeIn(150,'easeInCirc'); |
610 |
} |
611 |
} |
612 |
}); |
613 |
$('.entities li .more').mouseleave(function(e) { |
614 |
$(this).fadeOut(50, function() { |
615 |
$(this).siblings('.container').fadeIn(50); |
616 |
}); |
617 |
}); |
618 |
$('.grid-view .items-list > li').mouseleave(function(e){ |
619 |
var that = this; |
620 |
setTimeout(function(){
|
621 |
$(that).find('.more').fadeOut(200, function() { |
622 |
$(this).siblings('.container').fadeIn('fast'); |
623 |
}); |
624 |
},50)
|
625 |
}); |
626 |
|
627 |
ui.closeDiv($('.info .close'), '.info'); |
628 |
ui.editable(); |
629 |
ui.overlay(); |
630 |
ui.colorPickerVisible = 0;
|
631 |
|
632 |
$("a.disabled").each(function() { |
633 |
$(this).removeAttr('href'); |
634 |
}); |
635 |
|
636 |
$("a.disabled").click(function(e) { |
637 |
e.preventDefault(); |
638 |
}); |
639 |
|
640 |
// checkbox: basic reaction on click (checked, unchecked)
|
641 |
// see wizard
|
642 |
$('.check').on('click', function(e){ |
643 |
e.preventDefault(); |
644 |
e.stopPropagation(); |
645 |
ui.changeCheckboxState(this);
|
646 |
}); |
647 |
|
648 |
// for checkboxes created after document.ready
|
649 |
$('.items-list').on('click','.check', function(e){ |
650 |
e.preventDefault(); |
651 |
e.stopPropagation(); |
652 |
ui.changeCheckboxState(this);
|
653 |
}) |
654 |
|
655 |
|
656 |
$('.with-checkbox').click(function(e){ |
657 |
e.preventDefault(); |
658 |
e.stopPropagation(); |
659 |
var checkbox = $(this).find('.check'); |
660 |
ui.changeCheckboxState(checkbox); |
661 |
}); |
662 |
|
663 |
$('.with-checkbox').find('a').click(function(e){ |
664 |
e.stopPropagation(); |
665 |
}) |
666 |
$('.radio_btn').click(function(e) { |
667 |
e.preventDefault(); |
668 |
var state = $(this).find('span'); |
669 |
if(state.hasClass('snf-radio-unchecked')) { |
670 |
ui.checkOneRadioButton(this);
|
671 |
ui.changeRadiobuttonState(this);
|
672 |
} |
673 |
}); |
674 |
|
675 |
$('.main-actions li a').click(function(e){ |
676 |
if (!($(this).hasClass('active'))) { |
677 |
e.preventDefault(); |
678 |
} |
679 |
}); |
680 |
|
681 |
$('.main-actions li a').click(function(e){ |
682 |
if (!($(this).hasClass('active'))) { |
683 |
e.preventDefault(); |
684 |
} |
685 |
}); |
686 |
$('.overlay-area-custom').children('.close').click(function(e){ |
687 |
e.preventDefault(); |
688 |
e.stopPropagation(); |
689 |
$(this).parents('.overlay-area-custom').hide(); |
690 |
$(this).parents('.overlay-area-custom').find($('.overlay-div')).hide(); |
691 |
$('body').removeClass('with-overlay'); |
692 |
}) |
693 |
|
694 |
$('.browse-files').click(function(e){ |
695 |
e.preventDefault(); |
696 |
}) |
697 |
|
698 |
Dropzone.options.filesDropzone = { |
699 |
dictDefaultMessage:'', |
700 |
clickable: '.browse-files', |
701 |
previewsContainer: '.dropzone-files', |
702 |
createImageThumbnails: false, |
703 |
dictRemoveFile: "snf-Remove file", |
704 |
}; |
705 |
|
706 |
|
707 |
$('.main .files').magnificPopup({ |
708 |
delegate: 'a.show.image', |
709 |
type: 'image', |
710 |
tLoading: 'Loading image #%curr%...', |
711 |
mainClass: 'mfp-img-mobile', |
712 |
gallery: {
|
713 |
enabled: true, |
714 |
navigateByImgClick: true, |
715 |
preload: [0,1] // Will preload 0 - before current, and 1 after the current image |
716 |
}, |
717 |
image: {
|
718 |
tError: 'The image could not be loaded.', |
719 |
titleSrc: function(item) { |
720 |
return item.el.data('title'); |
721 |
} |
722 |
} |
723 |
}); |
724 |
|
725 |
if($('#picker-1').length>0) { |
726 |
$('#picker-1').farbtastic('#color-1'); |
727 |
}; |
728 |
if($('#picker-2').length>0) { |
729 |
$('#picker-2').farbtastic('#color-2'); |
730 |
}; |
731 |
if($('#sb-search').length>0) { |
732 |
new UISearch( document.getElementById( 'sb-search' ) ); |
733 |
} |
734 |
|
735 |
if ($('.toggle-lt-bar').length>0) { |
736 |
ui.ltBarToggle(400);
|
737 |
} |
738 |
|
739 |
/* grid/list view for items-list */
|
740 |
|
741 |
$('.actions-bar .list, .actions-bar .grid').click(function(e){ |
742 |
//e.preventDefault();
|
743 |
if (!($(this).find('span').hasClass('current'))) { |
744 |
$('.actions-bar .grid span, .actions-bar .list span').removeClass('current'); |
745 |
$(this).find('span').addClass('current'); |
746 |
$('.entities').toggleClass('grid-view list-view'); |
747 |
} |
748 |
}); |
749 |
|
750 |
$('.lt-bar .select').click(function(e){ |
751 |
$(this).find('span').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
752 |
$(this).find('em').toggle(); |
753 |
if ( $(this).find('span').hasClass('snf-checkbox-unchecked')){ |
754 |
$('.list-view li .check span').removeClass('snf-checkbox-checked'); |
755 |
$('.list-view li .check span').addClass('snf-checkbox-unchecked'); |
756 |
} else {
|
757 |
$('.list-view li .check span').addClass('snf-checkbox-checked'); |
758 |
$('.list-view li .check span').removeClass('snf-checkbox-unchecked'); |
759 |
} |
760 |
ui.entitiesActionsEnabled(); |
761 |
ui.checkedListItems(); |
762 |
}); |
763 |
|
764 |
// set filter visible
|
765 |
$('.filter-menu .filter').click(function(e) { |
766 |
e.preventDefault(); |
767 |
$(this).parents('.filter-menu').toggleClass('current'); |
768 |
}); |
769 |
|
770 |
// temp function used to demonstrate the visual effect of the building state of vm
|
771 |
$('[data-status="building"] .btn5.temp').click(function(e) { |
772 |
e.preventDefault(); |
773 |
$(this).siblings('.container').find('.complete').toggleClass('build-progress'); |
774 |
}); |
775 |
|
776 |
$('[data-status="rebooting"] .btn5.temp').click(function(e) { |
777 |
e.preventDefault(); |
778 |
$(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress'); |
779 |
}) |
780 |
|
781 |
// //temp function to preventDefault of links in modal
|
782 |
// $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
|
783 |
// e.preventDefault();
|
784 |
// $('a.close-reveal-modal').trigger('click');
|
785 |
// });
|
786 |
|
787 |
// temp btn to show communication error message
|
788 |
$('.temp-for-btns .communication-error-btn').click(function(e) { |
789 |
e.preventDefault(); |
790 |
e.stopPropagation(); |
791 |
$('.communication-error').animate({bottom: "0px"}); |
792 |
}); |
793 |
|
794 |
$('.communication-error a').click(function(e) { |
795 |
e.preventDefault(); |
796 |
e.stopPropagation(); |
797 |
$('.communication-error').animate({bottom: "-151px"}); |
798 |
|
799 |
}); |
800 |
$('.communication-error').click(function(e) { |
801 |
e.stopPropagation(); |
802 |
}); |
803 |
|
804 |
$('.show-add-tag').click(function(e) { |
805 |
e.preventDefault(); |
806 |
$(this).parents('.tags-area, .tags').find('.snf-color-picker').slideDown('slow', function() { |
807 |
$('#hide-add-tag-dummy').scrollintoview({ |
808 |
'duration': 'slow' |
809 |
}); |
810 |
}); |
811 |
ui.colorPickerVisible = 1;
|
812 |
}); |
813 |
|
814 |
$('.hide-add-tag').click(function(e) { |
815 |
e.preventDefault(); |
816 |
$(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() { |
817 |
$('.show-add-tag').first().scrollintoview({ |
818 |
'duration': 'slow' |
819 |
}); |
820 |
ui.colorPickerVisible = 0;
|
821 |
}); |
822 |
}); |
823 |
|
824 |
// connected details js
|
825 |
ui.detailsCustom($('#disk-connected')); |
826 |
ui.detailsCustom($('#network-connected')); |
827 |
ui.detailsCustom($('#vm-connected')); |
828 |
ui.firewallSetup(); |
829 |
$('.firewall .more a').click(function(e){ |
830 |
e.preventDefault(); |
831 |
if ($(this).find('span').hasClass('snf-radio-checked')) { |
832 |
return false; |
833 |
} |
834 |
$(this).parents('.firewall').removeAttr('data-firewall'); |
835 |
$(this).parents('.firewall').data('firewall', $(this).parent().attr('class')); |
836 |
$(this).find('span').toggleClass('snf-radio-unchecked snf-radio-checked'); |
837 |
$(this).parent('p').siblings('p').find('span').removeClass('snf-radio-checked'); |
838 |
$(this).parent('p').siblings('p').find('span').addClass('snf-radio-unchecked'); |
839 |
ui.firewallSetup(); |
840 |
}); |
841 |
$('.firewall').mouseenter(function(e){ |
842 |
$(this).css('z-index',2); |
843 |
$(this).find('.more').stop(true, true).slideDown(200); |
844 |
}); |
845 |
$('.firewall').mouseleave(function(e){ |
846 |
$(this).css('z-index',1); |
847 |
$(this).find('.more').stop(true, true).slideUp(200); |
848 |
}); |
849 |
ui.tabs($('.tabs'), $('.content')); |
850 |
ui.hashTabs($('.tabs'), $('.content')); |
851 |
ui.hashViews($('.actions-bar .rt-actions'), $('.entities')); |
852 |
|
853 |
$('.act').click(function(e) { |
854 |
$(this).addClass('pending last'); |
855 |
}); |
856 |
|
857 |
$('.remove .cancel').click(function(e) { |
858 |
e.preventDefault(); |
859 |
$('a.close-reveal-modal').trigger('click'); |
860 |
$('.last').removeClass('pending last'); |
861 |
}); |
862 |
|
863 |
$('.remove .ok').click(function(e) { |
864 |
e.preventDefault(); |
865 |
$('a.close-reveal-modal').trigger('click'); |
866 |
var connection_img = $('.connections').find('.last'); |
867 |
connection_img.addClass('open', 0); |
868 |
connection_img.removeClass('last');
|
869 |
var img = connection_img.closest('.item').find('.img-wrap .snf-font'); |
870 |
img.addClass('reboot-progress');
|
871 |
setTimeout(function() {
|
872 |
var connections_list = connection_img.closest('.connections').children('li:not(".hidden")'); |
873 |
if(connections_list.length>1) { |
874 |
connection_img.closest('li').slideUp(function(){ |
875 |
connection_img.closest('li').addClass('hidden'); |
876 |
if(connections_list.find('.pending').length == 0) { |
877 |
img.removeClass('reboot-progress');
|
878 |
} |
879 |
}); |
880 |
} |
881 |
else {
|
882 |
connection_img.closest('.item').slideUp(function(){ |
883 |
img.closest('li').addClass('hidden'); |
884 |
img.removeClass('reboot-progress');
|
885 |
img.removeClass('reboot-progress');
|
886 |
}); |
887 |
} |
888 |
connection_img.removeClass('pending');
|
889 |
}, 3000)
|
890 |
}); |
891 |
// end of connected details js
|
892 |
|
893 |
ui.replaceClass($('a.current, a.active'), 'outline', 'full', 'snf-'); |
894 |
|
895 |
// with the function below the sidebar in detailed views
|
896 |
// will not hide if we click something in a wizard
|
897 |
$('.wizard').click(function(e) { |
898 |
e.stopPropagation(); |
899 |
}) |
900 |
|
901 |
$('.tag-data').mouseover(function() { |
902 |
$(this).find('.delete').css({visibility: 'visible'}) |
903 |
}); |
904 |
$('.tag-data').mouseleave(function(){ |
905 |
$(this).find('.delete').css({visibility: 'hidden'}) |
906 |
}); |
907 |
$('.tag-data .delete').click(function(e) { |
908 |
e.preventDefault(); |
909 |
$(this).closest('div').fadeOut('slow'); |
910 |
}); |
911 |
|
912 |
$('.storage-progress').hover( |
913 |
function(e){
|
914 |
$(this).find('.details').stop(false,true).slideDown(); |
915 |
}, |
916 |
function(e){
|
917 |
$(this).find('.details').stop(false,true).slideUp(); |
918 |
} |
919 |
); |
920 |
|
921 |
$('.btn-more').mouseenter(function(e) { |
922 |
$(this).find('.explain').stop(true, true).show('slow'); |
923 |
}); |
924 |
|
925 |
$('.btn-more').click(function(e) { |
926 |
e.preventDefault(); |
927 |
e.stopPropagation(); |
928 |
$('.btn-more').removeClass('clicked'); |
929 |
$('.btn-more').siblings('ul').hide(); |
930 |
$(this).addClass('clicked'); |
931 |
$(this).siblings('ul').stop(true, true).slideDown('slow'); |
932 |
}); |
933 |
$('.containers .project').mouseleave(function(e){ |
934 |
$(this).find('ul').fadeOut(); |
935 |
$(this).find('.btn-more').removeClass('clicked'); |
936 |
}) |
937 |
|
938 |
if ($('.containers .btn-more').length>0) { |
939 |
$('body').click(function(e){ |
940 |
$('.btn-more').removeClass('clicked'); |
941 |
$('.btn-more').siblings('ul').fadeOut(); |
942 |
}) |
943 |
} |
944 |
|
945 |
// add a <span> element inside the content of each a.wrap-a element
|
946 |
$('a.wrap-a').wrapInner('<span></span>'); |
947 |
|
948 |
}) |
949 |
|
950 |
|
951 |
$(window).resize(function(e){ |
952 |
ui.setElminHeight($('.main > .details')); |
953 |
ui.setElminHeight($('.lt-bar')); |
954 |
ui.setElHeight($('.scroll-wrap')); |
955 |
ui.setCustomScrollBar(); |
956 |
ui.setElmaxHeight($('.storage-progress')); |
957 |
|
958 |
}) |