Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (26.7 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
/* Sets element max-height
54
* Used for div.storage-progress
55
*/
56
ui.setElmaxHeight = function(el){
57
    var WindowHeight = $(window).height();
58
    var header = $('.header').outerHeight();
59
    var actions = $('.actions-bar').height();
60
    var h1= WindowHeight - (header+actions);
61
    el.css('max-height', h1);
62
}
63

    
64
/* 
65
* Logic for Entities actions. Present in items_list pages
66
* Available categories are :
67
*  - both/single ( for multiple entities/single entities)
68
*  - running/off ( for running/off entities)
69
*  - permanent ( for entities always active )
70
* Can be used for pithos as well
71
* Available categories are :
72
* - files ( for files only actions)
73
* - folders ( for folders only actions)
74
* - all ( for files/folders actions)
75
*/
76
ui.entitiesActionsEnabled = function(){
77
    var all = $('.snf-checkbox-checked').length;
78
    var running = $('.snf-checkbox-checked').parents('li.running').length;
79
    var off = $('.snf-checkbox-checked').parents('li.off').length;
80
    var files = $('.snf-checkbox-checked').parents('li.file').length;
81
    var folders = $('.snf-checkbox-checked').parents('li.folder').length;
82

    
83
    console.log(files,'files');
84
    console.log(folders,'folders');
85

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

    
88
    if ( ( files * folders )>0 ) {
89
        $('.lt-actions li.all a').addClass('active');
90
    } else {
91
        if ( files>0 ) {
92
            $('.lt-actions li.files a').addClass('active');
93
        }
94
        if ( folders>0 ){
95
            $('.lt-actions li.folders a').addClass('active');
96
        }
97
    }
98

    
99
    if ( (running*off) > 0 ){
100
         $('.lt-actions li.both a').addClass('active');
101
         $('.lt-actions li.single a').removeClass('active');
102
    } else {
103
        if (running > 0) {
104
            $('.lt-actions li.both a').addClass('active');
105
            $('.lt-actions li.running a').addClass('active');
106
        } else if (off>0) {
107
            $('.lt-actions li.both a').addClass('active');
108
            $('.lt-actions li.off a').addClass('active');
109
        }
110
        if ( all > 1 ) {
111
            $('.lt-actions li.single a').removeClass('active');
112
        }
113
    }
114
}
115

    
116
ui.inactiveActions = function() {
117

    
118
    // Availble actions: connect, reboot, shut, destroy, start
119
    // These actions will be DISABLED
120
    var statesActions ={
121
        'off'      : ['connect', 'reboot', 'shut'],
122
        'error'    : ['connect', 'reboot', 'shut', 'start'],
123
        'building' : ['reboot', 'start'],
124
        'running'  : ['start'],
125
        'rebooting': ['start'],
126
        'starting' : ['start'],
127
        'shutting' : ['connect', 'reboot', 'shut']
128
    } ;
129

    
130
    _.each (statesActions, function(val, key) {
131
        _.each(val, function(value) {
132
            var el = '.' + key + ' .' + value;
133
            $(el).addClass('inactive');
134
        });
135
    })
136
}
137

    
138
ui.detailsCustom = function(area) {
139
    // position last connected item
140
    var el = area.find('.item').last();
141
    // -2 is the border width;
142
    var moveY = el.find('.connections >li').last().outerHeight(true) - 2;
143
    el.css('top',moveY);
144
    el.css('marginTop', -moveY);
145
}
146

    
147
ui.firewallSetup = function(){
148
    $('.firewall').each(function(){
149
        $(this).removeClass('fully unprotected basic');
150
        $(this).addClass($(this).data('firewall'));
151
        if($(this).hasClass('unprotected')){
152
            $(this).find('p').first().find('em').html('off');
153
        } else {
154
            $(this).find('p').first().find('em').html('on');
155
        }
156
    });
157
}
158

    
159
ui.checkedListItems = function (){
160
    $('.list-view .items-list').find('.snf-checkbox-checked').each(function(){
161
        $(this).parents('li').addClass('selected');
162
    });
163
    $('.list-view .items-list').find('.snf-checkbox-unchecked').each(function(){
164
        $(this).parents('li').removeClass('selected');
165
    });
166
};
167

    
168
/*
169
* In order for the editable value functionality to work, the html markup
170
* should be:
171
    <div class="editable">
172
        <span class="input-txt">editable value</span>
173
        <input type="text">
174
        <a href="#" class="edit">edit</a>
175
        <a href="#" class="save">save</a>
176
        <a href="#" class="cancel">cancel</a>
177
    </div>
178
*/
179
ui.editable = function(){
180

    
181
/*
182
* resetForm hides save and cancel buttons,
183
* text input and shows input-txt. resetForm does not alter
184
* input-txt content.
185
*/
186

    
187
    function resetForm(e, elem) {
188
        var el = elem.parents('.editable');
189
        el.find('input[type="text"]').hide();
190
        el.find('a.cancel, a.save').hide();
191
        el.find('a.edit, .input-txt').show();
192
    }
193

    
194
/* 
195
* showForm hides input-txt, shows save and cancel buttons and
196
* sets input value to input-txt content.
197
*/
198
    function showForm(e,elem) {
199
        e.stopPropagation(); 
200
        e.preventDefault();
201
        var el = elem.parents('.editable'); 
202
        el.find('input[type="text"]').val(el.find('.input-txt').html());
203
        el.find('input[type="text"]').show();
204
        el.find('a.cancel, a.save').show();
205
        elem.hide();
206
        el.find('.input-txt').hide();
207
    }
208

    
209
/*
210
setValue sets input-txt value to the input value.
211
Makes sure that the input value is not empty.
212
TODO:
213
Ajax request to submit form
214
*/
215

    
216
    function setValue(elem) {
217
        var el = elem.parents('.editable');
218
        if( el.find('input[type="text"]').val() ) {
219
            el.find('.input-txt').html(el.find('input[type="text"]').val());
220
        }
221
    }
222

    
223

    
224
    $('.editable .edit').click(function(e){
225
        showForm(e, $(this));
226
    })
227

    
228
    $('.editable .cancel').click(function(e){
229
        e.stopPropagation();
230
        e.preventDefault();
231
        resetForm(e, $(this));
232
    })
233

    
234
    $('.editable .save').click(function(e){
235
        e.stopPropagation();
236
        e.preventDefault();
237
        setValue($(this));
238
        resetForm(e, $(this));
239

    
240
    })
241

    
242

    
243
    $('.editable input[type="text"]').click(function(e){
244
        e.stopPropagation();
245
    })
246

    
247
    $('.editable input[type="text"]').keyup(function(e){
248
        if(e.keyCode == 13) { 
249
            setValue($(this));
250
            resetForm(e, $(this));
251
            
252
        }
253
    
254
    })
255

    
256
    $('html').click(function(e) {
257
        resetForm(e, $('.editable a.cancel'));
258
    });
259

    
260
}
261

    
262
/* TODO: better overlay functionality */
263
ui.overlay = function() {
264
    $('[data-overlay-id]').click(function(e){
265
        e.preventDefault();
266
        var el = $(this);
267
        var id = '#'+el.data('overlay-id');
268

    
269
        $('.overlay-area-custom').fadeIn(100);
270
        $('body').addClass('with-overlay');
271
        $(id).fadeIn('slow');
272
        if (id=='#network-wizard') {
273
            $(id).find('input').first().focus();
274
            return false;
275
        }
276
        $(id).find('a').first().focus();
277
    });
278
}
279

    
280
function goToByScroll(id){
281
      // Remove "link" from the ID
282
    id = id.replace("link", "");
283
      // Scroll
284
    $('html,body').animate({
285
        scrollTop: $("#"+id).offset().top},
286
        'slow');
287
}
288

    
289

    
290
/*
291
* functions concerning checkboxes and radiobuttons links
292
*/
293

    
294
ui.changeCheckboxState =function(checkbox_link) {
295
    $(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked');
296
    ui.entitiesActionsEnabled();
297
    ui.checkedListItems();
298
}
299

    
300
// to use the above functions use first the ui.checkOneRadioButton and then ui.changeRadiobuttonState
301
ui.checkOneRadioButton = function(radiobtn_link) {
302
    $(radiobtn_link).closest('ul').find('span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked');
303
}
304
ui.changeRadiobuttonState = function(radiobtn_link) {
305
    $(radiobtn_link).find('span.snf-radio-unchecked, span.snf-radio-checked').toggleClass('snf-radio-unchecked snf-radio-checked');
306
}
307

    
308

    
309

    
310
// toggle expand arrrow  and corresponding area
311
// todo: one function for all the areas we reveal
312
ui.expandDownArea = function(arrow_link, area) {
313
    var arrow_link = $(arrow_link);
314
    var area = $(area);
315
            arrow_link.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down');
316
            // $('.wizard-content').removeAttr('style');
317
            area.stop().slideToggle(600, function() {
318
                if (area.is(':visible')) {
319
                    arrow_link.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up');
320
                } else {
321
                    arrow_link.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down');
322
                }
323

    
324
            });
325
}
326

    
327

    
328
/* Tabs functionality
329
* tabsEl is the div/ul with the links to the sections and the sections that
330
* with toggle have class sectionEl.
331
* Markup needed is an href to each a with the id of the relative section.
332
*/
333

    
334
ui.tabsSection = function(link, sectionEl) {
335
    sectionEl.hide();
336
    var el = $(link.attr('href'));
337
    el.stop(true, true).show(0);
338
    el.css('opacity',0);
339
    ui.detailsCustom(el);
340
    el.animate({
341
        'opacity':1,
342
    }, 500)
343
}
344

    
345
ui.tabs = function(tabsEl, sectionEl) {
346
    var tabLink = tabsEl.find('a');
347
    ui.replaceClass(tabLink.find('.active'), 'outline', 'full', 'snf-');
348
    function href(a) {
349
        return a.attr('href');
350
    }
351
    tabLink.click(function(e){
352
        e.preventDefault();
353
        if ( $(this).hasClass('active')){
354
             return false;
355
        } else {
356
            window.location.hash = $(this).attr('href');
357
            ui.replaceClass($(this).parents(tabsEl).find('.active'), 'full', 'outline', 'snf-');
358
            $(this).parents(tabsEl).find('a').removeClass('active');
359
            $(this).addClass('active');
360
            ui.replaceClass($(this), 'outline', 'full', 'snf-');
361
            ui.tabsSection( $(this), sectionEl);
362
        }
363
    })
364
}
365

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

    
370
ui.replaceClass = function(elements, str1, str2, firstSubStr) {
371
    $.each($(elements), function() {
372
        var classOld = $(this).find('span').attr('class');
373
        var classNew;
374
        if(classOld != undefined && classOld.indexOf(str1) != -1) {
375
            if(classOld.indexOf(' ') == -1) {
376
                classNew = classOld.replace(str1, str2);
377
                $(this).find('.'+classOld).removeClass(classOld).addClass(classNew);
378
            }
379
            else {
380
                // the string starts with the firstSubStr and after the end of the word there's a space
381
                var expr1 = new RegExp('^'+firstSubStr+'+(\\S*)+'+str1+'+(\\s+)', 'g');
382

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

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

    
389
                // spaces all over the string
390
                var spacesExp = new RegExp('\\s+', 'g');
391

    
392
                if(classOld.match(expr1) != null) {
393
                    classToReplace = classOld.match(expr1);
394
                }
395
                else if(classOld.match(expr2) != null) {
396
                    classToReplace = classOld.match(expr2);
397
                }
398
                else if (classOld.match(expr3) != null) {
399
                    classToReplace = classOld.match(expr3);
400
                }
401
                classToReplace = classToReplace.toString().replace(spacesExp,"");
402
                classNew = classToReplace.replace(str1, str2);
403
                $(this).find('.'+classToReplace).removeClass(classToReplace).addClass(classNew);
404
            }
405
        }
406
    });
407
}
408

    
409
// in a page with tabs, allow navigation with hash tags
410
ui.hashTabs = function(tabsEl, sectionEl){
411
    var hash = window.location.hash;
412
    if ($(hash).length<=0){
413
        return;
414
    }
415
    tabsEl.find('a').removeClass('active');
416
    var link = tabsEl.find('a[href="'+hash+'"]');
417
    link.addClass('active');
418
    ui.tabsSection(link, sectionEl);
419

    
420
}
421

    
422
ui.ltBarToggle = function(speed){
423

    
424
    var cmarg = parseInt($('.lt-bar').width()) - parseInt($('.toggle-lt-bar').outerWidth(true));        
425
    var ctemp = cmarg / parseInt($('.lt-bar').width());
426
    var cvelocity = parseInt($('.lt-bar').width())/speed;
427
    var cdelay = parseInt($('.toggle-lt-bar').outerWidth(true))/cvelocity;
428

    
429
    $('.lt-bar').click(function(e) {
430
        e.stopPropagation();
431
    })
432
    $('.toggle-lt-bar').click(function(e){
433
        e.preventDefault();
434
        e.stopPropagation();
435
        var self =this;
436
        if($(this).hasClass('fix-position')) {
437
            var marg = parseInt($(self).css('marginLeft')) - cmarg;
438
            $(this).animate({
439
                'margin-left': marg,
440
            }, ctemp * speed, 'linear', function(){
441
                $(self).removeAttr('style');
442
                $(self).removeClass('fix-position');
443
            });
444
            $('.lt-bar').animate({
445
                width: 'toggle'
446
            }, speed, 'linear');
447
        }
448
        else {
449
            $(this).addClass('fix-position');
450
           var scrollBarWidth = 14;
451
            var marg = parseInt($(self).css('marginLeft')) + cmarg - scrollBarWidth;
452
            tt = marg;
453
            setTimeout(function(){
454
                $(self).animate({
455
                    'margin-left': marg,
456
                }, speed, 'linear')
457
            }, cdelay);
458
            $('.lt-bar').animate({
459
                width: 'toggle'
460
            }, speed, 'linear', ui.setCustomScrollBar);
461
        }
462
    });
463
}
464

    
465

    
466
ui.setCustomScrollBar = function() {
467
    $('.scroll-pane-arrows').jScrollPane({
468
        showArrows: true,
469
        horizontalGutter: 10,
470
        verticalDragMinHeight: 300,
471
        verticalDragMaxHeight: 300,
472
        mouseWheelSpeed: 50
473
});
474
}
475

    
476

    
477
$(document).ready(function(){
478

    
479
    $('html').click(function(e) {
480
        // not sure if we want to hide the error window after every click in the ui
481
        if($('.communication-error').css('bottom') == '0px') {
482
            $('.communication-error').animate({bottom: "-151px"});
483
        }
484
        if($('.details .lt-bar').is(':visible')) {
485
            $('.toggle-lt-bar').trigger('click');
486
        }
487
    });
488

    
489
    if($('.vms.entities').length!=0){
490
        ui.inactiveActions();
491
    };
492
    ui.setElminHeight($('.main > .details'));
493
    ui.setElminHeight($('.lt-bar'));
494
    ui.setElmaxHeight($('.storage-progress'));
495
    ui.setElHeight($('.scroll-wrap'));
496
    $('#hd-search .hd-icon-search').click(function(e){
497
        var that = this;
498
        $(this).parents('.hd-search').toggleClass('hd-open');
499
        if ($(this).parents('.hd-search').hasClass('hd-open')) {
500
            $(that).parents('.hd-search').find('input[type="search"]').focus();
501
        } else {
502
            $(that).parents('.hd-search').find('input[type="search"]').val('');
503
        }
504
    })
505

    
506
    $('.header .login').mouseenter(function(e){
507
        $(this).find('ul').stop(true, true).slideDown(200);
508
    });
509
    $('.header .login').mouseleave(function(e){
510
        $(this).find('ul').stop(true, true).slideUp(200);
511
    });
512

    
513
    $('.entities a').click(function(){
514
        if ($(this).attr('data-reveal-id') && !($(this).hasClass('inactive'))) {
515
            $('.entities li .more').hide();
516
        }
517
    });
518

    
519
    $('.inactive').click(function(e){
520
        e.stopPropagation();
521
        e.preventDefault();
522
     })
523

    
524

    
525
    $('.lt-actions a:not(.active)').click(function(e){
526
        e.preventDefault();
527
    })
528

    
529
    if ($('.entities .items-list >li').length == 1) {
530
        $('.body-wrapper').addClass('no-vm');
531
    };
532
    $('.entities li .more').each(function(){
533
        var width = $(this).parent('li').outerWidth()  + 20;
534
        $(this).css('width', width);
535
    });
536

    
537
    $('.items-list li .img-wrap').on("mouseenter", function(e) {
538
        var that = this;
539
        if ($(this).parents('.entities').hasClass('grid-view')) {
540
            if ($(that).parent('.container').siblings('.more').length>0) {
541
                $(that).parent('.container').fadeOut(50,'easeInCirc');
542
                $(that).parent('.container').siblings('.more').fadeIn(150,'easeInCirc');
543
            }
544
        }
545
    });
546
    $('.entities li .more').mouseleave(function(e) {
547
        $(this).fadeOut(50, function() {
548
            $(this).siblings('.container').fadeIn(50);
549
        });
550
    });
551
    $('.grid-view .items-list > li').mouseleave(function(e){
552
        var that = this;
553
        setTimeout(function(){
554
            $(that).find('.more').fadeOut(200, function() {
555
                $(this).siblings('.container').fadeIn('fast');
556
            });
557
        },50)
558
    });
559

    
560
    ui.closeDiv($('.info .close'), '.info');
561
    ui.editable();
562
    ui.overlay();
563
    ui.colorPickerVisible = 0;
564

    
565
    $("a.disabled").each(function() {
566
        $(this).removeAttr('href');
567
    });
568
    
569
    $("a.disabled").click(function(e) {
570
        e.preventDefault();
571
    });
572

    
573
    // checkbox: basic reaction on click (checked, unchecked)
574
    // see wizard
575
    $('.check').click(function(e){
576
        e.preventDefault();
577
        e.stopPropagation();
578
        ui.changeCheckboxState(this);
579
    });
580

    
581

    
582
    $('.with-checkbox').click(function(e){
583
        e.preventDefault();
584
        e.stopPropagation();
585
        var checkbox = self.find('.check');
586
        ui.changeCheckboxState(checkbox);
587
    });
588

    
589
    $('.radio_btn').click(function(e) {
590
        e.preventDefault();
591
         var state = $(this).find('span');
592
         if(state.hasClass('snf-radio-unchecked')) {
593
            ui.checkOneRadioButton(this);
594
            ui.changeRadiobuttonState(this);
595
        }
596
    });
597

    
598
    $('.main-actions li a').click(function(e){
599
        if (!($(this).hasClass('active'))) {
600
            e.preventDefault();
601
        }
602
    });
603

    
604
    $('.main-actions li a').click(function(e){
605
        if (!($(this).hasClass('active'))) {
606
            e.preventDefault();
607
        }
608
    });
609
    $('.overlay-area-custom').children('.close').click(function(e){
610
        e.preventDefault();
611
        e.stopPropagation();
612
        $(this).parents('.overlay-area-custom').hide();
613
        $(this).parents('.overlay-area-custom').find($('.overlay-div')).hide();
614
        $('body').removeClass('with-overlay');
615
    })
616

    
617
    $('.browse-files').click(function(e){
618
        e.preventDefault();
619
    })
620

    
621
    Dropzone.options.filesDropzone = {
622
        dictDefaultMessage:'',
623
        clickable: '.browse-files',
624
        previewsContainer: '.dropzone-files',
625
        createImageThumbnails: false,
626
        dictRemoveFile: "snf-Remove file",
627
    };
628

    
629

    
630
    $('.main .files').magnificPopup({
631
        delegate: 'a.show.image',
632
        type: 'image',
633
        tLoading: 'Loading image #%curr%...',
634
        mainClass: 'mfp-img-mobile',
635
        gallery: {
636
            enabled: true,
637
            navigateByImgClick: true,
638
            preload: [0,1] // Will preload 0 - before current, and 1 after the current image
639
        },
640
        image: {
641
            tError: 'The image could not be loaded.',
642
            titleSrc: function(item) {
643
                return item.el.data('title');
644
            }
645
        }
646
    });
647

    
648
    if($('#picker').length>0) {
649
        $('#picker').farbtastic('#color');
650
    };
651
    if($('#sb-search').length>0) {
652
        new UISearch( document.getElementById( 'sb-search' ) );
653
    }
654

    
655
    if ($('.toggle-lt-bar').length>0) {
656
        ui.ltBarToggle(400);
657
    }
658

    
659
    /* grid/list view for items-list */
660

    
661
    $('.actions-bar .list, .actions-bar .grid').click(function(e){
662
        e.preventDefault();
663
        if (!($(this).find('span').hasClass('current'))) {
664
            $('.actions-bar .grid span, .actions-bar .list span').removeClass('current');
665
            $(this).find('span').addClass('current');
666
            $('.entities').toggleClass('grid-view list-view');
667
        }
668
    });
669

    
670
     $('.lt-bar .select').click(function(e){
671
        $(this).find('span').toggleClass('snf-checkbox-checked snf-checkbox-unchecked');
672
        $(this).find('em').toggle();
673
        if ( $(this).find('span').hasClass('snf-checkbox-unchecked')){
674
            $('.list-view  li .check span').removeClass('snf-checkbox-checked');
675
            $('.list-view  li .check span').addClass('snf-checkbox-unchecked');
676
        } else {
677
            $('.list-view  li .check span').addClass('snf-checkbox-checked');
678
            $('.list-view  li .check span').removeClass('snf-checkbox-unchecked');
679
        }
680
        ui.entitiesActionsEnabled();
681
        ui.checkedListItems();
682
     });
683

    
684
    // set filter visible
685
    $('.filter-menu .filter').click(function(e) {
686
        e.preventDefault();
687
        $(this).parents('.filter-menu').toggleClass('current');
688
    });
689

    
690
    // temp function used to demonstrate the visual effect of the building state of vm
691
    $('[data-status="building"] .btn5.temp').click(function(e) {
692
        e.preventDefault();
693
        $(this).siblings('.container').find('.complete').toggleClass('build-progress');
694
    });
695

    
696
    $('[data-status="rebooting"] .btn5.temp').click(function(e) {
697
        e.preventDefault();
698
        $(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress');
699
    })
700

    
701
    // //temp function to preventDefault of links in modal
702
    // $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
703
    //     e.preventDefault();
704
    //     $('a.close-reveal-modal').trigger('click');
705
    // });
706

    
707
     // temp btn to show communication error message
708
    $('.temp-for-btns .communication-error-btn').click(function(e) {
709
         e.preventDefault();
710
         e.stopPropagation();
711
         $('.communication-error').animate({bottom: "0px"});
712
     });
713

    
714
    $('.communication-error a').click(function(e) {
715
        e.preventDefault();
716
        e.stopPropagation();
717
        $('.communication-error').animate({bottom: "-151px"});
718

    
719
    });
720
    $('.communication-error').click(function(e) {
721
        e.stopPropagation();
722
    });
723

    
724
    $('.show-add-tag').click(function(e) {
725
    e.preventDefault();
726
    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideDown('slow', function() {
727
        $('#hide-add-tag-dummy').scrollintoview({
728
            'duration': 'slow'
729
        });
730
    });
731
    ui.colorPickerVisible = 1;
732
    });
733

    
734
    $('.hide-add-tag').click(function(e) {
735
    e.preventDefault();
736
    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() {
737
        $('.show-add-tag').first().scrollintoview({
738
            'duration': 'slow'
739
        });
740
        ui.colorPickerVisible = 0;
741
    });
742
    });
743

    
744
    // connected details js
745
    ui.detailsCustom($('#disk-connected'));
746
    ui.detailsCustom($('#network-connected'));
747
    ui.detailsCustom($('#vm-connected'));
748
    ui.firewallSetup();
749
    $('.firewall .more  a').click(function(e){
750
        e.preventDefault();
751
        if ($(this).find('span').hasClass('snf-radio-checked')) {
752
            return false;
753
        }
754
        $(this).parents('.firewall').removeAttr('data-firewall');
755
        $(this).parents('.firewall').data('firewall', $(this).parent().attr('class'));
756
        $(this).find('span').toggleClass('snf-radio-unchecked snf-radio-checked');
757
        $(this).parent('p').siblings('p').find('span').removeClass('snf-radio-checked');
758
        $(this).parent('p').siblings('p').find('span').addClass('snf-radio-unchecked');
759
         ui.firewallSetup();
760
    });
761
    $('.firewall').mouseenter(function(e){
762
        $(this).css('z-index',2);
763
        $(this).find('.more').stop(true, true).slideDown(200);
764
    });
765
    $('.firewall').mouseleave(function(e){
766
        $(this).css('z-index',1);
767
        $(this).find('.more').stop(true, true).slideUp(200);
768
    });
769
    ui.tabs($('.tabs'), $('.content'));
770
    ui.hashTabs($('.tabs'), $('.content'));
771

    
772
    $('.act').click(function(e) {
773
        $(this).addClass('pending last');
774
    });
775

    
776
    $('.remove .cancel').click(function(e) {
777
        e.preventDefault();
778
        $('a.close-reveal-modal').trigger('click');
779
        $('.last').removeClass('pending last');
780
    });
781

    
782
    $('.remove .ok').click(function(e) {
783
        e.preventDefault();
784
        $('a.close-reveal-modal').trigger('click');
785
        var connection_img = $('.connections').find('.last');
786
        connection_img.addClass('open', 0);
787
        connection_img.removeClass('last');
788
        var img = connection_img.closest('.item').find('.img-wrap .snf-font');
789
        img.addClass('reboot-progress');
790
        setTimeout(function() {
791
            var connections_list = connection_img.closest('.connections').children('li:not(".hidden")');
792
            if(connections_list.length>1) {
793
                connection_img.closest('li').slideUp(function(){
794
                    connection_img.closest('li').addClass('hidden');
795
                    if(connections_list.find('.pending').length == 0) {
796
                      img.removeClass('reboot-progress');
797
                    }
798
                });
799
            }
800
            else {
801
                connection_img.closest('.item').slideUp(function(){
802
                    img.closest('li').addClass('hidden');
803
                    img.removeClass('reboot-progress');
804
                    img.removeClass('reboot-progress');
805
                });
806
            }
807
            connection_img.removeClass('pending');
808
        }, 3000)
809
    });
810
    // end of connected details js
811

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

    
814
    // with the function below the sidebar in detailed views
815
    // will not hide if we click something in a wizard
816
    $('.wizard').click(function(e) {
817
        e.stopPropagation();
818
    })
819

    
820
    $('.tag-data').mouseover(function() {
821
        $(this).find('.delete').css({visibility: 'visible'})
822
    });
823
    $('.tag-data').mouseleave(function(){
824
        $(this).find('.delete').css({visibility: 'hidden'})
825
    });
826
    $('.delete').click(function(e) {
827
        e.preventDefault();
828
        $(this).closest('div').fadeOut('slow');
829
    });
830

    
831
    $('.storage-progress').hover(
832
        function(e){
833
            $(this).find('.details').stop(false,true).slideDown();
834
        },
835
        function(e){
836
            $(this).find('.details').stop(false,true).slideUp();
837
        }
838
    );
839

    
840

    
841

    
842
})
843

    
844

    
845
$(window).resize(function(e){
846
    ui.setElminHeight($('.main > .details'));
847
    ui.setElminHeight($('.lt-bar'));
848
    ui.setElHeight($('.scroll-wrap'));
849
    ui.setCustomScrollBar();
850
    ui.setElmaxHeight($('.storage-progress'));
851

    
852
})