Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / common.js @ e4a6c3b8

History | View | Annotate | Download (25.9 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
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
}
469

    
470
function bytesToSize(bytes) {
471
    var sizes = [ 'n/a', 'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
472
    var i = +Math.floor(Math.log(bytes) / Math.log(1024));
473
    return  (bytes / Math.pow(1024, i)).toFixed( 0 ) + sizes[ isNaN( bytes ) ? 0 : i+1 ];
474
}
475
function date_ddmmmyytime(date)
476
{
477
  var d = date.getDate();
478
  var m = date.getMonth();
479
  var y = date.getYear();
480
  if(y >= 100)
481
  {
482
    y -= 100;
483
    y += 2000;
484
  }
485

    
486
    var curr_hour = date.getHours();
487

    
488
    if (curr_hour < 12){
489
        a_p = "am";
490
    } else {
491
       a_p = "pm";
492
    }
493

    
494
    if (curr_hour == 0) {
495
       curr_hour = 12;
496
    }
497
    if (curr_hour > 12){
498
       curr_hour = curr_hour - 12;
499
    }
500

    
501
    var curr_min = date.getMinutes();
502

    
503
  return "" +
504
    (d<10?"0"+d:d) + "/" +m + "/" + y + ' '+curr_hour + ":" + curr_min + a_p;
505
}
506

    
507
 // returns the file class/extension of a file
508
ui.mimeToExt = function( mimetype) {
509
  var mimeExt = {
510
    'image/jpeg': 'jpg',
511
    'image/png': 'png',
512
    'application/pdf': 'pdf',
513
    'text/plain': 'txt',
514
  };
515
  console.log(mimetype);
516
  return mimeExt[mimetype] || 'unknown';
517
}
518

    
519
$(document).ready(function(){
520

    
521
    $('html').click(function(e) {
522
        // not sure if we want to hide the error window after every click in the ui
523
        if($('.communication-error').css('bottom') == '0px') {
524
            $('.communication-error').animate({bottom: "-151px"});
525
        }
526
    });
527

    
528
    if($('.vms.entities').length!=0){
529
        ui.inactiveActions();
530
    };
531
    ui.setElminHeight($('.main > .details'));
532
    ui.setElminHeight($('.lt-bar'));
533
    ui.setElmaxHeight($('.storage-progress'));
534
    ui.setElHeight($('.scroll-wrap'));
535
    $('#hd-search .hd-icon-search').click(function(e){
536
        var that = this;
537
        $(this).parents('.hd-search').toggleClass('hd-open');
538
        if ($(this).parents('.hd-search').hasClass('hd-open')) {
539
            $(that).parents('.hd-search').find('input[type="search"]').focus();
540
        } else {
541
            $(that).parents('.hd-search').find('input[type="search"]').val('');
542
        }
543
    })
544

    
545
    $('.header .login').mouseenter(function(e){
546
        $(this).find('ul').stop(true, true).slideDown(200);
547
    });
548
    $('.header .login').mouseleave(function(e){
549
        $(this).find('ul').stop(true, true).slideUp(200);
550
    });
551

    
552
    $('.entities a').click(function(){
553
        if ($(this).attr('data-reveal-id') && !($(this).hasClass('inactive'))) {
554
            $('.entities li .more').hide();
555
        }
556
    });
557

    
558
    $('.inactive').click(function(e){
559
        e.stopPropagation();
560
        e.preventDefault();
561
     });
562

    
563
    $('.arrows').on('click','.inactive', function(e){
564
        e.preventDefault();
565
        e.stopPropagation();
566
    });
567

    
568

    
569
    $('.lt-actions a:not(.active)').click(function(e){
570
        e.preventDefault();
571
    })
572

    
573
    if ($('.entities .items-list >li').length == 1) {
574
        $('.body-wrapper').addClass('no-vm');
575
    };
576
    $('.entities li .more').each(function(){
577
        var width = $(this).parent('li').outerWidth()  + 20;
578
        $(this).css('width', width);
579
    });
580

    
581
    $('.items-list li .img-wrap').on("mouseenter", function(e) {
582
        var that = this;
583
        if ($(this).parents('.entities').hasClass('grid-view')) {
584
            if ($(that).parent('.container').siblings('.more').length>0) {
585
                $(that).parent('.container').fadeOut(50,'easeInCirc');
586
                $(that).parent('.container').siblings('.more').fadeIn(150,'easeInCirc');
587
            }
588
        }
589
    });
590
    $('.entities li .more').mouseleave(function(e) {
591
        $(this).fadeOut(50, function() {
592
            $(this).siblings('.container').fadeIn(50);
593
        });
594
    });
595
    $('.grid-view .items-list > li').mouseleave(function(e){
596
        var that = this;
597
        setTimeout(function(){
598
            $(that).find('.more').fadeOut(200, function() {
599
                $(this).siblings('.container').fadeIn('fast');
600
            });
601
        },50)
602
    });
603

    
604
    ui.closeDiv($('.info .close'), '.info');
605
    ui.editable();
606
    ui.overlay();
607
    ui.colorPickerVisible = 0;
608

    
609
    $("a.disabled").each(function() {
610
        $(this).removeAttr('href');
611
    });
612
    
613
    $("a.disabled").click(function(e) {
614
        e.preventDefault();
615
    });
616

    
617
    $('.main-actions li a').click(function(e){
618
        if (!($(this).hasClass('active'))) {
619
            e.preventDefault();
620
        }
621
    });
622

    
623
    $('.main-actions li a').click(function(e){
624
        if (!($(this).hasClass('active'))) {
625
            e.preventDefault();
626
        }
627
    });
628
    $('.overlay-area-custom').children('.close').click(function(e){
629
        e.preventDefault();
630
        e.stopPropagation();
631
        $(this).parents('.overlay-area-custom').hide();
632
        $(this).parents('.overlay-area-custom').find($('.overlay-div')).hide();
633
        $('body').removeClass('with-overlay');
634
    })
635

    
636
    $('.browse-files').click(function(e){
637
        e.preventDefault();
638
    });
639

    
640
    if($('#picker-1').length>0) {
641
        $('#picker-1').farbtastic('#color-1');
642
    };
643
    if($('#picker-2').length>0) {
644
        $('#picker-2').farbtastic('#color-2');
645
    };
646
    if($('#sb-search').length>0) {
647
        new UISearch( document.getElementById( 'sb-search' ) );
648
    }
649

    
650
    if ($('.toggle-lt-bar').length>0) {
651
        ui.ltBarToggle(400);
652
    }
653

    
654
    /* grid/list view for items-list */
655

    
656
    $('.actions-bar .list, .actions-bar .grid').click(function(e){
657
        //e.preventDefault();
658
        /*if (!($(this).find('span').hasClass('current'))) {
659
            $('.actions-bar .grid span, .actions-bar .list span').removeClass('current');
660
            $(this).find('span').addClass('current');
661
            $('.entities').toggleClass('grid-view list-view');
662
        }*/
663
    });
664

    
665

    
666

    
667
    // set filter visible
668
    $('.filter-menu .filter').click(function(e) {
669
        e.preventDefault();
670
        $(this).parents('.filter-menu').toggleClass('current');
671
    });
672

    
673
    // temp function used to demonstrate the visual effect of the building state of vm
674
    $('[data-status="building"] .btn5.temp').click(function(e) {
675
        e.preventDefault();
676
        $(this).siblings('.container').find('.complete').toggleClass('build-progress');
677
    });
678

    
679
    $('[data-status="rebooting"] .btn5.temp').click(function(e) {
680
        e.preventDefault();
681
        $(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress');
682
    })
683

    
684
    // //temp function to preventDefault of links in modal
685
    // $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
686
    //     e.preventDefault();
687
    //     $('a.close-reveal-modal').trigger('click');
688
    // });
689

    
690
     // temp btn to show communication error message
691
    $('.temp-for-btns .communication-error-btn').click(function(e) {
692
         e.preventDefault();
693
         e.stopPropagation();
694
         $('.communication-error').animate({bottom: "0px"});
695
     });
696

    
697
    $('.communication-error a').click(function(e) {
698
        e.preventDefault();
699
        e.stopPropagation();
700
        $('.communication-error').animate({bottom: "-151px"});
701

    
702
    });
703
    $('.communication-error').click(function(e) {
704
        e.stopPropagation();
705
    });
706

    
707
    $('.show-add-tag').click(function(e) {
708
    e.preventDefault();
709
    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideDown('slow', function() {
710
        $('#hide-add-tag-dummy').scrollintoview({
711
            'duration': 'slow'
712
        });
713
    });
714
    ui.colorPickerVisible = 1;
715
    });
716

    
717
    $('.hide-add-tag').click(function(e) {
718
    e.preventDefault();
719
    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() {
720
        $('.show-add-tag').first().scrollintoview({
721
            'duration': 'slow'
722
        });
723
        ui.colorPickerVisible = 0;
724
    });
725
    });
726

    
727
    // connected details js
728
    ui.detailsCustom($('#disk-connected'));
729
    ui.detailsCustom($('#network-connected'));
730
    ui.detailsCustom($('#vm-connected'));
731
    ui.firewallSetup();
732

    
733
    $('.firewall').mouseenter(function(e){
734
        $(this).css('z-index',2);
735
        $(this).find('.more').stop(true, true).slideDown(200);
736
    });
737
    $('.firewall').mouseleave(function(e){
738
        $(this).css('z-index',1);
739
        $(this).find('.more').stop(true, true).slideUp(200);
740
    });
741
    //ui.tabs($('.tabs'), $('.content'));
742
    ui.hashTabs($('.tabs'), $('.content'));
743
    ui.hashViews($('.actions-bar .rt-actions'), $('.entities'));
744

    
745
    $('.act').click(function(e) {
746
        $(this).addClass('pending last');
747
    });
748

    
749
    $('.remove .cancel').click(function(e) {
750
        e.preventDefault();
751
        $('a.close-reveal-modal').trigger('click');
752
        $('.last').removeClass('pending last');
753
    });
754

    
755
    $('.remove .ok').click(function(e) {
756
        e.preventDefault();
757
        $('a.close-reveal-modal').trigger('click');
758
        var connection_img = $('.connections').find('.last');
759
        connection_img.addClass('open', 0);
760
        connection_img.removeClass('last');
761
        var img = connection_img.closest('.item').find('.img-wrap .snf-font');
762
        img.addClass('reboot-progress');
763
        setTimeout(function() {
764
            var connections_list = connection_img.closest('.connections').children('li:not(".hidden")');
765
            if(connections_list.length>1) {
766
                connection_img.closest('li').slideUp(function(){
767
                    connection_img.closest('li').addClass('hidden');
768
                    if(connections_list.find('.pending').length == 0) {
769
                      img.removeClass('reboot-progress');
770
                    }
771
                });
772
            }
773
            else {
774
                connection_img.closest('.item').slideUp(function(){
775
                    img.closest('li').addClass('hidden');
776
                    img.removeClass('reboot-progress');
777
                    img.removeClass('reboot-progress');
778
                });
779
            }
780
            connection_img.removeClass('pending');
781
        }, 3000)
782
    });
783
    // end of connected details js
784

    
785
    ui.replaceClass($('a.current, a.active'), 'outline', 'full', 'snf-');
786

    
787
    $('.tag-data').mouseover(function() {
788
        $(this).find('.delete').css({visibility: 'visible'})
789
    });
790
    $('.tag-data').mouseleave(function(){
791
        $(this).find('.delete').css({visibility: 'hidden'})
792
    });
793
    $('.tag-data .delete').click(function(e) {
794
        e.preventDefault();
795
        $(this).closest('div').fadeOut('slow');
796
    });
797

    
798
    $('.storage-progress').hover(
799
        function(e){
800
            $(this).find('.details').stop(false,true).slideDown();
801
        },
802
        function(e){
803
            $(this).find('.details').stop(false,true).slideUp();
804
        }
805
    );
806

    
807
    $('.btn-more').mouseenter(function(e) {
808
        $(this).find('.explain').stop(true, true).show('slow');
809
    });
810

    
811
    $('.btn-more').click(function(e) {
812
        e.preventDefault();
813
        e.stopPropagation();
814
        $('.btn-more').removeClass('clicked');
815
        $('.btn-more').siblings('ul').hide();
816
        $(this).addClass('clicked');
817
        $(this).siblings('ul').stop(true, true).slideDown('slow');
818
    });
819
    $('.containers .project').mouseleave(function(e){
820
        $(this).find('ul').fadeOut();
821
        $(this).find('.btn-more').removeClass('clicked');
822
    })
823

    
824
    if ($('.containers .btn-more').length>0) {
825
        $('body').click(function(e){
826
            $('.btn-more').removeClass('clicked');
827
            $('.btn-more').siblings('ul').fadeOut();
828
        })
829
    }
830

    
831
    // add a <span> element inside the content of each a.wrap-a element
832
    $('a.wrap-a').wrapInner('<span></span>');
833

    
834

    
835
    $('.side-actions .bottom .reassign').click(function(e){
836
        e.preventDefault();
837
        $(this).parents('.bottom').find('ul').hide();
838
        $(this).parents('.bottom').find('ul.options').show();
839
    });
840

    
841
    $('.side-actions ul.options').mouseleave(function(e){
842
        $(this).hide();
843
        $(this).siblings('ul').removeAttr('style');
844
    })
845

    
846
})
847

    
848

    
849
$(window).resize(function(e){
850
    ui.setElminHeight($('.main > .details'));
851
    ui.setElminHeight($('.lt-bar'));
852
    ui.setElHeight($('.scroll-wrap'));
853
    ui.setCustomScrollBar();
854
    ui.setElmaxHeight($('.storage-progress'));
855

    
856
})