Revision d0fe8c12 snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/okeanos.js
b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/okeanos.js | ||
---|---|---|
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 |
ui.checkbox = {}; |
|
13 |
ui.radiobtn = {}; |
|
14 |
|
|
15 |
/* when closeEl el is clicked, its parent with class divToCloseClass slidesUp */ |
|
16 |
ui.closeDiv = function(closeEl, divToCloseClass) { |
|
17 |
closeEl.click(function(e){ |
|
18 |
e.preventDefault(); |
|
19 |
$(this).parents(divToCloseClass).slideUp('slow'); |
|
20 |
}); |
|
21 |
} |
|
22 |
|
|
23 |
|
|
24 |
ui.trimChars = function( str, chars) { |
|
25 |
if ( str.length>chars){ |
|
26 |
return $.trim(str).substring(0, chars)+ "..."; |
|
27 |
} else { |
|
28 |
return str; |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
/* Sets element min-height |
|
34 |
* Used for .details, .lt-bar divs |
|
35 |
*/ |
|
36 |
ui.setElminHeight = function(el){ |
|
37 |
var WindowHeight = $(window).height(); |
|
38 |
var header = $('.header').outerHeight(); |
|
39 |
var actions = $('.actions-bar').height(); |
|
40 |
var h1= WindowHeight - (header+actions); |
|
41 |
el.css('min-height', h1); |
|
42 |
} |
|
43 |
|
|
44 |
/* Sets element height |
|
45 |
* Used for .details, .lt-bar divs |
|
46 |
*/ |
|
47 |
ui.setElHeight = function(el){ |
|
48 |
var WindowHeight = $(window).height(); |
|
49 |
var header = $('.header').outerHeight(); |
|
50 |
var actions = $('.actions-bar').height(); |
|
51 |
var h1= WindowHeight - (header+actions); |
|
52 |
el.css('height', h1); |
|
53 |
} |
|
54 |
|
|
55 |
/* Sets element max-height |
|
56 |
* Used for div.storage-progress |
|
57 |
*/ |
|
58 |
ui.setElmaxHeight = function(el){ |
|
59 |
var WindowHeight = $(window).height(); |
|
60 |
var header = $('.header').outerHeight(); |
|
61 |
var actions = $('.actions-bar').height(); |
|
62 |
var h1= WindowHeight - (header+actions); |
|
63 |
el.css('max-height', h1); |
|
64 |
} |
|
65 |
|
|
66 |
/* |
|
67 |
* Logic for Entities actions. Present in items_list pages |
|
68 |
* Available categories are : |
|
69 |
* - both/single ( for multiple entities/single entities) |
|
70 |
* - running/off ( for running/off entities) |
|
71 |
* - permanent ( for entities always active ) |
|
72 |
* Can be used for pithos as well |
|
73 |
* Available categories are : |
|
74 |
* - files ( for files only actions) |
|
75 |
* - folders ( for folders only actions) |
|
76 |
* - all ( for files/folders actions) |
|
77 |
*/ |
|
78 |
ui.entitiesActionsEnabled = function(){ |
|
79 |
var all = $('.snf-checkbox-checked').length; |
|
80 |
var running = $('.snf-checkbox-checked').parents('li.running').length; |
|
81 |
var off = $('.snf-checkbox-checked').parents('li.off').length; |
|
82 |
var files = $('.snf-checkbox-checked').parents('li.file').length; |
|
83 |
var folders = $('.snf-checkbox-checked').parents('li.folder').length; |
|
84 |
|
|
85 |
console.log(files,'files'); |
|
86 |
console.log(folders,'folders'); |
|
87 |
|
|
88 |
$('.lt-bar .lt-actions li:not(.permanent) a').removeClass('active'); |
|
89 |
|
|
90 |
if ( ( files * folders )>0 ) { |
|
91 |
$('.lt-actions li.all a').addClass('active'); |
|
92 |
} else { |
|
93 |
if ( files>0 ) { |
|
94 |
$('.lt-actions li.files a').addClass('active'); |
|
95 |
} |
|
96 |
if ( folders>0 ){ |
|
97 |
$('.lt-actions li.folders a').addClass('active'); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
if ( (running*off) > 0 ){ |
|
102 |
$('.lt-actions li.both a').addClass('active'); |
|
103 |
$('.lt-actions li.single a').removeClass('active'); |
|
104 |
} else { |
|
105 |
if (running > 0) { |
|
106 |
$('.lt-actions li.both a').addClass('active'); |
|
107 |
$('.lt-actions li.running a').addClass('active'); |
|
108 |
} else if (off>0) { |
|
109 |
$('.lt-actions li.both a').addClass('active'); |
|
110 |
$('.lt-actions li.off a').addClass('active'); |
|
111 |
} |
|
112 |
if ( all > 1 ) { |
|
113 |
$('.lt-actions li.single a').removeClass('active'); |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
ui.inactiveActions = function() { |
|
119 |
|
|
120 |
// Availble actions: connect, reboot, shut, destroy, start |
|
121 |
// These actions will be DISABLED |
|
122 |
var statesActions ={ |
|
123 |
'off' : ['connect', 'reboot', 'shut'], |
|
124 |
'error' : ['connect', 'reboot', 'shut', 'start'], |
|
125 |
'building' : ['reboot', 'start'], |
|
126 |
'running' : ['start'], |
|
127 |
'rebooting': ['start'], |
|
128 |
'starting' : ['start'], |
|
129 |
'shutting' : ['connect', 'reboot', 'shut'] |
|
130 |
} ; |
|
131 |
|
|
132 |
_.each (statesActions, function(val, key) { |
|
133 |
_.each(val, function(value) { |
|
134 |
var el = '.' + key + ' .' + value; |
|
135 |
$(el).addClass('inactive'); |
|
136 |
}); |
|
137 |
}) |
|
138 |
} |
|
139 |
|
|
140 |
ui.detailsCustom = function(area) { |
|
141 |
// position last connected item |
|
142 |
var el = area.find('.item').last(); |
|
143 |
// -2 is the border width; |
|
144 |
var moveY = el.find('.connections >li').last().outerHeight(true) - 2; |
|
145 |
el.css('top',moveY); |
|
146 |
el.css('marginTop', -moveY); |
|
147 |
} |
|
148 |
|
|
149 |
ui.firewallSetup = function(){ |
|
150 |
$('.firewall').each(function(){ |
|
151 |
$(this).removeClass('fully unprotected basic'); |
|
152 |
$(this).addClass($(this).data('firewall')); |
|
153 |
if($(this).hasClass('unprotected')){ |
|
154 |
$(this).find('p').first().find('em').html('off'); |
|
155 |
} else { |
|
156 |
$(this).find('p').first().find('em').html('on'); |
|
157 |
} |
|
158 |
}); |
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
/* |
|
164 |
* In order for the editable value functionality to work, the html markup |
|
165 |
* should be: |
|
166 |
<div class="editable"> |
|
167 |
<span class="input-txt">editable value</span> |
|
168 |
<input type="text"> |
|
169 |
<a href="#" class="edit">edit</a> |
|
170 |
<a href="#" class="save">save</a> |
|
171 |
<a href="#" class="cancel">cancel</a> |
|
172 |
</div> |
|
173 |
*/ |
|
174 |
ui.editable = function(){ |
|
175 |
|
|
176 |
/* |
|
177 |
* resetForm hides save and cancel buttons, |
|
178 |
* text input and shows input-txt. resetForm does not alter |
|
179 |
* input-txt content. |
|
180 |
*/ |
|
181 |
|
|
182 |
function resetForm(e, elem) { |
|
183 |
var el = elem.parents('.editable'); |
|
184 |
el.find('input[type="text"]').hide(); |
|
185 |
el.find('a.cancel, a.save').hide(); |
|
186 |
el.find('a.edit, .input-txt').show(); |
|
187 |
} |
|
188 |
|
|
189 |
/* |
|
190 |
* showForm hides input-txt, shows save and cancel buttons and |
|
191 |
* sets input value to input-txt content. |
|
192 |
*/ |
|
193 |
function showForm(e,elem) { |
|
194 |
e.stopPropagation(); |
|
195 |
e.preventDefault(); |
|
196 |
var el = elem.parents('.editable'); |
|
197 |
el.find('input[type="text"]').val(el.find('.input-txt').html()); |
|
198 |
el.find('input[type="text"]').show().focus(); |
|
199 |
el.find('a.cancel, a.save').show(); |
|
200 |
elem.hide(); |
|
201 |
el.find('.input-txt').hide(); |
|
202 |
} |
|
203 |
|
|
204 |
/* |
|
205 |
setValue sets input-txt value to the input value. |
|
206 |
Makes sure that the input value is not empty. |
|
207 |
TODO: |
|
208 |
Ajax request to submit form |
|
209 |
*/ |
|
210 |
|
|
211 |
function setValue(elem) { |
|
212 |
var el = elem.parents('.editable'); |
|
213 |
if( el.find('input[type="text"]').val() ) { |
|
214 |
el.find('.input-txt').html(el.find('input[type="text"]').val()); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
|
|
219 |
$('.editable .edit').click(function(e){ |
|
220 |
showForm(e, $(this)); |
|
221 |
}) |
|
222 |
|
|
223 |
$('.editable .cancel').click(function(e){ |
|
224 |
e.stopPropagation(); |
|
225 |
e.preventDefault(); |
|
226 |
resetForm(e, $(this)); |
|
227 |
}) |
|
228 |
|
|
229 |
$('.editable .save').click(function(e){ |
|
230 |
e.stopPropagation(); |
|
231 |
e.preventDefault(); |
|
232 |
setValue($(this)); |
|
233 |
resetForm(e, $(this)); |
|
234 |
|
|
235 |
}) |
|
236 |
|
|
237 |
|
|
238 |
$('.editable input[type="text"]').click(function(e){ |
|
239 |
e.stopPropagation(); |
|
240 |
}) |
|
241 |
|
|
242 |
$('.editable input[type="text"]').keyup(function(e){ |
|
243 |
if(e.keyCode == 13) { |
|
244 |
setValue($(this)); |
|
245 |
resetForm(e, $(this)); |
|
246 |
|
|
247 |
} |
|
248 |
|
|
249 |
}) |
|
250 |
|
|
251 |
$('html').click(function(e) { |
|
252 |
resetForm(e, $('.editable a.cancel')); |
|
253 |
}); |
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
/* TODO: better overlay functionality */ |
|
258 |
ui.overlay = function() { |
|
259 |
$('[data-overlay-id]').click(function(e){ |
|
260 |
e.preventDefault(); |
|
261 |
var el = $(this); |
|
262 |
var id = '#'+el.data('overlay-id'); |
|
263 |
|
|
264 |
$('.overlay-area-custom').fadeIn(100); |
|
265 |
$('body').addClass('with-overlay'); |
|
266 |
$(id).fadeIn('slow'); |
|
267 |
if (id=='#network-wizard') { |
|
268 |
$(id).find('input').first().focus(); |
|
269 |
return false; |
|
270 |
} |
|
271 |
$(id).find('a').first().focus(); |
|
272 |
}); |
|
273 |
} |
|
274 |
|
|
275 |
function goToByScroll(id){ |
|
276 |
// Remove "link" from the ID |
|
277 |
id = id.replace("link", ""); |
|
278 |
// Scroll |
|
279 |
$('html,body').animate({ |
|
280 |
scrollTop: $("#"+id).offset().top}, |
|
281 |
'slow'); |
|
282 |
} |
|
283 |
|
|
284 |
|
|
285 |
// toggle expand arrrow and area |
|
286 |
// todo: one function for all the areas we reveal |
|
287 |
ui.expandDownArea = function(arrow_link, area) { |
|
288 |
var arrow_link = $(arrow_link); |
|
289 |
var area = $(area); |
|
290 |
arrow_link.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down'); |
|
291 |
// $('.wizard-content').removeAttr('style'); |
|
292 |
area.stop().slideToggle(600, function() { |
|
293 |
if (area.is(':visible')) { |
|
294 |
arrow_link.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up'); |
|
295 |
} else { |
|
296 |
arrow_link.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down'); |
|
297 |
} |
|
298 |
|
|
299 |
}); |
|
300 |
} |
|
301 |
|
|
302 |
// toggle checkbox and area |
|
303 |
ui.slideHiddenArea = function(checkbox_link, area) { |
|
304 |
area.stop().slideToggle(400, function() { |
|
305 |
if (area.is(':visible')) { |
|
306 |
ui.checkbox.check(checkbox_link); |
|
307 |
} else { |
|
308 |
ui.checkbox.uncheck(checkbox_link); |
|
309 |
} |
|
310 |
}); |
|
311 |
}; |
|
312 |
/* Tabs functionality |
|
313 |
* tabsEl is the div/ul with the links to the sections and the sections that |
|
314 |
* with toggle have class sectionEl. |
|
315 |
* Markup needed is an href to each a with the id of the relative section. |
|
316 |
*/ |
|
317 |
|
|
318 |
ui.tabsSection = function(link, sectionEl) { |
|
319 |
sectionEl.hide(); |
|
320 |
var el = $(link.attr('href')); |
|
321 |
el.stop(true, true).show(0); |
|
322 |
el.css('opacity',0); |
|
323 |
ui.detailsCustom(el); |
|
324 |
el.animate({ |
|
325 |
'opacity':1, |
|
326 |
}, 500) |
|
327 |
} |
|
328 |
|
|
329 |
ui.tabs = function(tabsEl, sectionEl) { |
|
330 |
var tabLink = tabsEl.find('a'); |
|
331 |
ui.replaceClass(tabLink.find('.active'), 'outline', 'full', 'snf-'); |
|
332 |
function href(a) { |
|
333 |
return a.attr('href'); |
|
334 |
} |
|
335 |
tabLink.click(function(e){ |
|
336 |
e.preventDefault(); |
|
337 |
if ( $(this).hasClass('active')){ |
|
338 |
return false; |
|
339 |
} else { |
|
340 |
window.location.hash = $(this).attr('href'); |
|
341 |
ui.replaceClass($(this).parents(tabsEl).find('.active'), 'full', 'outline', 'snf-'); |
|
342 |
$(this).parents(tabsEl).find('a').removeClass('active'); |
|
343 |
$(this).addClass('active'); |
|
344 |
ui.replaceClass($(this), 'outline', 'full', 'snf-'); |
|
345 |
ui.tabsSection( $(this), sectionEl); |
|
346 |
} |
|
347 |
}) |
|
348 |
} |
|
349 |
|
|
350 |
// the function replaces part of the class of a span that is placed inside an a element |
|
351 |
// the class is a word with the form : firstSubStr+*+str1 and it will be converted to: firstSubStr+*+str2 |
|
352 |
// it must be uniquely recognized by the firstSubStr and the str1. |
|
353 |
|
|
354 |
ui.replaceClass = function(elements, str1, str2, firstSubStr) { |
|
355 |
$.each($(elements), function() { |
|
356 |
var classOld = $(this).find('span').attr('class'); |
|
357 |
var classNew; |
|
358 |
if(classOld != undefined && classOld.indexOf(str1) != -1) { |
|
359 |
if(classOld.indexOf(' ') == -1) { |
|
360 |
classNew = classOld.replace(str1, str2); |
|
361 |
$(this).find('.'+classOld).removeClass(classOld).addClass(classNew); |
|
362 |
} |
|
363 |
else { |
|
364 |
// the string starts with the firstSubStr and after the end of the word there's a space |
|
365 |
var expr1 = new RegExp('^'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g'); |
|
366 |
|
|
367 |
// the word is between spaces |
|
368 |
var expr2 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g'); |
|
369 |
|
|
370 |
// before the word there's at least one space and the string ends with this word |
|
371 |
var expr3 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'$', 'g'); |
|
372 |
|
|
373 |
// spaces all over the string |
|
374 |
var spacesExp = new RegExp('\\s+', 'g'); |
|
375 |
|
|
376 |
if(classOld.match(expr1) != null) { |
|
377 |
classToReplace = classOld.match(expr1); |
|
378 |
} |
|
379 |
else if(classOld.match(expr2) != null) { |
|
380 |
classToReplace = classOld.match(expr2); |
|
381 |
} |
|
382 |
else if (classOld.match(expr3) != null) { |
|
383 |
classToReplace = classOld.match(expr3); |
|
384 |
} |
|
385 |
classToReplace = classToReplace.toString().replace(spacesExp,""); |
|
386 |
classNew = classToReplace.replace(str1, str2); |
|
387 |
$(this).find('.'+classToReplace).removeClass(classToReplace).addClass(classNew); |
|
388 |
} |
|
389 |
} |
|
390 |
}); |
|
391 |
} |
|
392 |
|
|
393 |
// in a page with tabs, allow navigation with hash tags |
|
394 |
ui.hashTabs = function(tabsEl, sectionEl){ |
|
395 |
var hash = window.location.hash; |
|
396 |
if ($(hash).length<=0){ |
|
397 |
return; |
|
398 |
} |
|
399 |
tabsEl.find('a').removeClass('active'); |
|
400 |
var link = tabsEl.find('a[href="'+hash+'"]'); |
|
401 |
link.addClass('active'); |
|
402 |
ui.tabsSection(link, sectionEl); |
|
403 |
|
|
404 |
} |
|
405 |
|
|
406 |
// in a page with tabs, allow navigation with hash tags |
|
407 |
ui.hashViews = function(viewsEl, sectionEl){ |
|
408 |
var hash = window.location.hash; |
|
409 |
if (!(hash)){ |
|
410 |
return; |
|
411 |
} |
|
412 |
var link = viewsEl.find('a[href="'+hash+'"]'); |
|
413 |
console.log('link', link); |
|
414 |
if (link.length<=0){ |
|
415 |
return; |
|
416 |
} |
|
417 |
viewsEl.find('a span').removeClass('current'); |
|
418 |
link.find('span').addClass('current'); |
|
419 |
sectionEl.removeClass('grid-view list-view'); |
|
420 |
var sectionClass = hash.slice(1) + '-view'; |
|
421 |
sectionEl.addClass(sectionClass); |
|
422 |
} |
|
423 |
|
|
424 |
ui.ltBarToggle = function(speed){ |
|
425 |
|
|
426 |
var cmarg = parseInt($('.lt-bar').width()) - parseInt($('.toggle-lt-bar').outerWidth(true)); |
|
427 |
var ctemp = cmarg / parseInt($('.lt-bar').width()); |
|
428 |
var cvelocity = parseInt($('.lt-bar').width())/speed; |
|
429 |
var cdelay = parseInt($('.toggle-lt-bar').outerWidth(true))/cvelocity; |
|
430 |
|
|
431 |
$('.lt-bar').click(function(e) { |
|
432 |
e.stopPropagation(); |
|
433 |
}) |
|
434 |
$('.toggle-lt-bar').click(function(e){ |
|
435 |
e.preventDefault(); |
|
436 |
e.stopPropagation(); |
|
437 |
var self =this; |
|
438 |
if($(this).hasClass('fix-position')) { |
|
439 |
var marg = parseInt($(self).css('marginLeft')) - cmarg; |
|
440 |
$(this).animate({ |
|
441 |
'margin-left': marg, |
|
442 |
}, ctemp * speed, 'linear', function(){ |
|
443 |
$(self).removeAttr('style'); |
|
444 |
$(self).removeClass('fix-position'); |
|
445 |
}); |
|
446 |
$('.lt-bar').animate({ |
|
447 |
width: 'toggle' |
|
448 |
}, speed, 'linear'); |
|
449 |
} |
|
450 |
else { |
|
451 |
$(this).addClass('fix-position'); |
|
452 |
var scrollBarWidth = 14; |
|
453 |
var marg = parseInt($(self).css('marginLeft')) + cmarg - scrollBarWidth; |
|
454 |
setTimeout(function(){ |
|
455 |
$(self).animate({ |
|
456 |
'margin-left': marg, |
|
457 |
}, speed, 'linear') |
|
458 |
}, cdelay); |
|
459 |
$('.lt-bar').animate({ |
|
460 |
width: 'toggle' |
|
461 |
}, speed, 'linear', ui.setCustomScrollBar); |
|
462 |
} |
|
463 |
}); |
|
464 |
} |
|
465 |
|
|
466 |
|
|
467 |
ui.setCustomScrollBar = function() { |
|
468 |
$('.scroll-pane-arrows').jScrollPane({ |
|
469 |
showArrows: true, |
|
470 |
horizontalGutter: 10, |
|
471 |
verticalDragMinHeight: 300, |
|
472 |
verticalDragMaxHeight: 300, |
|
473 |
mouseWheelSpeed: 50 |
|
474 |
}); |
|
475 |
} |
|
476 |
|
|
477 |
function bytesToSize(bytes) { |
|
478 |
var sizes = [ 'n/a', 'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
|
479 |
var i = +Math.floor(Math.log(bytes) / Math.log(1024)); |
|
480 |
return (bytes / Math.pow(1024, i)).toFixed( 0 ) + sizes[ isNaN( bytes ) ? 0 : i+1 ]; |
|
481 |
} |
|
482 |
function date_ddmmmyytime(date) |
|
483 |
{ |
|
484 |
var d = date.getDate(); |
|
485 |
var m = date.getMonth(); |
|
486 |
var y = date.getYear(); |
|
487 |
if(y >= 100) |
|
488 |
{ |
|
489 |
y -= 100; |
|
490 |
y += 2000; |
|
491 |
} |
|
492 |
|
|
493 |
var curr_hour = date.getHours(); |
|
494 |
|
|
495 |
if (curr_hour < 12){ |
|
496 |
a_p = "am"; |
|
497 |
} else { |
|
498 |
a_p = "pm"; |
|
499 |
} |
|
500 |
|
|
501 |
if (curr_hour == 0) { |
|
502 |
curr_hour = 12; |
|
503 |
} |
|
504 |
if (curr_hour > 12){ |
|
505 |
curr_hour = curr_hour - 12; |
|
506 |
} |
|
507 |
|
|
508 |
var curr_min = date.getMinutes(); |
|
509 |
|
|
510 |
return "" + |
|
511 |
(d<10?"0"+d:d) + "/" +m + "/" + y + ' '+curr_hour + ":" + curr_min + a_p; |
|
512 |
} |
|
513 |
|
|
514 |
// returns the file class/extension of a file |
|
515 |
ui.mimeToExt = function( mimetype) { |
|
516 |
var mimeExt = { |
|
517 |
'image/jpeg': 'jpg', |
|
518 |
'image/png': 'png', |
|
519 |
'application/pdf': 'pdf', |
|
520 |
'text/plain': 'txt', |
|
521 |
}; |
|
522 |
console.log(mimetype); |
|
523 |
return mimeExt[mimetype] || 'unknown'; |
|
524 |
} |
|
525 |
|
|
526 |
$(document).ready(function(){ |
|
527 |
|
|
528 |
$('html').click(function(e) { |
|
529 |
// not sure if we want to hide the error window after every click in the ui |
|
530 |
if($('.communication-error').css('bottom') == '0px') { |
|
531 |
$('.communication-error').animate({bottom: "-151px"}); |
|
532 |
} |
|
533 |
}); |
|
534 |
|
|
535 |
if($('.vms.entities').length!=0){ |
|
536 |
ui.inactiveActions(); |
|
537 |
}; |
|
538 |
ui.setElminHeight($('.main > .details')); |
|
539 |
ui.setElminHeight($('.lt-bar')); |
|
540 |
ui.setElmaxHeight($('.storage-progress')); |
|
541 |
ui.setElHeight($('.scroll-wrap')); |
|
542 |
$('#hd-search .hd-icon-search').click(function(e){ |
|
543 |
var that = this; |
|
544 |
$(this).parents('.hd-search').toggleClass('hd-open'); |
|
545 |
if ($(this).parents('.hd-search').hasClass('hd-open')) { |
|
546 |
$(that).parents('.hd-search').find('input[type="search"]').focus(); |
|
547 |
} else { |
|
548 |
$(that).parents('.hd-search').find('input[type="search"]').val(''); |
|
549 |
} |
|
550 |
}) |
|
551 |
|
|
552 |
$('.header .login').mouseenter(function(e){ |
|
553 |
$(this).find('ul').stop(true, true).slideDown(200); |
|
554 |
}); |
|
555 |
$('.header .login').mouseleave(function(e){ |
|
556 |
$(this).find('ul').stop(true, true).slideUp(200); |
|
557 |
}); |
|
558 |
|
|
559 |
$('.entities a').click(function(){ |
|
560 |
if ($(this).attr('data-reveal-id') && !($(this).hasClass('inactive'))) { |
|
561 |
$('.entities li .more').hide(); |
|
562 |
} |
|
563 |
}); |
|
564 |
|
|
565 |
$('.inactive').click(function(e){ |
|
566 |
e.stopPropagation(); |
|
567 |
e.preventDefault(); |
|
568 |
}); |
|
569 |
|
|
570 |
$('.arrows').on('click','.inactive', function(e){ |
|
571 |
e.preventDefault(); |
|
572 |
e.stopPropagation(); |
|
573 |
}); |
|
574 |
|
|
575 |
|
|
576 |
$('.lt-actions a:not(.active)').click(function(e){ |
|
577 |
e.preventDefault(); |
|
578 |
}) |
|
579 |
|
|
580 |
if ($('.entities .items-list >li').length == 1) { |
|
581 |
$('.body-wrapper').addClass('no-vm'); |
|
582 |
}; |
|
583 |
$('.entities li .more').each(function(){ |
|
584 |
var width = $(this).parent('li').outerWidth() + 20; |
|
585 |
$(this).css('width', width); |
|
586 |
}); |
|
587 |
|
|
588 |
$('.items-list li .img-wrap').on("mouseenter", function(e) { |
|
589 |
var that = this; |
|
590 |
if ($(this).parents('.entities').hasClass('grid-view')) { |
|
591 |
if ($(that).parent('.container').siblings('.more').length>0) { |
|
592 |
$(that).parent('.container').fadeOut(50,'easeInCirc'); |
|
593 |
$(that).parent('.container').siblings('.more').fadeIn(150,'easeInCirc'); |
|
594 |
} |
|
595 |
} |
|
596 |
}); |
|
597 |
$('.entities li .more').mouseleave(function(e) { |
|
598 |
$(this).fadeOut(50, function() { |
|
599 |
$(this).siblings('.container').fadeIn(50); |
|
600 |
}); |
|
601 |
}); |
|
602 |
$('.grid-view .items-list > li').mouseleave(function(e){ |
|
603 |
var that = this; |
|
604 |
setTimeout(function(){ |
|
605 |
$(that).find('.more').fadeOut(200, function() { |
|
606 |
$(this).siblings('.container').fadeIn('fast'); |
|
607 |
}); |
|
608 |
},50) |
|
609 |
}); |
|
610 |
|
|
611 |
ui.closeDiv($('.info .close'), '.info'); |
|
612 |
ui.editable(); |
|
613 |
ui.overlay(); |
|
614 |
ui.colorPickerVisible = 0; |
|
615 |
|
|
616 |
$("a.disabled").each(function() { |
|
617 |
$(this).removeAttr('href'); |
|
618 |
}); |
|
619 |
|
|
620 |
$("a.disabled").click(function(e) { |
|
621 |
e.preventDefault(); |
|
622 |
}); |
|
623 |
|
|
624 |
$('.main-actions li a').click(function(e){ |
|
625 |
if (!($(this).hasClass('active'))) { |
|
626 |
e.preventDefault(); |
|
627 |
} |
|
628 |
}); |
|
629 |
|
|
630 |
$('.main-actions li a').click(function(e){ |
|
631 |
if (!($(this).hasClass('active'))) { |
|
632 |
e.preventDefault(); |
|
633 |
} |
|
634 |
}); |
|
635 |
$('.overlay-area-custom').children('.close').click(function(e){ |
|
636 |
e.preventDefault(); |
|
637 |
e.stopPropagation(); |
|
638 |
$(this).parents('.overlay-area-custom').hide(); |
|
639 |
$(this).parents('.overlay-area-custom').find($('.overlay-div')).hide(); |
|
640 |
$('body').removeClass('with-overlay'); |
|
641 |
}) |
|
642 |
|
|
643 |
$('.browse-files').click(function(e){ |
|
644 |
e.preventDefault(); |
|
645 |
}); |
|
646 |
|
|
647 |
$('.main .files').magnificPopup({ |
|
648 |
delegate: 'a.show.image', |
|
649 |
type: 'image', |
|
650 |
tLoading: 'Loading image #%curr%...', |
|
651 |
mainClass: 'mfp-img-mobile', |
|
652 |
gallery: { |
|
653 |
enabled: true, |
|
654 |
navigateByImgClick: true, |
|
655 |
preload: [0,1] // Will preload 0 - before current, and 1 after the current image |
|
656 |
}, |
|
657 |
image: { |
|
658 |
tError: 'The image could not be loaded.', |
|
659 |
titleSrc: function(item) { |
|
660 |
return item.el.data('title'); |
|
661 |
} |
|
662 |
} |
|
663 |
}); |
|
664 |
|
|
665 |
if($('#picker-1').length>0) { |
|
666 |
$('#picker-1').farbtastic('#color-1'); |
|
667 |
}; |
|
668 |
if($('#picker-2').length>0) { |
|
669 |
$('#picker-2').farbtastic('#color-2'); |
|
670 |
}; |
|
671 |
if($('#sb-search').length>0) { |
|
672 |
new UISearch( document.getElementById( 'sb-search' ) ); |
|
673 |
} |
|
674 |
|
|
675 |
if ($('.toggle-lt-bar').length>0) { |
|
676 |
ui.ltBarToggle(400); |
|
677 |
} |
|
678 |
|
|
679 |
/* grid/list view for items-list */ |
|
680 |
|
|
681 |
$('.actions-bar .list, .actions-bar .grid').click(function(e){ |
|
682 |
//e.preventDefault(); |
|
683 |
if (!($(this).find('span').hasClass('current'))) { |
|
684 |
$('.actions-bar .grid span, .actions-bar .list span').removeClass('current'); |
|
685 |
$(this).find('span').addClass('current'); |
|
686 |
$('.entities').toggleClass('grid-view list-view'); |
|
687 |
} |
|
688 |
}); |
|
689 |
|
|
690 |
|
|
691 |
|
|
692 |
// set filter visible |
|
693 |
$('.filter-menu .filter').click(function(e) { |
|
694 |
e.preventDefault(); |
|
695 |
$(this).parents('.filter-menu').toggleClass('current'); |
|
696 |
}); |
|
697 |
|
|
698 |
// temp function used to demonstrate the visual effect of the building state of vm |
|
699 |
$('[data-status="building"] .btn5.temp').click(function(e) { |
|
700 |
e.preventDefault(); |
|
701 |
$(this).siblings('.container').find('.complete').toggleClass('build-progress'); |
|
702 |
}); |
|
703 |
|
|
704 |
$('[data-status="rebooting"] .btn5.temp').click(function(e) { |
|
705 |
e.preventDefault(); |
|
706 |
$(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress'); |
|
707 |
}) |
|
708 |
|
|
709 |
// //temp function to preventDefault of links in modal |
|
710 |
// $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){ |
|
711 |
// e.preventDefault(); |
|
712 |
// $('a.close-reveal-modal').trigger('click'); |
|
713 |
// }); |
|
714 |
|
|
715 |
// temp btn to show communication error message |
|
716 |
$('.temp-for-btns .communication-error-btn').click(function(e) { |
|
717 |
e.preventDefault(); |
|
718 |
e.stopPropagation(); |
|
719 |
$('.communication-error').animate({bottom: "0px"}); |
|
720 |
}); |
|
721 |
|
|
722 |
$('.communication-error a').click(function(e) { |
|
723 |
e.preventDefault(); |
|
724 |
e.stopPropagation(); |
|
725 |
$('.communication-error').animate({bottom: "-151px"}); |
|
726 |
|
|
727 |
}); |
|
728 |
$('.communication-error').click(function(e) { |
|
729 |
e.stopPropagation(); |
|
730 |
}); |
|
731 |
|
|
732 |
$('.show-add-tag').click(function(e) { |
|
733 |
e.preventDefault(); |
|
734 |
$(this).parents('.tags-area, .tags').find('.snf-color-picker').slideDown('slow', function() { |
|
735 |
$('#hide-add-tag-dummy').scrollintoview({ |
|
736 |
'duration': 'slow' |
|
737 |
}); |
|
738 |
}); |
|
739 |
ui.colorPickerVisible = 1; |
|
740 |
}); |
|
741 |
|
|
742 |
$('.hide-add-tag').click(function(e) { |
|
743 |
e.preventDefault(); |
|
744 |
$(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() { |
|
745 |
$('.show-add-tag').first().scrollintoview({ |
|
746 |
'duration': 'slow' |
|
747 |
}); |
|
748 |
ui.colorPickerVisible = 0; |
|
749 |
}); |
|
750 |
}); |
|
751 |
|
|
752 |
// connected details js |
|
753 |
ui.detailsCustom($('#disk-connected')); |
|
754 |
ui.detailsCustom($('#network-connected')); |
|
755 |
ui.detailsCustom($('#vm-connected')); |
|
756 |
ui.firewallSetup(); |
|
757 |
|
|
758 |
$('.firewall').mouseenter(function(e){ |
|
759 |
$(this).css('z-index',2); |
|
760 |
$(this).find('.more').stop(true, true).slideDown(200); |
|
761 |
}); |
|
762 |
$('.firewall').mouseleave(function(e){ |
|
763 |
$(this).css('z-index',1); |
|
764 |
$(this).find('.more').stop(true, true).slideUp(200); |
|
765 |
}); |
|
766 |
ui.tabs($('.tabs'), $('.content')); |
|
767 |
ui.hashTabs($('.tabs'), $('.content')); |
|
768 |
ui.hashViews($('.actions-bar .rt-actions'), $('.entities')); |
|
769 |
|
|
770 |
$('.act').click(function(e) { |
|
771 |
$(this).addClass('pending last'); |
|
772 |
}); |
|
773 |
|
|
774 |
$('.remove .cancel').click(function(e) { |
|
775 |
e.preventDefault(); |
|
776 |
$('a.close-reveal-modal').trigger('click'); |
|
777 |
$('.last').removeClass('pending last'); |
|
778 |
}); |
|
779 |
|
|
780 |
$('.remove .ok').click(function(e) { |
|
781 |
e.preventDefault(); |
|
782 |
$('a.close-reveal-modal').trigger('click'); |
|
783 |
var connection_img = $('.connections').find('.last'); |
|
784 |
connection_img.addClass('open', 0); |
|
785 |
connection_img.removeClass('last'); |
|
786 |
var img = connection_img.closest('.item').find('.img-wrap .snf-font'); |
|
787 |
img.addClass('reboot-progress'); |
|
788 |
setTimeout(function() { |
|
789 |
var connections_list = connection_img.closest('.connections').children('li:not(".hidden")'); |
|
790 |
if(connections_list.length>1) { |
|
791 |
connection_img.closest('li').slideUp(function(){ |
|
792 |
connection_img.closest('li').addClass('hidden'); |
|
793 |
if(connections_list.find('.pending').length == 0) { |
|
794 |
img.removeClass('reboot-progress'); |
|
795 |
} |
|
796 |
}); |
|
797 |
} |
|
798 |
else { |
|
799 |
connection_img.closest('.item').slideUp(function(){ |
|
800 |
img.closest('li').addClass('hidden'); |
|
801 |
img.removeClass('reboot-progress'); |
|
802 |
img.removeClass('reboot-progress'); |
|
803 |
}); |
|
804 |
} |
|
805 |
connection_img.removeClass('pending'); |
|
806 |
}, 3000) |
|
807 |
}); |
|
808 |
// end of connected details js |
|
809 |
|
|
810 |
ui.replaceClass($('a.current, a.active'), 'outline', 'full', 'snf-'); |
|
811 |
|
|
812 |
$('.tag-data').mouseover(function() { |
|
813 |
$(this).find('.delete').css({visibility: 'visible'}) |
|
814 |
}); |
|
815 |
$('.tag-data').mouseleave(function(){ |
|
816 |
$(this).find('.delete').css({visibility: 'hidden'}) |
|
817 |
}); |
|
818 |
$('.tag-data .delete').click(function(e) { |
|
819 |
e.preventDefault(); |
|
820 |
$(this).closest('div').fadeOut('slow'); |
|
821 |
}); |
|
822 |
|
|
823 |
$('.storage-progress').hover( |
|
824 |
function(e){ |
|
825 |
$(this).find('.details').stop(false,true).slideDown(); |
|
826 |
}, |
|
827 |
function(e){ |
|
828 |
$(this).find('.details').stop(false,true).slideUp(); |
|
829 |
} |
|
830 |
); |
|
831 |
|
|
832 |
$('.btn-more').mouseenter(function(e) { |
|
833 |
$(this).find('.explain').stop(true, true).show('slow'); |
|
834 |
}); |
|
835 |
|
|
836 |
$('.btn-more').click(function(e) { |
|
837 |
e.preventDefault(); |
|
838 |
e.stopPropagation(); |
|
839 |
$('.btn-more').removeClass('clicked'); |
|
840 |
$('.btn-more').siblings('ul').hide(); |
|
841 |
$(this).addClass('clicked'); |
|
842 |
$(this).siblings('ul').stop(true, true).slideDown('slow'); |
|
843 |
}); |
|
844 |
$('.containers .project').mouseleave(function(e){ |
|
845 |
$(this).find('ul').fadeOut(); |
|
846 |
$(this).find('.btn-more').removeClass('clicked'); |
|
847 |
}) |
|
848 |
|
|
849 |
if ($('.containers .btn-more').length>0) { |
|
850 |
$('body').click(function(e){ |
|
851 |
$('.btn-more').removeClass('clicked'); |
|
852 |
$('.btn-more').siblings('ul').fadeOut(); |
|
853 |
}) |
|
854 |
} |
|
855 |
|
|
856 |
// add a <span> element inside the content of each a.wrap-a element |
|
857 |
$('a.wrap-a').wrapInner('<span></span>'); |
|
858 |
|
|
859 |
|
|
860 |
$('.side-actions .bottom .reassign').click(function(e){ |
|
861 |
e.preventDefault(); |
|
862 |
$(this).parents('.bottom').find('ul').hide(); |
|
863 |
$(this).parents('.bottom').find('ul.options').show(); |
|
864 |
}); |
|
865 |
|
|
866 |
$('.side-actions ul.options').mouseleave(function(e){ |
|
867 |
$(this).hide(); |
|
868 |
$(this).siblings('ul').removeAttr('style'); |
|
869 |
}) |
|
870 |
|
|
871 |
}) |
|
872 |
|
|
873 |
|
|
874 |
$(window).resize(function(e){ |
|
875 |
ui.setElminHeight($('.main > .details')); |
|
876 |
ui.setElminHeight($('.lt-bar')); |
|
877 |
ui.setElHeight($('.scroll-wrap')); |
|
878 |
ui.setCustomScrollBar(); |
|
879 |
ui.setElmaxHeight($('.storage-progress')); |
|
880 |
|
|
881 |
}) |
|
882 |
;/* |
|
883 |
* functions concerning checkboxes and radiobuttons links |
|
884 |
*/ |
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
ui.checkbox = { |
|
889 |
changeState : function(checkbox_link) { |
|
890 |
$(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked'); |
|
891 |
$(checkbox_link).closest('li').toggleClass('selected'); |
|
892 |
}, |
|
893 |
check : function(checkbox_link) { |
|
894 |
$(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
|
895 |
$(checkbox_link).closest('li').addClass('selected'); |
|
896 |
}, |
|
897 |
uncheck : function(checkbox_link) { |
|
898 |
$(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
|
899 |
$(checkbox_link).closest('li').removeClass('selected'); |
|
900 |
}, |
|
901 |
|
|
902 |
reset: function(area) { |
|
903 |
$(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
|
904 |
$(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
|
905 |
} |
|
906 |
|
|
907 |
}; |
|
908 |
|
|
909 |
ui.radiobtn = { |
|
910 |
changeState: function(radiobtn_link) { |
|
911 |
$(radiobtn_link).find('span.snf-radio-unchecked, span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked'); |
|
912 |
$(radiobtn_link).closest('li').addClass('selected'); |
|
913 |
}, |
|
914 |
obtainOneChecked : function(radiobtn_link) { |
|
915 |
$(radiobtn_link).closest('ul').find('li').removeClass('selected'); |
|
916 |
$(radiobtn_link).closest('ul').find('span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked'); |
|
917 |
}, |
|
918 |
reset : function(area) { |
|
919 |
$(area).find('.snf-checkbox-checked').not('.prechecked').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
|
920 |
$(area).find('.snf-checkbox-unchecked.prechecked').toggleClass('snf-checkbox-checked snf-checkbox-unchecked'); |
|
921 |
} |
|
922 |
|
|
923 |
}; |
|
924 |
|
|
925 |
$(document).ready(function(){ |
|
926 |
|
|
927 |
// checkboxes binds |
|
928 |
|
|
929 |
$('.check').click(function(e) { |
|
930 |
e.preventDefault(); |
|
931 |
e.stopPropagation(); |
|
932 |
ui.checkbox.changeState(this); |
|
933 |
ui.entitiesActionsEnabled(); |
|
934 |
}); |
|
935 |
|
|
936 |
$('.lt-bar .select .check').click(function(e) { |
|
937 |
$(this).siblings('em').toggle(); |
|
938 |
if ( $(this).find('span').hasClass('snf-checkbox-unchecked')){ |
|
939 |
ui.checkbox.uncheck($('.list-view li:not(".not-selectable") .check')); |
|
940 |
} else { |
|
941 |
ui.checkbox.check($('.list-view li:not(".not-selectable") .check')); |
|
942 |
} |
|
943 |
}); |
|
944 |
|
|
945 |
$('.trigger-checkbox.has-more .check').click(function(e) { |
|
946 |
ui.slideHiddenArea(this, $(this).parent().next('.more')); |
|
947 |
}); |
|
948 |
|
|
949 |
$('.dhcp-option .check').click(function(e) { |
|
950 |
$(this).parents('li').siblings().find('ul.subnet-options').parent('li').toggle(); |
|
951 |
}); |
|
952 |
|
|
953 |
// for lis that we want to change the checkbox state |
|
954 |
$('.trigger-checkbox').click(function(e){ |
|
955 |
$(this).find('.check').trigger('click'); |
|
956 |
}); |
|
957 |
|
|
958 |
$('.trigger-checkbox').find('a').click(function(e){ |
|
959 |
e.stopPropagation(); |
|
960 |
}); |
|
961 |
|
|
962 |
// for checkboxes created after document.ready |
|
963 |
$('.items-list').on('click','.check', function(e){ |
|
964 |
e.preventDefault(); |
|
965 |
e.stopPropagation(); |
|
966 |
ui.changeCheckboxState(this); |
|
967 |
}); |
|
968 |
|
|
969 |
// radiobuttons binds |
|
970 |
|
|
971 |
$('.radiobtn').click(function(e) { |
|
972 |
e.stopPropagation(); |
|
973 |
e.preventDefault(); |
|
974 |
if($(this).find('span').hasClass('snf-radio-unchecked')) { |
|
975 |
ui.radiobtn.obtainOneChecked(this); |
|
976 |
ui.radiobtn.changeState(this); |
|
977 |
} |
|
978 |
}); |
|
979 |
|
|
980 |
$('.subnet-options .radiobtn').click(function(e) { |
|
981 |
if($(this).closest('li').hasClass('manual')) { |
|
982 |
$(this).siblings('.input').show(); |
|
983 |
} |
|
984 |
else { |
|
985 |
$(this).closest('li').siblings('.manual').find('.input').hide(); |
|
986 |
} |
|
987 |
}); |
|
988 |
|
|
989 |
$('.trigger-radiobtn').click(function(e) { |
|
990 |
$(this).find('.radiobtn').trigger('click'); |
|
991 |
}); |
|
992 |
|
|
993 |
$('.firewall .more .radiobtn').click(function(e){ |
|
994 |
$(this).parents('.firewall').removeAttr('data-firewall'); |
|
995 |
$(this).parents('.firewall').data('firewall', $(this).parent().attr('class')); |
|
996 |
ui.firewallSetup(); |
|
997 |
}); |
|
998 |
|
|
999 |
}); |
|
1000 |
;/* |
|
1001 |
* functions regarding all wizards |
|
1002 |
*/ |
|
1003 |
|
|
1004 |
ui.wizard = { |
|
1005 |
domID: undefined, |
|
1006 |
currentStep: undefined, |
|
1007 |
totalStep: undefined, |
|
1008 |
btns: { |
|
1009 |
start: undefined, |
|
1010 |
close: undefined, |
|
1011 |
next: undefined, |
|
1012 |
previous: undefined, |
|
1013 |
}, |
|
1014 |
areas : { |
|
1015 |
top: { |
|
1016 |
header: undefined, |
|
1017 |
menu: undefined |
|
1018 |
}, |
|
1019 |
middle: undefined, |
|
1020 |
bottom: undefined |
|
1021 |
}, |
|
1022 |
speed: 500, |
|
1023 |
onMove: 0, |
|
1024 |
|
|
1025 |
getCurrentStep: function(){ |
|
1026 |
return ui.wizard.domID.find('.step').filter('.current').first(); |
|
1027 |
}, |
|
1028 |
|
|
1029 |
getNextStep: function() { |
|
1030 |
return ui.wizard.getCurrentStep().next(); |
|
1031 |
}, |
|
1032 |
|
|
1033 |
getPreviousStep: function() { |
|
1034 |
return ui.wizard.getCurrentStep().prev(); |
|
1035 |
}, |
|
1036 |
|
|
1037 |
getScrollOffset: function() { |
|
1038 |
return document.body.scrollTop; |
|
1039 |
}, |
|
1040 |
|
|
1041 |
submitData: function() { |
|
1042 |
console.log('submit data dummy function'); |
|
1043 |
}, |
|
1044 |
|
|
1045 |
|
|
1046 |
|
|
1047 |
move: function(stepToDisplay, pos) { |
|
1048 |
ui.wizard.onMove = 1; |
|
1049 |
ui.wizard.focusFun(); |
|
1050 |
ui.wizard.indicateStep(); |
|
1051 |
ui.wizard.setMovementTags(); |
|
1052 |
$('body').css('overflow','hidden'); |
|
1053 |
// the current visible pane |
|
1054 |
var current = this.getCurrentStep(); |
|
1055 |
// Set next pane position on the right of the current one |
|
1056 |
// Add current to the next pane, so that it will become |
|
1057 |
// visible |
|
1058 |
stepToDisplay.css({ |
|
1059 |
left: pos.toString() + '%' |
|
1060 |
}).addClass("current"); |
|
1061 |
// identify the current scroll position. Use it to |
|
1062 |
// set next pane top position. We assume all panes |
|
1063 |
// are within the scroll context of the main window. |
|
1064 |
stepToDisplay.css({ |
|
1065 |
top: this.getScrollOffset() + 'px' |
|
1066 |
}); |
|
1067 |
ui.wizard.domID.find('.step').animate({ |
|
1068 |
marginLeft: (-pos).toString() + '%' |
|
1069 |
}, { |
|
1070 |
complete: _.bind(function() { |
|
1071 |
// assuming all the following take place |
|
1072 |
// instantaneously within a single browser |
|
1073 |
// render cycle, no flickering should occur. |
|
1074 |
current.removeClass("current"); |
|
1075 |
window.scroll(0, 0); |
|
1076 |
stepToDisplay.css({ |
|
1077 |
left: '0', |
|
1078 |
top: '0' |
|
1079 |
}); |
|
1080 |
$('.step').css({ |
|
1081 |
marginLeft: '0' |
|
1082 |
}); |
|
1083 |
$('body').css('overflow','visible'); |
|
1084 |
if (ui.wizard.currentStep == 3 ){ |
|
1085 |
$('.vm-name input').first().focus(); |
|
1086 |
} |
|
1087 |
$('.actions-bar').show(); |
|
1088 |
ui.wizard.onMove = 0; |
|
1089 |
}, this) |
|
1090 |
}); |
|
1091 |
|
|
1092 |
}, |
|
1093 |
|
|
1094 |
data_next_array: ['el0', 'el2', 'el4', 'el7'], |
|
1095 |
|
|
1096 |
focusFun: function() { |
|
1097 |
var step = ui.wizard.currentStep; |
|
1098 |
var nextBtn = ui.wizard.btns.next; |
|
1099 |
|
|
1100 |
$('.firstfocus-' + step + '').first().focus(); |
|
1101 |
nextBtn.removeAttr('data-next'); |
|
1102 |
nextBtn.attr('data-next', ui.wizard.data_next_array[step]); |
|
1103 |
}, |
|
1104 |
|
|
1105 |
goNext: function() { |
|
1106 |
var next = ui.wizard.getNextStep(); |
|
1107 |
if (ui.wizard.onMove == 0) { |
|
1108 |
ui.wizard.currentStep++; |
|
1109 |
ui.wizard.move(next, 100); |
|
1110 |
} |
|
1111 |
}, |
|
1112 |
|
|
1113 |
goPrev: function() { |
|
1114 |
var prev = ui.wizard.getPreviousStep(); |
|
1115 |
if (ui.wizard.onMove == 0) { |
|
1116 |
ui.wizard.currentStep--; |
|
1117 |
ui.wizard.move(prev, -100); |
|
1118 |
} |
|
1119 |
}, |
|
1120 |
|
|
1121 |
indicateStep: function() { |
|
1122 |
var step =ui.wizard.currentStep; |
|
1123 |
var menus = ui.wizard.areas.top.menu; |
|
1124 |
var wizardHeader = ui.wizard.areas.top.header; |
|
1125 |
|
|
1126 |
menus.find('.sub-menu').hide(); |
|
1127 |
menus.find('.sub-menu[data-step='+step+']').fadeIn(); |
|
1128 |
wizardHeader.children().removeClass('current'); |
|
1129 |
wizardHeader.find('li:not(".current")').show().css("display", "inline"); |
|
1130 |
wizardHeader.find('li:nth-child(' + step + ')').addClass('current'); |
|
1131 |
wizardHeader.find('li.current').hide(); |
|
1132 |
wizardHeader.find('li.current').fadeIn('slow').css("display", "inline"); |
|
1133 |
wizardHeader.find('.current').prevAll('li').hide(); |
|
1134 |
}, |
|
1135 |
|
|
1136 |
// changes the text of next and previous buttons |
|
1137 |
setMovementTags: function() { |
|
1138 |
var step = ui.wizard.currentStep; |
|
1139 |
var totalStep = ui.wizard.totalStep; |
|
1140 |
var prevBtnLabel = ui.wizard.btns.previous.find('span'); |
|
1141 |
var nextBtnLabel = ui.wizard.btns.next.find('span'); |
|
1142 |
|
|
1143 |
if(totalStep == 1) { |
|
1144 |
prevBtnLabel.html('CANCEL'); |
|
1145 |
nextBtnLabel.html('CREATE'); |
|
1146 |
} |
|
1147 |
else { |
|
1148 |
if (step == 1) { |
|
1149 |
prevBtnLabel.html('CANCEL'); |
|
1150 |
nextBtnLabel.html('NEXT'); |
|
1151 |
} else if (step == totalStep) { |
|
1152 |
prevBtnLabel.html('PREVIOUS'); |
|
1153 |
nextBtnLabel.html('CREATE'); |
|
1154 |
} else if (ui.wizard.vm.hideNext()){ |
|
1155 |
// *** |
|
1156 |
ui.wizard.btns.next.hide(); |
|
1157 |
} else { |
|
1158 |
prevBtnLabel.html('PREVIOUS'); |
|
1159 |
nextBtnLabel.html('NEXT'); |
|
1160 |
} |
|
1161 |
} |
|
1162 |
}, |
|
1163 |
close: function() { |
|
1164 |
console.log('1'); |
|
1165 |
$('body').removeClass('with-overlay'); |
|
1166 |
$('.overlay-area-custom').fadeOut(400, function() { |
|
1167 |
$('.overlay-div').hide(); |
|
1168 |
ui.wizard.reset(); |
|
1169 |
}); |
|
1170 |
}, |
|
1171 |
|
|
1172 |
reset: function() { |
|
1173 |
var wizard = ui.wizard.domID; |
|
1174 |
var wizardType = wizard.attr('id'); |
|
1175 |
|
|
1176 |
if(wizardType == 'vm-wizard') { |
|
1177 |
wizard.find('.networks-area .more').show(); |
|
1178 |
wizard.find('.details').hide(); |
|
1179 |
wizard.find('.os li').hide(); |
|
1180 |
wizard.find('.advanced-conf-options').hide(); |
|
1181 |
wizard.find('.snf-color-picker').hide(); |
|
1182 |
|
|
1183 |
} |
|
1184 |
else if(wizardType == 'network-wizard') { |
|
1185 |
wizard.find('li .manual .input').hide(); |
|
1186 |
wizard.find('ul.subnet-options').parent('li').show(); |
|
1187 |
} |
|
1188 |
|
|
1189 |
ui.wizard.currentStep = 1; |
|
1190 |
wizard.find('.step').removeAttr('style'); |
|
1191 |
wizard.find('.bottom').show(); |
|
1192 |
wizard.find('input').val(''); |
|
1193 |
ui.wizard.indicateStep(); |
|
1194 |
ui.wizard.setMovementTags(); |
|
1195 |
ui.wizard.preselectElements(wizardType); |
|
1196 |
}, |
|
1197 |
|
|
1198 |
preselectElements: function(wizardType) { |
|
1199 |
var wizard = ui.wizard.domID; |
|
1200 |
|
|
1201 |
wizard.find('.current').not('.preselected').removeClass('current'); |
|
1202 |
wizard.find('.preselected').not('.current').addClass('current'); |
|
1203 |
wizard.find('.custom.dropdown.medium a:first').addClass('current'); // to fix |
|
1204 |
ui.radiobtn.reset(wizard); |
|
1205 |
ui.checkbox.reset(wizard); |
|
1206 |
wizard.find('.snf-arrow-up.preselected').toggleClass('snf-arrow-up snf-arrow-down'); |
|
1207 |
if(wizardType == 'vm-wizard') { |
|
1208 |
var preselectedImgCategory = wizard.find('.top .sub-menu[data-step=1] .preselected').data('img-type'); |
|
1209 |
wizard.find('.os .'+preselectedImgCategory).show(); |
|
1210 |
} |
|
1211 |
}, |
|
1212 |
|
|
1213 |
// use the showExplanatory and hideExplanatory functions |
|
1214 |
// when there's html structure as the following: |
|
1215 |
// <div class="title"> |
|
1216 |
// <p>EXPLANATORY TEXT</p> |
|
1217 |
// </div> |
|
1218 |
// <div class="options-bar"> |
|
1219 |
// <div> |
|
1220 |
// <a href="">link</a>< |
|
1221 |
// </div> |
|
1222 |
// </div> |
|
1223 |
showExplanatoryText: function(link) { |
|
1224 |
var paragraph = $(link).parents('.options-bar').siblings('.title').find('p'); |
|
1225 |
// var text = $(link).data('help'); |
|
1226 |
// paragraph.html(text); |
|
1227 |
paragraph.css('visibility', 'visible'); |
|
1228 |
}, |
|
1229 |
|
|
1230 |
hideExplanatoryText: function(link) { |
|
1231 |
var paragraph = $(link).parents('.options-bar').siblings('.title').find('p'); |
|
1232 |
paragraph.css('visibility', 'hidden'); |
|
1233 |
}, |
|
1234 |
|
|
1235 |
vm: { |
|
1236 |
hideNext: function() { |
|
1237 |
if(ui.wizard.currentStep == 2 && $('.flavor a.disabled').hasClass('small')) { |
|
1238 |
return true; |
|
1239 |
} |
|
1240 |
else { |
|
1241 |
return false; |
|
1242 |
} |
|
1243 |
}, |
|
1244 |
getSize: function(elem) { |
|
1245 |
if ($(elem).hasClass('small')) { |
|
1246 |
return 'small'; |
|
1247 |
} else if ($(elem).hasClass('medium')) { |
|
1248 |
return 'medium'; |
|
1249 |
} else if ($(elem).hasClass('large')) { |
|
1250 |
return 'large'; |
|
1251 |
} |
|
1252 |
}, |
|
1253 |
|
|
1254 |
|
|
1255 |
pickResources: function(resource) { |
|
1256 |
var wizard = ui.wizard.domID; |
|
1257 |
wizard.find('.flavor .with-flavor a:not(.' + resource + ')').removeClass('current'); |
|
1258 |
wizard.find('.flavor .with-flavor a.' + resource + '').addClass('current'); |
|
1259 |
}, |
|
1260 |
|
|
1261 |
showImageCategory: function(imagesCategory) { |
|
1262 |
var wizard = ui.wizard.domID; |
|
1263 |
var selectedImages = $(imagesCategory).data('img-type'); |
|
1264 |
wizard.find(imagesCategory).closest('.sub-menu').find('.current').removeClass('current'); |
|
1265 |
wizard.find(imagesCategory).addClass('current'); |
|
1266 |
wizard.find('.os li').hide(); |
|
1267 |
wizard.find('.os .details').hide(); |
|
1268 |
wizard.find('.os').find('.'+selectedImages).fadeIn(); |
|
1269 |
} |
|
1270 |
}, |
|
1271 |
network : { } |
|
1272 |
} |
|
1273 |
|
|
1274 |
$(document).ready(function() { |
|
1275 |
|
|
1276 |
if($('.wizard').length>0) { |
|
1277 |
var wizardType = $('.wizard').attr('id'); |
|
1278 |
var wizard = ui.wizard.domID =$('#'+wizardType); |
|
1279 |
ui.wizard.totalStep = ui.wizard.domID.find('.step').length; |
|
1280 |
ui.wizard.currentStep = 1; |
|
1281 |
var topHeaderArea = ui.wizard.areas.top.header = wizard.find('.top .nums'); |
|
1282 |
var topMenuArea = ui.wizard.areas.top.menu = wizard.find('.top .menus'); |
|
1283 |
var middleArea = ui.wizard.areas.middle = wizard.find('.middle'); |
|
1284 |
var bottomArea = ui.wizard.areas.bottom = wizard.find('.bottom'); |
|
1285 |
|
|
1286 |
var prevBtn = ui.wizard.btns.previous = ui.wizard.areas.bottom.find('.nav.prev'); |
|
1287 |
var nextBtn = ui.wizard.btns.next = ui.wizard.areas.bottom.find('.nav.next'); |
|
1288 |
var closeBtn = ui.wizard.btns.close = wizard.find('.close'); |
|
1289 |
|
|
1290 |
// various functions for creation wizards |
|
1291 |
closeBtn.click(function(e) { |
|
1292 |
e.preventDefault(); |
|
1293 |
ui.wizard.close(); |
|
1294 |
}); |
|
1295 |
|
|
1296 |
nextBtn.click(function(e) { |
|
1297 |
e.preventDefault(); |
|
1298 |
if (ui.wizard.currentStep == ui.wizard.totalStep ){ |
|
1299 |
ui.wizard.submitData(); |
|
1300 |
ui.wizard.close(); |
|
1301 |
return false; |
|
1302 |
} |
|
1303 |
ui.wizard.goNext(); |
|
1304 |
|
|
1305 |
}); |
|
1306 |
|
|
1307 |
prevBtn.click(function(e) { |
|
1308 |
e.preventDefault(); |
|
1309 |
if (ui.wizard.currentStep == 1 ){ |
|
1310 |
ui.wizard.close(); |
|
1311 |
return false; |
|
1312 |
} |
|
1313 |
ui.wizard.goPrev(); |
|
1314 |
}); |
|
1315 |
|
|
1316 |
|
|
1317 |
$(document).keydown(function(e) { |
|
1318 |
var exp1 = $('.vm-name input').is(':focus') && $('.vm-name input').val().length>0; |
|
1319 |
var exp2 = $('.form-item input').is(':focus') && $('.form-item input').val().length>0; |
|
1320 |
// right arrow keyCode == 39 |
|
1321 |
if (wizard.is(':visible').length != 0) { |
|
1322 |
if (e.keyCode == 39 && ui.wizard.currentStep != (ui.wizard.totalStep) &&(!exp1) && (!exp2)) { |
|
1323 |
ui.wizard.goNext(); |
|
1324 |
return false; |
|
1325 |
} |
|
1326 |
// left arrow keyCode == 37 |
|
1327 |
else if (e.keyCode == 37 && ui.wizard.currentStep != 1 &&(!exp1) &&(!exp2)) { |
|
1328 |
ui.wizard.goPrev(); |
|
1329 |
return false; |
|
1330 |
} |
|
1331 |
// ESC |
|
1332 |
else if (e.keyCode == 27 && ui.wizard.currentStep == 1) { |
|
1333 |
ui.wizard.close(); |
|
1334 |
} |
|
1335 |
} |
|
1336 |
}); |
|
1337 |
|
|
1338 |
// focus and tabs functionality |
|
1339 |
wizard.find('a').keyup(function(e) { |
|
1340 |
var self = this; |
|
1341 |
if (e.keyCode == 9 || e.which == 9) { |
|
1342 |
if (e.shiftKey) { |
|
1343 |
} else { |
|
1344 |
//Focus next input |
|
1345 |
if ($(self).attr('data-next')) { |
|
1346 |
$(self).focusout(function(e) { |
|
1347 |
var classname = $(self).data('next'); |
|
1348 |
wizard.find('.' + classname + '').first().focus(); |
|
1349 |
}); |
|
1350 |
} |
|
1351 |
} |
|
1352 |
} |
|
1353 |
}); |
|
1354 |
|
|
1355 |
// navigation and numbers functions |
|
1356 |
wizard.find('.nav.previous').focus(function(e) { |
|
1357 |
$(this).addClass('active'); |
|
1358 |
}); |
|
1359 |
|
|
1360 |
wizard.find('.nav.previous').focusout(function(e) { |
|
1361 |
$(this).removeClass('active'); |
|
1362 |
|
|
1363 |
}); |
|
1364 |
|
|
1365 |
if(wizardType == 'vm-wizard') { |
|
1366 |
|
|
1367 |
// step-1: pick OS |
|
1368 |
wizard.find('.os > li').keydown(function(e) { |
|
1369 |
if(e.keyCode == 13) { |
|
1370 |
$(this).trigger("click", true); |
|
1371 |
e.preventDefault(); |
|
1372 |
} |
|
1373 |
}); |
|
1374 |
wizard.find('.os .btn-col a').keydown(function(e) { |
|
1375 |
if(e.keyCode == 13) { |
|
1376 |
$(this).trigger("click", true); |
|
1377 |
e.preventDefault(); |
|
1378 |
e.stopPropagation(); |
|
1379 |
} |
|
1380 |
}); |
|
1381 |
|
|
1382 |
wizard.find('.os > li').click(function(e, wasEnterKey) { |
|
1383 |
e.preventDefault(); |
|
1384 |
if ( $(this).hasClass('current') && wasEnterKey) { |
|
1385 |
ui.wizard.goNext(); |
|
1386 |
} |
|
1387 |
wizard.find('.os >li').removeClass('current'); |
|
1388 |
$(this).addClass('current'); |
|
1389 |
}); |
|
1390 |
|
|
1391 |
wizard.find('.os .btn-col a').click(function(e) { |
|
1392 |
e.preventDefault(); |
|
1393 |
e.stopPropagation(); |
|
1394 |
$(this).toggleClass('current'); |
|
1395 |
var self = this; |
|
1396 |
$(this).parents('li').find('.details').stop().slideToggle(); |
|
1397 |
}); |
|
1398 |
|
|
1399 |
wizard.find('.top .sub-menu[data-step=1] a').click(function(e) { |
|
1400 |
e.preventDefault(); |
|
1401 |
ui.wizard.vm.showImageCategory(this); |
|
1402 |
}); |
|
1403 |
|
|
1404 |
wizard.find('.os .name-col').focus(function(e) { |
|
1405 |
$(this).parents('li').addClass('hover'); |
|
1406 |
}); |
|
1407 |
|
|
1408 |
wizard.find('.os .name-col').focusout(function(e) { |
|
1409 |
$(this).parents('li').removeClass('hover'); |
|
1410 |
}); |
|
1411 |
|
|
1412 |
// step-2: pick flavor |
|
1413 |
var disabledElems = wizard.find('.flavor a.disabled'); |
|
1414 |
var disabledElemsNum = disabledElems.length; |
|
1415 |
var size; |
|
1416 |
if(disabledElemsNum>0) { |
|
1417 |
for(i=0; i<disabledElemsNum; i++) { |
|
1418 |
size = ui.wizard.vm.getSize(disabledElems.get(i)); |
|
1419 |
wizard.find('.sub-menu[data-step=2] a[data-size=' + size + ']').removeClass('current').addClass('disabled'); |
|
1420 |
wizard.find('.flavor .'+size).removeClass('current preselected'); |
|
1421 |
if(size == 'small') { |
|
1422 |
wizard.find('.flavor .vm-storage-selection a').removeClass('current preselected'); |
|
1423 |
|
|
1424 |
} |
|
1425 |
} |
|
1426 |
} |
|
1427 |
wizard.find('.sub-menu a[data-size]:not(.disabled)').click(function(e) { |
|
1428 |
e.preventDefault(); |
|
1429 |
$(this).parents('.sub-menu').find('a').removeClass('current'); |
|
1430 |
$(this).addClass('current'); |
|
1431 |
ui.wizard.vm.pickResources($(this).data('size')); |
|
1432 |
}); |
|
1433 |
|
|
1434 |
wizard.find('.flavor .options:not(.vm-storage-selection) a:not(.disabled)').click(function(e) { |
|
1435 |
e.preventDefault(); |
|
1436 |
wizard.find('.sub-menu a[data-size]').removeClass('current'); |
|
1437 |
$(this).parents('.options').find('a').removeClass('current'); |
|
1438 |
$(this).addClass('current'); |
|
1439 |
size = ui.wizard.vm.getSize(this); |
|
1440 |
var count = wizard.find('.options.with-flavor .' + size + '.current').length; |
|
1441 |
if (count == 3) { |
|
1442 |
wizard.find('.sub-menu[data-step=2] a[data-size=' + size + ']').addClass('current'); |
|
1443 |
} |
|
1444 |
}); |
|
1445 |
|
|
1446 |
wizard.find('.flavor .options.vm-storage-selection a').click(function(e) { |
|
1447 |
e.preventDefault(); |
|
1448 |
$(this).parents('.options').find('a').removeClass('current'); |
|
1449 |
$(this).addClass('current'); |
|
1450 |
}); |
|
1451 |
|
|
1452 |
wizard.find('.flavor .options a').hover( |
|
1453 |
function() { |
|
1454 |
ui.wizard.showExplanatoryText($(this)) |
|
1455 |
}, function() { |
|
1456 |
ui.wizard.hideExplanatoryText($(this)) |
|
1457 |
}); |
|
1458 |
|
|
1459 |
wizard.find('.sub-menu[data-step=2] li:last').find('a').focusout(function(e) { |
|
1460 |
$('.step-2').find('.dropdown a:first').focus(); |
|
1461 |
}); |
|
1462 |
|
|
1463 |
// step-3: custom options |
|
1464 |
wizard.find('.expand-arrow').click(function(e) { |
|
1465 |
e.preventDefault(); |
|
1466 |
ui.expandDownArea(this, wizard.find('.advanced-conf-options')); |
|
1467 |
}); |
|
1468 |
} |
|
1469 |
|
|
1470 |
else if (wizardType == 'volume-wizard') { |
|
1471 |
// step-1 |
|
1472 |
wizard.find('.volume_options .options a').hover( |
|
1473 |
function() { |
|
1474 |
ui.wizard.showExplanatoryText($(this)) |
|
1475 |
}, function() { |
|
1476 |
ui.wizard.hideExplanatoryText($(this)) |
|
1477 |
}); |
|
1478 |
wizard.find('.volume_options .options a:not(.disabled)').click(function(e) { |
|
1479 |
e.preventDefault(); |
|
1480 |
if(!$(this).hasClass('current')) { |
|
1481 |
$(this).closest('.options').find('.current').removeClass('current'); |
|
1482 |
$(this).addClass('current'); |
|
1483 |
} |
|
1484 |
}); |
|
1485 |
} |
|
1486 |
|
|
1487 |
} |
|
1488 |
|
|
1489 |
}) |
Also available in: Unified diff