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