Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (26.1 kB)

1
/*
2
* Various functions that will be used throughout all templates
3
* are inside ui Object
4
*/
5

    
6
ui = {};
7
/*
8
* ui.wizards get populated in vm-wizard.js
9
* here is the declaration only
10
*/
11
ui.wizard = {};
12

    
13
/* when closeEl el is clicked, its parent with class divToCloseClass slidesUp */
14
ui.closeDiv = function(closeEl, divToCloseClass) {
15
    closeEl.click(function(e){
16
        e.preventDefault();
17
        $(this).parents(divToCloseClass).slideUp('slow');
18
    });
19
}
20

    
21

    
22
ui.trimChars = function( str, chars) {
23
    if ( str.length>chars){
24
        return $.trim(str).substring(0, chars)+ "...";
25
    } else {
26
        return str;
27
    }
28
}
29

    
30

    
31
/* Sets element min-height
32
* Used for .details, .lt-bar divs
33
*/
34
ui.setElminHeight = function(el){
35
    var WindowHeight = $(window).height();
36
    var header = $('.header').outerHeight();
37
    var actions = $('.actions-bar').height();
38
    var h1= WindowHeight - (header+actions);
39
    el.css('min-height', h1);
40
}
41

    
42
/* Sets element height
43
* Used for .details, .lt-bar divs
44
*/
45
ui.setElHeight = function(el){
46
    var WindowHeight = $(window).height();
47
    var header = $('.header').outerHeight();
48
    var actions = $('.actions-bar').height();
49
    var h1= WindowHeight - (header+actions);
50
    el.css('height', h1);
51
}
52

    
53
/* 
54
* Logic for Entities actions. Present in items_list pages
55
* Available categories are :
56
*  - both/single ( for multiple entities/single entities)
57
*  - running/off ( for running/off entities)
58
*  - permanent ( for entities always active )
59
* Can be used for pithos as well
60
* Available categories are :
61
* - files ( for files only actions)
62
* - folders ( for folders only actions)
63
* - all ( for files/folders actions)
64
*/
65
ui.entitiesActionsEnabled = function(){
66
    var all = $('.snf-checkbox-checked').length;
67
    var running = $('.snf-checkbox-checked').parents('li.running').length;
68
    var off = $('.snf-checkbox-checked').parents('li.off').length;
69
    var files = $('.snf-checkbox-checked').parents('li.file').length;
70
    var folders = $('.snf-checkbox-checked').parents('li.folder').length;
71

    
72
    console.log(files,'files');
73
    console.log(folders,'folders');
74

    
75
    $('.lt-bar .lt-actions li:not(.permanent) a').removeClass('active');
76

    
77
    if ( ( files * folders )>0 ) {
78
        $('.lt-actions li.all a').addClass('active');
79
    } else {
80
        if ( files>0 ) {
81
            $('.lt-actions li.files a').addClass('active');
82
        }
83
        if ( folders>0 ){
84
            $('.lt-actions li.folders a').addClass('active');
85
        }
86
    }
87

    
88
    if ( (running*off) > 0 ){
89
         $('.lt-actions li.both a').addClass('active');
90
         $('.lt-actions li.single a').removeClass('active');
91
    } else {
92
        if (running > 0) {
93
            $('.lt-actions li.both a').addClass('active');
94
            $('.lt-actions li.running a').addClass('active');
95
        } else if (off>0) {
96
            $('.lt-actions li.both a').addClass('active');
97
            $('.lt-actions li.off a').addClass('active');
98
        }
99
        if ( all > 1 ) {
100
            $('.lt-actions li.single a').removeClass('active');
101
        }
102
    }
103
}
104

    
105
ui.inactiveActions = function() {
106

    
107
    // Availble actions: connect, reboot, shut, destroy, start
108
    // These actions will be DISABLED
109
    var statesActions ={
110
        'off'      : ['connect', 'reboot', 'shut'],
111
        'error'    : ['connect', 'reboot', 'shut', 'start'],
112
        'building' : ['reboot', 'start'],
113
        'running'  : ['start'],
114
        'rebooting': ['start'],
115
        'starting' : ['start'],
116
        'shutting' : ['connect', 'reboot', 'shut']
117
    } ;
118

    
119
    _.each (statesActions, function(val, key) {
120
        _.each(val, function(value) {
121
            var el = '.' + key + ' .' + value;
122
            $(el).addClass('inactive');
123
        });
124
    })
125
}
126

    
127
ui.detailsCustom = function(area) {
128
    // position last connected item
129
    var el = area.find('.item').last();
130
    // -2 is the border width;
131
    var moveY = el.find('.connections >li').last().outerHeight(true) - 2;
132
    el.css('top',moveY);
133
    el.css('marginTop', -moveY);
134
}
135

    
136
ui.firewallSetup = function(){
137
    $('.firewall').each(function(){
138
        $(this).removeClass('fully unprotected basic');
139
        $(this).addClass($(this).data('firewall'));
140
        if($(this).hasClass('unprotected')){
141
            $(this).find('p').first().find('em').html('off');
142
        } else {
143
            $(this).find('p').first().find('em').html('on');
144
        }
145
    });
146
}
147

    
148

    
149
/*
150
* In order for the editable value functionality to work, the html markup
151
* should be:
152
    <div class="editable">
153
        <span class="input-txt">editable value</span>
154
        <input type="text">
155
        <a href="#" class="edit">edit</a>
156
        <a href="#" class="save">save</a>
157
        <a href="#" class="cancel">cancel</a>
158
    </div>
159
*/
160
ui.editable = function(){
161

    
162
/*
163
* resetForm hides save and cancel buttons,
164
* text input and shows input-txt. resetForm does not alter
165
* input-txt content.
166
*/
167

    
168
    function resetForm(e, elem) {
169
        var el = elem.parents('.editable');
170
        el.find('input[type="text"]').hide();
171
        el.find('a.cancel, a.save').hide();
172
        el.find('a.edit, .input-txt').show();
173
    }
174

    
175
/* 
176
* showForm hides input-txt, shows save and cancel buttons and
177
* sets input value to input-txt content.
178
*/
179
    function showForm(e,elem) {
180
        e.stopPropagation(); 
181
        e.preventDefault();
182
        var el = elem.parents('.editable'); 
183
        el.find('input[type="text"]').val(el.find('.input-txt').html());
184
        el.find('input[type="text"]').show();
185
        el.find('a.cancel, a.save').show();
186
        elem.hide();
187
        el.find('.input-txt').hide();
188
    }
189

    
190
/*
191
setValue sets input-txt value to the input value.
192
Makes sure that the input value is not empty.
193
TODO:
194
Ajax request to submit form
195
*/
196

    
197
    function setValue(elem) {
198
        var el = elem.parents('.editable');
199
        if( el.find('input[type="text"]').val() ) {
200
            el.find('.input-txt').html(el.find('input[type="text"]').val());
201
        }
202
    }
203

    
204

    
205
    $('.editable .edit').click(function(e){
206
        showForm(e, $(this));
207
    })
208

    
209
    $('.editable .cancel').click(function(e){
210
        e.stopPropagation();
211
        e.preventDefault();
212
        resetForm(e, $(this));
213
    })
214

    
215
    $('.editable .save').click(function(e){
216
        e.stopPropagation();
217
        e.preventDefault();
218
        setValue($(this));
219
        resetForm(e, $(this));
220

    
221
    })
222

    
223

    
224
    $('.editable input[type="text"]').click(function(e){
225
        e.stopPropagation();
226
    })
227

    
228
    $('.editable input[type="text"]').keyup(function(e){
229
        if(e.keyCode == 13) { 
230
            setValue($(this));
231
            resetForm(e, $(this));
232
            
233
        }
234
    
235
    })
236

    
237
    $('html').click(function(e) {
238
        resetForm(e, $('.editable a.cancel'));
239
    });
240

    
241
}
242

    
243
/* TODO: better overlay functionality */
244
ui.overlay = function() {
245
    $('[data-overlay-id]').click(function(e){
246
        e.preventDefault();
247
        var el = $(this);
248
        var id = '#'+el.data('overlay-id');
249

    
250
        $('.overlay-area-custom').fadeIn(100);
251
        $('body').addClass('with-overlay');
252
        $(id).fadeIn('slow');
253
        if (id=='#network-wizard') {
254
            $(id).find('input').first().focus();
255
            return false;
256
        }
257
        $(id).find('a').first().focus();
258
    });
259
}
260

    
261
function goToByScroll(id){
262
      // Remove "link" from the ID
263
    id = id.replace("link", "");
264
      // Scroll
265
    $('html,body').animate({
266
        scrollTop: $("#"+id).offset().top},
267
        'slow');
268
}
269

    
270

    
271
/*
272
* functions concerning checkboxes and radiobuttons links
273
*/
274

    
275
ui.changeCheckboxState =function(checkbox_link) {
276
    $(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked');
277
    ui.entitiesActionsEnabled();
278
}
279

    
280
// to use the above functions use first the ui.checkOneRadioButton and then ui.changeRadiobuttonState
281
ui.checkOneRadioButton = function(radiobtn_link) {
282
    $(radiobtn_link).closest('ul').find('span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked');
283
}
284
ui.changeRadiobuttonState = function(radiobtn_link) {
285
    $(radiobtn_link).find('span.snf-radio-unchecked, span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked');
286
}
287

    
288

    
289

    
290
// toggle expand arrrow  and corresponding area
291
// todo: one function for all the areas we reveal
292
ui.expandDownArea = function(arrow_link, area) {
293
    var arrow_link = $(arrow_link);
294
    var area = $(area);
295
            arrow_link.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down');
296
            // $('.wizard-content').removeAttr('style');
297
            area.stop().slideToggle(600, function() {
298
                if (area.is(':visible')) {
299
                    arrow_link.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up');
300
                } else {
301
                    arrow_link.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down');
302
                }
303

    
304
            });
305
}
306

    
307

    
308
/* Tabs functionality
309
* tabsEl is the div/ul with the links to the sections and the sections that
310
* with toggle have class sectionEl.
311
* Markup needed is an href to each a with the id of the relative section.
312
*/
313

    
314
ui.tabsSection = function(link, sectionEl) {
315
    sectionEl.hide();
316
    var el = $(link.attr('href'));
317
    el.stop(true, true).show(0);
318
    el.css('opacity',0);
319
    ui.detailsCustom(el);
320
    el.animate({
321
        'opacity':1,
322
    }, 500)
323
}
324

    
325
ui.tabs = function(tabsEl, sectionEl) {
326
    var tabLink = tabsEl.find('a');
327
    ui.replaceClass(tabLink.find('.active'), 'outline', 'full', 'snf-');
328
    function href(a) {
329
        return a.attr('href');
330
    }
331
    tabLink.click(function(e){
332
        e.preventDefault();
333
        if ( $(this).hasClass('active')){
334
             return false;
335
        } else {
336
            window.location.hash = $(this).attr('href');
337
            ui.replaceClass($(this).parents(tabsEl).find('.active'), 'full', 'outline', 'snf-');
338
            $(this).parents(tabsEl).find('a').removeClass('active');
339
            $(this).addClass('active');
340
            ui.replaceClass($(this), 'outline', 'full', 'snf-');
341
            ui.tabsSection( $(this), sectionEl);
342
        }
343
    })
344
}
345

    
346
// the function replaces part of the class of a span that is placed inside an a element
347
// the class is a word with the form : firstSubStr+*+str1 and it will be converted to: firstSubStr+*+str2
348
// it must be uniquely recognized by the firstSubStr and the str1.
349

    
350
ui.replaceClass = function(elements, str1, str2, firstSubStr) {
351
    $.each($(elements), function() {
352
        var classOld = $(this).find('span').attr('class');
353
        var classNew;
354
        if(classOld != undefined && classOld.indexOf(str1) != -1) {
355
            if(classOld.indexOf(' ') == -1) {
356
                classNew = classOld.replace(str1, str2);
357
                $(this).find('.'+classOld).removeClass(classOld).addClass(classNew);
358
            }
359
            else {
360
                // the string starts with the firstSubStr and after the end of the word there's a space
361
                var expr1 = new RegExp('^'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g');
362

    
363
                // the word is between spaces
364
                var expr2 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g');
365

    
366
                // before the word there's at least one space and the string ends with this word
367
                var expr3 = new RegExp('(\\s+)'+firstSubStr+'+(\\S*)+'+str1+'$', 'g');
368

    
369
                // spaces all over the string
370
                var spacesExp = new RegExp('\\s+', 'g');
371

    
372
                if(classOld.match(expr1) != null) {
373
                    classToReplace = classOld.match(expr1);
374
                }
375
                else if(classOld.match(expr2) != null) {
376
                    classToReplace = classOld.match(expr2);
377
                }
378
                else if (classOld.match(expr3) != null) {
379
                    classToReplace = classOld.match(expr3);
380
                }
381
                classToReplace = classToReplace.toString().replace(spacesExp,"");
382
                classNew = classToReplace.replace(str1, str2);
383
                $(this).find('.'+classToReplace).removeClass(classToReplace).addClass(classNew);
384
            }
385
        }
386
    });
387
}
388

    
389
// in a page with tabs, allow navigation with hash tags
390
ui.hashTabs = function(tabsEl, sectionEl){
391
    var hash = window.location.hash;
392
    if ($(hash).length<=0){
393
        return;
394
    }
395
    tabsEl.find('a').removeClass('active');
396
    var link = tabsEl.find('a[href="'+hash+'"]');
397
    link.addClass('active');
398
    ui.tabsSection(link, sectionEl);
399

    
400
}
401

    
402
ui.ltBarToggle = function(speed){
403

    
404
    var cmarg = parseInt($('.lt-bar').width()) - parseInt($('.toggle-lt-bar').outerWidth(true));        
405
    var ctemp = cmarg / parseInt($('.lt-bar').width());
406
    var cvelocity = parseInt($('.lt-bar').width())/speed;
407
    var cdelay = parseInt($('.toggle-lt-bar').outerWidth(true))/cvelocity;
408

    
409
    $('.lt-bar').click(function(e) {
410
        e.stopPropagation();
411
    })
412
    $('.toggle-lt-bar').click(function(e){
413
        e.preventDefault();
414
        e.stopPropagation();
415
        var self =this;
416
        if($(this).hasClass('fix-position')) {
417
            var marg = parseInt($(self).css('marginLeft')) - cmarg;
418
            $(this).animate({
419
                'margin-left': marg,
420
            }, ctemp * speed, 'linear', function(){
421
                $(self).removeAttr('style');
422
                $(self).removeClass('fix-position');
423
            });
424
            $('.lt-bar').animate({
425
                width: 'toggle'
426
            }, speed, 'linear');
427
        }
428
        else {
429
            $(this).addClass('fix-position');
430
           var scrollBarWidth = 14;
431
            var marg = parseInt($(self).css('marginLeft')) + cmarg - scrollBarWidth;
432
            tt = marg;
433
            setTimeout(function(){
434
                $(self).animate({
435
                    'margin-left': marg,
436
                }, speed, 'linear')
437
            }, cdelay);
438
            $('.lt-bar').animate({
439
                width: 'toggle'
440
            }, speed, 'linear', ui.setCustomScrollBar);
441
        }
442
    });
443
}
444

    
445

    
446
ui.setCustomScrollBar = function() {
447
    $('.scroll-pane-arrows').jScrollPane({
448
        showArrows: true,
449
        horizontalGutter: 10,
450
        verticalDragMinHeight: 300,
451
        verticalDragMaxHeight: 300,
452
        mouseWheelSpeed: 50
453
});
454
}
455

    
456

    
457
$(document).ready(function(){
458

    
459
    $('html').click(function(e) {
460
        // not sure if we want to hide the error window after every click in the ui
461
        if($('.communication-error').css('bottom') == '0px') {
462
            $('.communication-error').animate({bottom: "-151px"});
463
        }
464
        if($('.details .lt-bar').is(':visible')) {
465
            $('.toggle-lt-bar').trigger('click');
466
        }
467
    });
468

    
469
    if($('.vms.entities').length!=0){
470
        ui.inactiveActions();
471
    };
472
    ui.setElminHeight($('.main > .details'));
473
    ui.setElminHeight($('.lt-bar'));
474
    ui.setElHeight($('.scroll-wrap'));
475
    $('#hd-search .hd-icon-search').click(function(e){
476
        var that = this;
477
        $(this).parents('.hd-search').toggleClass('hd-open');
478
        if ($(this).parents('.hd-search').hasClass('hd-open')) {
479
            $(that).parents('.hd-search').find('input[type="search"]').focus();
480
        } else {
481
            $(that).parents('.hd-search').find('input[type="search"]').val('');
482
        }
483
    })
484

    
485
    $('.header .login').mouseenter(function(e){
486
        $(this).find('ul').stop(true, true).slideDown(200);
487
    });
488
    $('.header .login').mouseleave(function(e){
489
        $(this).find('ul').stop(true, true).slideUp(200);
490
    });
491

    
492
    $('.entities a').click(function(){
493
        if ($(this).attr('data-reveal-id') && !($(this).hasClass('inactive'))) {
494
            $('.entities li .more').hide();
495
        }
496
    });
497

    
498
    $('.inactive').click(function(e){
499
        e.stopPropagation();
500
        e.preventDefault();
501
     })
502

    
503

    
504
    $('.lt-actions a:not(.active)').click(function(e){
505
        e.preventDefault();
506
    })
507

    
508
    if ($('.entities .items-list >li').length == 1) {
509
        $('.body-wrapper').addClass('no-vm');
510
    };
511
    $('.entities li .more').each(function(){
512
        var width = $(this).parent('li').outerWidth()  + 20;
513
        $(this).css('width', width);
514
    });
515

    
516
    $('.items-list li .img-wrap').on("mouseenter", function(e) {
517
        var that = this;
518
        if ($(this).parents('.entities').hasClass('grid-view')) {
519
            if ($(that).parent('.container').siblings('.more').length>0) {
520
                $(that).parent('.container').fadeOut(50,'easeInCirc');
521
                $(that).parent('.container').siblings('.more').fadeIn(150,'easeInCirc');
522
            }
523
        }
524
    });
525
    $('.entities li .more').mouseleave(function(e) {
526
        $(this).fadeOut(50, function() {
527
            $(this).siblings('.container').fadeIn(50);
528
        });
529
    });
530
    $('.grid-view .items-list > li').mouseleave(function(e){
531
        var that = this;
532
        setTimeout(function(){
533
            $(that).find('.more').fadeOut(200, function() {
534
                $(this).siblings('.container').fadeIn('fast');
535
            });
536
        },50)
537
    });
538

    
539
    ui.closeDiv($('.info .close'), '.info');
540
    ui.editable();
541
    ui.overlay();
542
    ui.colorPickerVisible = 0;
543

    
544
    $("a.disabled").each(function() {
545
        $(this).removeAttr('href');
546
    });
547
    
548
    $("a.disabled").click(function(e) {
549
        e.preventDefault();
550
    });
551

    
552
    // checkbox: basic reaction on click (checked, unchecked)
553
    // see wizard
554
    $('.check').click(function(e){
555
        e.preventDefault();
556
        e.stopPropagation();
557
        ui.changeCheckboxState(this);
558
    });
559

    
560

    
561
    $('.with-checkbox').click(function(e){
562
        e.preventDefault();
563
        e.stopPropagation();
564
        var checkbox = self.find('.check');
565
        ui.changeCheckboxState(checkbox);
566
    });
567

    
568
    $('.radio_btn').click(function(e) {
569
        e.preventDefault();
570
         var state = $(this).find('span');
571
         if(state.hasClass('snf-radio-unchecked')) {
572
            ui.checkOneRadioButton(this);
573
            ui.changeRadiobuttonState(this);
574
        }
575
    });
576

    
577
    $('.main-actions li a').click(function(e){
578
        if (!($(this).hasClass('active'))) {
579
            e.preventDefault();
580
        }
581
    });
582

    
583
    $('.main-actions li a').click(function(e){
584
        if (!($(this).hasClass('active'))) {
585
            e.preventDefault();
586
        }
587
    });
588
    $('.overlay-area-custom').children('.close').click(function(e){
589
        e.preventDefault();
590
        e.stopPropagation();
591
        $(this).parents('.overlay-area-custom').hide();
592
        $(this).parents('.overlay-area-custom').find($('.overlay-div')).hide();
593
        $('body').removeClass('with-overlay');
594
    })
595

    
596
    $('.browse-files').click(function(e){
597
        e.preventDefault();
598
    })
599

    
600
    Dropzone.options.filesDropzone = {
601
        dictDefaultMessage:'',
602
        clickable: '.browse-files',
603
        previewsContainer: '.dropzone-files',
604
        createImageThumbnails: false,
605
        dictRemoveFile: "snf-Remove file",
606
    };
607

    
608

    
609
    $('.main .files').magnificPopup({
610
        delegate: 'a.show.image',
611
        type: 'image',
612
        tLoading: 'Loading image #%curr%...',
613
        mainClass: 'mfp-img-mobile',
614
        gallery: {
615
            enabled: true,
616
            navigateByImgClick: true,
617
            preload: [0,1] // Will preload 0 - before current, and 1 after the current image
618
        },
619
        image: {
620
            tError: 'The image could not be loaded.',
621
            titleSrc: function(item) {
622
                return item.el.data('title');
623
            }
624
        }
625
    });
626

    
627
    if($('#picker').length>0) {
628
        $('#picker').farbtastic('#color');
629
    };
630
    if($('#sb-search').length>0) {
631
        new UISearch( document.getElementById( 'sb-search' ) );
632
    }
633

    
634
    if ($('.toggle-lt-bar').length>0) {
635
        ui.ltBarToggle(400);
636
    }
637

    
638
    /* grid/list view for items-list */
639

    
640
    $('.actions-bar .list, .actions-bar .grid').click(function(e){
641
        e.preventDefault();
642
        if (!($(this).find('span').hasClass('current'))) {
643
            $('.actions-bar .grid span, .actions-bar .list span').removeClass('current');
644
            $(this).find('span').addClass('current');
645
            $('.entities').toggleClass('grid-view list-view');
646
        }
647
    });
648

    
649
     $('.lt-bar .select').click(function(e){
650
        $(this).find('span').toggleClass('snf-checkbox-checked snf-checkbox-unchecked');
651
        $(this).find('em').toggle();
652
        if ( $(this).find('span').hasClass('snf-checkbox-unchecked')){
653
            $('.list-view  li .check span').removeClass('snf-checkbox-checked');
654
            $('.list-view  li .check span').addClass('snf-checkbox-unchecked');
655
        } else {
656
            $('.list-view  li .check span').addClass('snf-checkbox-checked');
657
            $('.list-view  li .check span').removeClass('snf-checkbox-unchecked');
658
        }
659
        ui.entitiesActionsEnabled();
660
     });
661

    
662
    // set filter visible
663
    $('.filter-menu .filter').click(function(e) {
664
        e.preventDefault();
665
        $(this).parents('.filter-menu').toggleClass('current');
666
    });
667

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

    
674
    $('[data-status="rebooting"] .btn5.temp').click(function(e) {
675
        e.preventDefault();
676
        $(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress');
677
    })
678

    
679
    // //temp function to preventDefault of links in modal
680
    // $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
681
    //     e.preventDefault();
682
    //     $('a.close-reveal-modal').trigger('click');
683
    // });
684

    
685
     // temp btn to show communication error message
686
    $('.temp-for-btns .communication-error-btn').click(function(e) {
687
         e.preventDefault();
688
         e.stopPropagation();
689
         $('.communication-error').animate({bottom: "0px"});
690
     });
691

    
692
    $('.communication-error a').click(function(e) {
693
        e.preventDefault();
694
        e.stopPropagation();
695
        $('.communication-error').animate({bottom: "-151px"});
696

    
697
    });
698
    $('.communication-error').click(function(e) {
699
        e.stopPropagation();
700
    });
701

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

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

    
722
    // connected details js
723
    ui.detailsCustom($('#disk-connected'));
724
    ui.detailsCustom($('#network-connected'));
725
    ui.detailsCustom($('#vm-connected'));
726
    ui.firewallSetup();
727
    $('.firewall .more  a').click(function(e){
728
        e.preventDefault();
729
        if ($(this).find('span').hasClass('snf-radio-checked')) {
730
            return false;
731
        }
732
        $(this).parents('.firewall').removeAttr('data-firewall');
733
        $(this).parents('.firewall').data('firewall', $(this).parent().attr('class'));
734
        $(this).find('span').toggleClass('snf-radio-unchecked snf-radio-checked');
735
        $(this).parent('p').siblings('p').find('span').removeClass('snf-radio-checked');
736
        $(this).parent('p').siblings('p').find('span').addClass('snf-radio-unchecked');
737
         ui.firewallSetup();
738
    });
739
    $('.firewall').mouseenter(function(e){
740
        $(this).css('z-index',2);
741
        $(this).find('.more').stop(true, true).slideDown(200);
742
    });
743
    $('.firewall').mouseleave(function(e){
744
        $(this).css('z-index',1);
745
        $(this).find('.more').stop(true, true).slideUp(200);
746
    });
747
    ui.tabs($('.tabs'), $('.content'));
748
    ui.hashTabs($('.tabs'), $('.content'));
749

    
750
    $('.act').click(function(e) {
751
        $(this).addClass('pending last');
752
    });
753

    
754
    $('.remove .cancel').click(function(e) {
755
        e.preventDefault();
756
        $('a.close-reveal-modal').trigger('click');
757
        $('.last').removeClass('pending last');
758
    });
759

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

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

    
792
    // with the function below the sidebar in detailed views
793
    // will not hide if we click something in a wizard
794
    $('.wizard').click(function(e) {
795
        e.stopPropagation();
796
    })
797

    
798
    $('.tag-data').mouseover(function() {
799
        $(this).find('.delete').css({visibility: 'visible'})
800
    });
801
    $('.tag-data').mouseleave(function(){
802
        $(this).find('.delete').css({visibility: 'hidden'})
803
    });
804
    $('.delete').click(function(e) {
805
        e.preventDefault();
806
        $(this).closest('div').fadeOut('slow');
807
    });
808

    
809
    $('.strorage-progress').hover(
810
        function(e){
811
            $(this).find('.summary').stop(true,true).hide();
812
            $(this).find('.details').stop(true,true).slideDown();
813
        },
814
        function(e){
815
            $(this).find('.details').stop(true,true).slideUp();
816
            $(this).find('.summary').stop(true,true).show();
817
        }
818
    );
819

    
820
})
821

    
822

    
823
$(window).resize(function(e){
824
    ui.setElminHeight($('.main > .details'));
825
    ui.setElminHeight($('.lt-bar'));
826
    ui.setElHeight($('.scroll-wrap'));
827
    ui.setCustomScrollBar();
828
})