commit ff529368841201ff481174d4228295fe12540efd
Author: Olga Brani <olgabrani@grnet.gr>
Date:   Thu Feb 27 19:41:48 2014 +0200

    uinext: Clean-up common.js

diff --git a/snf-cyclades-app/synnefo/ui/new_ui/ui/app/common.js b/snf-cyclades-app/synnefo/ui/new_ui/ui/app/common.js
index 5cbf0b4..898f2ea 100644
--- a/snf-cyclades-app/synnefo/ui/new_ui/ui/app/common.js
+++ b/snf-cyclades-app/synnefo/ui/new_ui/ui/app/common.js
@@ -2,6 +2,15 @@
 * These functions are used throughout ember
 */
 
+_.mixin({
+  capitalize: function(string) {
+    return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
+  }
+});
+
+
+em = {};
+
 
 
 
@@ -31,7 +40,7 @@ ui.closeDiv = function(closeEl, divToCloseClass) {
         e.preventDefault();
         $(this).parents(divToCloseClass).slideUp('slow');
     });
-}
+};
 
 
 ui.trimChars = function( str, chars) {
@@ -40,7 +49,7 @@ ui.trimChars = function( str, chars) {
     } else {
         return str;
     }
-}
+};
 
 
 /* Sets element min-height
@@ -52,7 +61,7 @@ ui.setElminHeight = function(el){
     var actions = $('.actions-bar').height();
     var h1= WindowHeight - (header+actions);
     el.css('min-height', h1);
-}
+};
 
 /* Sets element height
 * Used for .details, .lt-bar divs
@@ -63,7 +72,7 @@ ui.setElHeight = function(el){
     var actions = $('.actions-bar').height();
     var h1= WindowHeight - (header+actions);
     el.css('height', h1);
-}
+};
 
 /* Sets element max-height
 * Used for div.storage-progress
@@ -74,7 +83,7 @@ ui.setElmaxHeight = function(el){
     var actions = $('.actions-bar').height();
     var h1= WindowHeight - (header+actions);
     el.css('max-height', h1);
-}
+};
 
 /* 
 * Logic for Entities actions. Present in items_list pages
@@ -126,7 +135,7 @@ ui.entitiesActionsEnabled = function(){
             $('.lt-actions li.single a').removeClass('active');
         }
     }
-}
+};
 
 ui.inactiveActions = function() {
 
@@ -147,8 +156,8 @@ ui.inactiveActions = function() {
             var el = '.' + key + ' .' + value;
             $(el).addClass('inactive');
         });
-    })
-}
+    });
+};
 
 ui.detailsCustom = function(area) {
     // position last connected item
@@ -157,7 +166,7 @@ ui.detailsCustom = function(area) {
     var moveY = el.find('.connections >li').last().outerHeight(true) - 2;
     el.css('top',moveY);
     el.css('marginTop', -moveY);
-}
+};
 
 ui.firewallSetup = function(){
     $('.firewall').each(function(){
@@ -169,103 +178,10 @@ ui.firewallSetup = function(){
             $(this).find('p').first().find('em').html('on');
         }
     });
-}
-
-
-
-/*
-* In order for the editable value functionality to work, the html markup
-* should be:
-    <div class="editable">
-        <span class="input-txt">editable value</span>
-        <input type="text">
-        <a href="#" class="edit">edit</a>
-        <a href="#" class="save">save</a>
-        <a href="#" class="cancel">cancel</a>
-    </div>
-*/
-ui.editable = function(){
-
-/*
-* resetForm hides save and cancel buttons,
-* text input and shows input-txt. resetForm does not alter
-* input-txt content.
-*/
-
-    function resetForm(e, elem) {
-        var el = elem.parents('.editable');
-        el.find('input[type="text"]').hide();
-        el.find('a.cancel, a.save').hide();
-        el.find('a.edit, .input-txt').show();
-    }
-
-/* 
-* showForm hides input-txt, shows save and cancel buttons and
-* sets input value to input-txt content.
-*/
-    function showForm(e,elem) {
-        e.stopPropagation(); 
-        e.preventDefault();
-        var el = elem.parents('.editable'); 
-        el.find('input[type="text"]').val(el.find('.input-txt').html());
-        el.find('input[type="text"]').show().focus();
-        el.find('a.cancel, a.save').show();
-        elem.hide();
-        el.find('.input-txt').hide();
-    }
-
-/*
-setValue sets input-txt value to the input value.
-Makes sure that the input value is not empty.
-TODO:
-Ajax request to submit form
-*/
-
-    function setValue(elem) {
-        var el = elem.parents('.editable');
-        if( el.find('input[type="text"]').val() ) {
-            el.find('.input-txt').html(el.find('input[type="text"]').val());
-        }
-    }
-
-
-    $('.editable .edit').click(function(e){
-        showForm(e, $(this));
-    })
-
-    $('.editable .cancel').click(function(e){
-        e.stopPropagation();
-        e.preventDefault();
-        resetForm(e, $(this));
-    })
-
-    $('.editable .save').click(function(e){
-        e.stopPropagation();
-        e.preventDefault();
-        setValue($(this));
-        resetForm(e, $(this));
+};
 
-    })
 
 
-    $('.editable input[type="text"]').click(function(e){
-        e.stopPropagation();
-    })
-
-    $('.editable input[type="text"]').keyup(function(e){
-        if(e.keyCode == 13) { 
-            setValue($(this));
-            resetForm(e, $(this));
-            
-        }
-    
-    })
-
-    $('html').click(function(e) {
-        resetForm(e, $('.editable a.cancel'));
-    });
-
-}
 
 /* TODO: better overlay functionality */
 ui.overlay = function() {
@@ -283,7 +199,7 @@ ui.overlay = function() {
         }
         $(id).find('a').first().focus();
     });
