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