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