-}
+};
 
 function goToByScroll(id){
       // Remove "link" from the ID
@@ -298,19 +214,18 @@ function goToByScroll(id){
 // toggle expand arrrow  and  area
 // todo: one function for all the areas we reveal
 ui.expandDownArea = function(arrow_link, area) {
-    var arrow_link = $(arrow_link);
-    var area = $(area);
-            arrow_link.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down');
-            // $('.wizard-content').removeAttr('style');
-            area.stop().slideToggle(600, function() {
-                if (area.is(':visible')) {
-                    arrow_link.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up');
-                } else {
-                    arrow_link.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down');
-                }
+    var arrow = $(arrow_link);
+    arrow.find('span.snf-arrow-up, span.snf-arrow-down').toggleClass('snf-arrow-up snf-arrow-down');
+    // $('.wizard-content').removeAttr('style');
+    $(area).stop().slideToggle(600, function() {
+        if ($(area).is(':visible')) {
+            arrow.find('.snf-arrow-down .snf-arrow-up').removeClass('snf-arrow-down').addClass('snf-arrow-up');
+        } else {
+            arrow.find('.snf-arrow-down .snf-arrow-up').addClass('snf-arrow-down');
+        }
 
-            });
-}
+    });
+};
 
 // toggle checkbox and area
 ui.slideHiddenArea = function(checkbox_link, area) {
@@ -322,43 +237,7 @@ ui.slideHiddenArea = function(checkbox_link, area) {
         }
     });
 };
-/* Tabs functionality
-* tabsEl is the div/ul with the links to the sections and the sections that
-* with toggle have class sectionEl.
-* Markup needed is an href to each a with the id of the relative section.
-*/
 
-/*ui.tabsSection = function(link, sectionEl) {
-    sectionEl.hide();
-    var el = $(link.attr('href'));
-    el.stop(true, true).show(0);
-    el.css('opacity',0);
-    ui.detailsCustom(el);
-    el.animate({
-        'opacity':1,
-    }, 500)
-}
-
-ui.tabs = function(tabsEl, sectionEl) {
-    var tabLink = tabsEl.find('a');
-    ui.replaceClass(tabLink.find('.active'), 'outline', 'full', 'snf-');
-    function href(a) {
-        return a.attr('href');
-    }
-    tabLink.click(function(e){
-        e.preventDefault();
-        if ( $(this).hasClass('active')){
-             return false;
-        } else {
-            window.location.hash = $(this).attr('href');
-            ui.replaceClass($(this).parents(tabsEl).find('.active'), 'full', 'outline', 'snf-');
-            $(this).parents(tabsEl).find('a').removeClass('active');
-            $(this).addClass('active');
-            ui.replaceClass($(this), 'outline', 'full', 'snf-');
-            ui.tabsSection( $(this), sectionEl);
-        }
-    })
-}*/
 
 // the function replaces part of the class of a span that is placed inside an a element
 // the class is a word with the form : firstSubStr+*+str1 and it will be converted to: firstSubStr+*+str2
