Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (28.5 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
function bytesToSize(bytes) {
477
    var sizes = [ 'n/a', 'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
478
    var i = +Math.floor(Math.log(bytes) / Math.log(1024));
479
    return  (bytes / Math.pow(1024, i)).toFixed( 0 ) + sizes[ isNaN( bytes ) ? 0 : i+1 ];
480
}
481
function date_ddmmmyytime(date)
482
{
483
  var d = date.getDate();
484
  var m = date.getMonth();
485
  var y = date.getYear();
486
  if(y >= 100)
487
  {
488
    y -= 100;
489
    y += 2000;
490
  }
491

    
492
    var curr_hour = date.getHours();
493

    
494
    if (curr_hour < 12){
495
        a_p = "am";
496
    } else {
497
       a_p = "pm";
498
    }
499

    
500
    if (curr_hour == 0) {
501
       curr_hour = 12;
502
    }
503
    if (curr_hour > 12){
504
       curr_hour = curr_hour - 12;
505
    }
506

    
507
    var curr_min = date.getMinutes();
508

    
509
  return "" +
510
    (d<10?"0"+d:d) + "/" +m + "/" + y + ' '+curr_hour + ":" + curr_min + a_p;
511
}
512

    
513

    
514
$(document).ready(function(){
515

    
516
    $('html').click(function(e) {
517
        // not sure if we want to hide the error window after every click in the ui
518
        if($('.communication-error').css('bottom') == '0px') {
519
            $('.communication-error').animate({bottom: "-151px"});
520
        }
521
        if($('.details .lt-bar').is(':visible')) {
522
            $('.toggle-lt-bar').trigger('click');
523
        }
524
    });
525

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

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

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

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

    
561

    
562
    $('.lt-actions a:not(.active)').click(function(e){
563
        e.preventDefault();
564
    })
565

    
566
    if ($('.entities .items-list >li').length == 1) {
567
        $('.body-wrapper').addClass('no-vm');
568
    };
569
    $('.entities li .more').each(function(){
570
        var width = $(this).parent('li').outerWidth()  + 20;
571
        $(this).css('width', width);
572
    });
573

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

    
597
    ui.closeDiv($('.info .close'), '.info');
598
    ui.editable();
599
    ui.overlay();
600
    ui.colorPickerVisible = 0;
601

    
602
    $("a.disabled").each(function() {
603
        $(this).removeAttr('href');
604
    });
605
    
606
    $("a.disabled").click(function(e) {
607
        e.preventDefault();
608
    });
609

    
610
    // checkbox: basic reaction on click (checked, unchecked)
611
    // see wizard
612
    $('.check').on('click', function(e){
613
        alert('skata');
614
        e.preventDefault();
615
        e.stopPropagation();
616
        ui.changeCheckboxState(this);
617
    });
618

    
619

    
620
    $('.with-checkbox').click(function(e){
621
        e.preventDefault();
622
        e.stopPropagation();
623
        var checkbox = self.find('.check');
624
        ui.changeCheckboxState(checkbox);
625
    });
626

    
627
    $('.radio_btn').click(function(e) {
628
        e.preventDefault();
629
         var state = $(this).find('span');
630
         if(state.hasClass('snf-radio-unchecked')) {
631
            ui.checkOneRadioButton(this);
632
            ui.changeRadiobuttonState(this);
633
        }
634
    });
635

    
636
    $('.main-actions li a').click(function(e){
637
        if (!($(this).hasClass('active'))) {
638
            e.preventDefault();
639
        }
640
    });
641

    
642
    $('.main-actions li a').click(function(e){
643
        if (!($(this).hasClass('active'))) {
644
            e.preventDefault();
645
        }
646
    });
647
    $('.overlay-area-custom').children('.close').click(function(e){
648
        e.preventDefault();
649
        e.stopPropagation();
650
        $(this).parents('.overlay-area-custom').hide();
651
        $(this).parents('.overlay-area-custom').find($('.overlay-div')).hide();
652
        $('body').removeClass('with-overlay');
653
    })
654

    
655
    $('.browse-files').click(function(e){
656
        e.preventDefault();
657
    })
658

    
659
    Dropzone.options.filesDropzone = {
660
        dictDefaultMessage:'',
661
        clickable: '.browse-files',
662
        previewsContainer: '.dropzone-files',
663
        createImageThumbnails: false,
664
        dictRemoveFile: "snf-Remove file",
665
    };
666

    
667

    
668
    $('.main .files').magnificPopup({
669
        delegate: 'a.show.image',
670
        type: 'image',
671
        tLoading: 'Loading image #%curr%...',
672
        mainClass: 'mfp-img-mobile',
673
        gallery: {
674
            enabled: true,
675
            navigateByImgClick: true,
676
            preload: [0,1] // Will preload 0 - before current, and 1 after the current image
677
        },
678
        image: {
679
            tError: 'The image could not be loaded.',
680
            titleSrc: function(item) {
681
                return item.el.data('title');
682
            }
683
        }
684
    });
685

    
686
    if($('#picker').length>0) {
687
        $('#picker').farbtastic('#color');
688
    };
689
    if($('#sb-search').length>0) {
690
        new UISearch( document.getElementById( 'sb-search' ) );
691
    }
692

    
693
    if ($('.toggle-lt-bar').length>0) {
694
        ui.ltBarToggle(400);
695
    }
696

    
697
    /* grid/list view for items-list */
698

    
699
    $('.actions-bar .list, .actions-bar .grid').click(function(e){
700
        e.preventDefault();
701
        if (!($(this).find('span').hasClass('current'))) {
702
            $('.actions-bar .grid span, .actions-bar .list span').removeClass('current');
703
            $(this).find('span').addClass('current');
704
            $('.entities').toggleClass('grid-view list-view');
705
        }
706
    });
707

    
708
     $('.lt-bar .select').click(function(e){
709
        $(this).find('span').toggleClass('snf-checkbox-checked snf-checkbox-unchecked');
710
        $(this).find('em').toggle();
711
        if ( $(this).find('span').hasClass('snf-checkbox-unchecked')){
712
            $('.list-view  li .check span').removeClass('snf-checkbox-checked');
713
            $('.list-view  li .check span').addClass('snf-checkbox-unchecked');
714
        } else {
715
            $('.list-view  li .check span').addClass('snf-checkbox-checked');
716
            $('.list-view  li .check span').removeClass('snf-checkbox-unchecked');
717
        }
718
        ui.entitiesActionsEnabled();
719
        ui.checkedListItems();
720
     });
721

    
722
    // set filter visible
723
    $('.filter-menu .filter').click(function(e) {
724
        e.preventDefault();
725
        $(this).parents('.filter-menu').toggleClass('current');
726
    });
727

    
728
    // temp function used to demonstrate the visual effect of the building state of vm
729
    $('[data-status="building"] .btn5.temp').click(function(e) {
730
        e.preventDefault();
731
        $(this).siblings('.container').find('.complete').toggleClass('build-progress');
732
    });
733

    
734
    $('[data-status="rebooting"] .btn5.temp').click(function(e) {
735
        e.preventDefault();
736
        $(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress');
737
    })
738

    
739
    // //temp function to preventDefault of links in modal
740
    // $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
741
    //     e.preventDefault();
742
    //     $('a.close-reveal-modal').trigger('click');
743
    // });
744

    
745
     // temp btn to show communication error message
746
    $('.temp-for-btns .communication-error-btn').click(function(e) {
747
         e.preventDefault();
748
         e.stopPropagation();
749
         $('.communication-error').animate({bottom: "0px"});
750
     });
751

    
752
    $('.communication-error a').click(function(e) {
753
        e.preventDefault();
754
        e.stopPropagation();
755
        $('.communication-error').animate({bottom: "-151px"});
756

    
757
    });
758
    $('.communication-error').click(function(e) {
759
        e.stopPropagation();
760
    });
761

    
762
    $('.show-add-tag').click(function(e) {
763
    e.preventDefault();
764
    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideDown('slow', function() {
765
        $('#hide-add-tag-dummy').scrollintoview({
766
            'duration': 'slow'
767
        });
768
    });
769
    ui.colorPickerVisible = 1;
770
    });
771

    
772
    $('.hide-add-tag').click(function(e) {
773
    e.preventDefault();
774
    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() {
775
        $('.show-add-tag').first().scrollintoview({
776
            'duration': 'slow'
777
        });
778
        ui.colorPickerVisible = 0;
779
    });
780
    });
781

    
782
    // connected details js
783
    ui.detailsCustom($('#disk-connected'));
784
    ui.detailsCustom($('#network-connected'));
785
    ui.detailsCustom($('#vm-connected'));
786
    ui.firewallSetup();
787
    $('.firewall .more  a').click(function(e){
788
        e.preventDefault();
789
        if ($(this).find('span').hasClass('snf-radio-checked')) {
790
            return false;
791
        }
792
        $(this).parents('.firewall').removeAttr('data-firewall');
793
        $(this).parents('.firewall').data('firewall', $(this).parent().attr('class'));
794
        $(this).find('span').toggleClass('snf-radio-unchecked snf-radio-checked');
795
        $(this).parent('p').siblings('p').find('span').removeClass('snf-radio-checked');
796
        $(this).parent('p').siblings('p').find('span').addClass('snf-radio-unchecked');
797
         ui.firewallSetup();
798
    });
799
    $('.firewall').mouseenter(function(e){
800
        $(this).css('z-index',2);
801
        $(this).find('.more').stop(true, true).slideDown(200);
802
    });
803
    $('.firewall').mouseleave(function(e){
804
        $(this).css('z-index',1);
805
        $(this).find('.more').stop(true, true).slideUp(200);
806
    });
807
    ui.tabs($('.tabs'), $('.content'));
808
    ui.hashTabs($('.tabs'), $('.content'));
809

    
810
    $('.act').click(function(e) {
811
        $(this).addClass('pending last');
812
    });
813

    
814
    $('.remove .cancel').click(function(e) {
815
        e.preventDefault();
816
        $('a.close-reveal-modal').trigger('click');
817
        $('.last').removeClass('pending last');
818
    });
819

    
820
    $('.remove .ok').click(function(e) {
821
        e.preventDefault();
822
        $('a.close-reveal-modal').trigger('click');
823
        var connection_img = $('.connections').find('.last');
824
        connection_img.addClass('open', 0);
825
        connection_img.removeClass('last');
826
        var img = connection_img.closest('.item').find('.img-wrap .snf-font');
827
        img.addClass('reboot-progress');
828
        setTimeout(function() {
829
            var connections_list = connection_img.closest('.connections').children('li:not(".hidden")');
830
            if(connections_list.length>1) {
831
                connection_img.closest('li').slideUp(function(){
832
                    connection_img.closest('li').addClass('hidden');
833
                    if(connections_list.find('.pending').length == 0) {
834
                      img.removeClass('reboot-progress');
835
                    }
836
                });
837
            }
838
            else {
839
                connection_img.closest('.item').slideUp(function(){
840
                    img.closest('li').addClass('hidden');
841
                    img.removeClass('reboot-progress');
842
                    img.removeClass('reboot-progress');
843
                });
844
            }
845
            connection_img.removeClass('pending');
846
        }, 3000)
847
    });
848
    // end of connected details js
849

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

    
852
    // with the function below the sidebar in detailed views
853
    // will not hide if we click something in a wizard
854
    $('.wizard').click(function(e) {
855
        e.stopPropagation();
856
    })
857

    
858
    $('.tag-data').mouseover(function() {
859
        $(this).find('.delete').css({visibility: 'visible'})
860
    });
861
    $('.tag-data').mouseleave(function(){
862
        $(this).find('.delete').css({visibility: 'hidden'})
863
    });
864
    $('.delete').click(function(e) {
865
        e.preventDefault();
866
        $(this).closest('div').fadeOut('slow');
867
    });
868

    
869
    $('.storage-progress').hover(
870
        function(e){
871
            $(this).find('.details').stop(false,true).slideDown();
872
        },
873
        function(e){
874
            $(this).find('.details').stop(false,true).slideUp();
875
        }
876
    );
877

    
878
    $('.btn-more').mouseenter(function(e) {
879
        $(this).find('.explain').stop(true, true).show('slow');
880
        $(this).addClass('style-1');
881
        $(this).find('.snf-arrow-down').removeClass('style-1');
882
        // $(this).siblings('.available').stop(true, true).slideDown(200);
883
    });
884

    
885
    $('.btn-more').click(function(e) {
886
        e.preventDefault();
887
        $(this).addClass('style-2');
888
        $(this).closest('.project').css('z-index', 2);
889
        $(this).siblings('.available').stop(true, true).slideDown('slow');
890
    })
891

    
892
    $('.project').mouseleave(function(e) {
893
        $(this).find('.available').stop(true, true).slideUp(200);
894
        var btn = $(this).find('.btn-more');
895
        btn.find('.explain').stop(true, true).hide('slow');
896
        $(btn).find('.snf-arrow-down').addClass('style-1');
897
        btn.removeClass('style-2');
898
        $(btn).removeClass('style-1');
899
        $(this).closest('.project').css('z-index',1);
900
    })
901
})
902

    
903

    
904
$(window).resize(function(e){
905
    ui.setElminHeight($('.main > .details'));
906
    ui.setElminHeight($('.lt-bar'));
907
    ui.setElHeight($('.scroll-wrap'));
908
    ui.setCustomScrollBar();
909
    ui.setElmaxHeight($('.storage-progress'));
910

    
911
})