@@ -368,7 +247,7 @@ ui.replaceClass = function(elements, str1, str2, firstSubStr) {
     $.each($(elements), function() {
         var classOld = $(this).find('span').attr('class');
         var classNew;
-        if(classOld != undefined && classOld.indexOf(str1) != -1) {
+        if(classOld !== undefined && classOld.indexOf(str1) != -1) {
             if(classOld.indexOf(' ') == -1) {
                 classNew = classOld.replace(str1, str2);
                 $(this).find('.'+classOld).removeClass(classOld).addClass(classNew);
@@ -386,13 +265,13 @@ ui.replaceClass = function(elements, str1, str2, firstSubStr) {
                 // spaces all over the string
                 var spacesExp = new RegExp('\\s+', 'g');
 
-                if(classOld.match(expr1) != null) {
+                if(classOld.match(expr1) !== null) {
                     classToReplace = classOld.match(expr1);
                 }
-                else if(classOld.match(expr2) != null) {
+                else if(classOld.match(expr2) !== null) {
                     classToReplace = classOld.match(expr2);
                 }
-                else if (classOld.match(expr3) != null) {
+                else if (classOld.match(expr3) !== null) {
                     classToReplace = classOld.match(expr3);
                 }
                 classToReplace = classToReplace.toString().replace(spacesExp,"");
@@ -401,44 +280,7 @@ ui.replaceClass = function(elements, str1, str2, firstSubStr) {
             }
         }
     });
-}
-
-// in a page with tabs, allow navigation with hash tags
-ui.hashTabs = function(tabsEl, sectionEl){
-/*    var hash = window.location.hash;
-    if ($(hash).length<=0){
-        return;
-    }
-    tabsEl.find('a').removeClass('active');
-    var link = tabsEl.find('a[href="'+hash+'"]');
-    link.addClass('active');
-    ui.tabsSection(link, sectionEl);
-*/
-}
-
-// in a page with tabs, allow navigation with hash tags
-ui.hashViews = function(viewsEl, sectionEl){
-    /*var hash = window.location.hash;
-    if (!(hash)){
-        return;
-    }
-    var link = viewsEl.find('a[href="'+hash+'"]');
-    console.log('link', link);
-    if (link.length<=0){
-        return;
-    }
-    viewsEl.find('a span').removeClass('current');
-    link.find('span').addClass('current');
-    sectionEl.removeClass('grid-view list-view');
-    var sectionClass = hash.slice(1) + '-view';
-    sectionEl.addClass(sectionClass);*/
-}
-
-
-
-
-ui.setCustomScrollBar = function() {
-}
+};
 
 function bytesToSize(bytes) {
     var sizes = [ 'n/a', 'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
@@ -464,7 +306,7 @@ function date_ddmmmyytime(date)
        a_p = "pm";
     }
 
-    if (curr_hour == 0) {
+    if (curr_hour === 0) {
        curr_hour = 12;
     }
     if (curr_hour > 12){
@@ -487,7 +329,7 @@ ui.mimeToExt = function( mimetype) {
   };
   console.log(mimetype);
   return mimeExt[mimetype] || 'unknown';
-}
+};
 
 $(document).ready(function(){
 
@@ -498,9 +340,9 @@ $(document).ready(function(){
         }
     });
 
-    if($('.vms.entities').length!=0){
+    if($('.vms.entities').length!==0){
         ui.inactiveActions();
-    };
+    }
     ui.setElminHeight($('.main > .details'));
     ui.setElminHeight($('.lt-bar'));
     ui.setElmaxHeight($('.storage-progress'));
@@ -512,7 +354,7 @@ $(document).ready(function(){
         } else {
             $(that).parents('.hd-search').find('input[type="search"]').val('');
         }
-    })
+    });
 
     $('.header .login').mouseenter(function(e){
         $(this).find('ul').stop(true, true).slideDown(200);
@@ -540,11 +382,12 @@ $(document).ready(function(){
 
     $('.lt-actions a:not(.active)').click(function(e){
         e.preventDefault();
-    })
+    });
 
     if ($('.entities .items-list >li').length == 1) {
         $('.body-wrapper').addClass('no-vm');
-    };
+    }
+
     $('.entities li .more').each(function(){
         var width = $(this).parent('li').outerWidth()  + 20;
         $(this).css('width', width);
@@ -570,11 +413,11 @@ $(document).ready(function(){
             $(that).find('.more').fadeOut(200, function() {
                 $(this).siblings('.container').fadeIn('fast');
             });
-        },50)
+        },50);
     });
 
     ui.closeDiv($('.info .close'), '.info');
-    //ui.editable();
+
     ui.overlay();
     ui.colorPickerVisible = 0;
 
@@ -603,7 +446,7 @@ $(document).ready(function(){
         $(this).parents('.overlay-area-custom').hide();
         $(this).parents('.overlay-area-custom').find($('.overlay-div')).hide();
         $('body').removeClass('with-overlay');
-    })
+    });
 
     $('.browse-files').click(function(e){
         e.preventDefault();
@@ -611,10 +454,10 @@ $(document).ready(function(){
 
     if($('#picker-1').length>0) {
         $('#picker-1').farbtastic('#color-1');
-    };
+    }
     if($('#picker-2').length>0) {
         $('#picker-2').farbtastic('#color-2');
-    };
+    }
     if($('#sb-search').length>0) {
         new UISearch( document.getElementById( 'sb-search' ) );
     }
@@ -651,7 +494,7 @@ $(document).ready(function(){
     $('[data-status="rebooting"] .btn5.temp').click(function(e) {
         e.preventDefault();
         $(this).siblings('.container').find('.snf-pc-full').toggleClass('reboot-progress');
-    })
+    });
 
     // //temp function to preventDefault of links in modal
     // $('.reveal-modal a:not(".close-reveal-modal, .generate-key-btn, .import-key-btn")').click(function(e){
@@ -687,13 +530,13 @@ $(document).ready(function(){
     });
 
     $('.hide-add-tag').click(function(e) {
-    e.preventDefault();
-    $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() {
-        $('.show-add-tag').first().scrollintoview({
-            'duration': 'slow'
+        e.preventDefault();
+        $(this).parents('.tags-area, .tags').find('.snf-color-picker').slideUp(400, function() {
+            $('.show-add-tag').first().scrollintoview({
+                'duration': 'slow'
+            });
+            ui.colorPickerVisible = 0;
         });
-        ui.colorPickerVisible = 0;
-    });
     });
 
     // connected details js
@@ -710,9 +553,8 @@ $(document).ready(function(){
         $(this).css('z-index',1);
         $(this).find('.more').stop(true, true).slideUp(200);
     });
-    //ui.tabs($('.tabs'), $('.content'));
-    ui.hashTabs($('.tabs'), $('.content'));
-    ui.hashViews($('.actions-bar .rt-actions'), $('.entities'));
+    
+
 
     $('.act').click(function(e) {
         $(this).addClass('pending last');
@@ -759,13 +601,13 @@ $(document).ready(function(){
     $('.containers .project').mouseleave(function(e){
         $(this).find('ul').fadeOut();
         $(this).find('.btn-more').removeClass('clicked');
-    })
+    });
 
     if ($('.containers .btn-more').length>0) {
         $('body').click(function(e){
             $('.btn-more').removeClass('clicked');
             $('.btn-more').siblings('ul').fadeOut();
-        })
+        });
     }
 
     // add a <span> element inside the content of each a.wrap-a element
@@ -781,23 +623,16 @@ $(document).ready(function(){
     $('.side-actions ul.options').mouseleave(function(e){
         $(this).hide();
         $(this).siblings('ul').removeAttr('style');
-    })
+    });
 
-})
+});
 
 
 $(window).resize(function(e){
     ui.setElminHeight($('.main > .details'));
     ui.setElminHeight($('.lt-bar'));
     ui.setElHeight($('.scroll-wrap'));
-    ui.setCustomScrollBar();
     ui.setElmaxHeight($('.storage-progress'));
 
 });
 
-
-_.mixin({
-  capitalize: function(string) {
-    return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
-  }
-});
\ No newline at end of file
