Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[myslice.git] / portal / static / js / institution.js
index dc44870..2b2cfa3 100644 (file)
@@ -1,24 +1,21 @@
 $(document).ready(function() {
-    $('a.home-tab').click(function() {
-        $('ul.nav-tabs li').removeClass('active');
-        $(this).parent().addClass('active');
-        $('div.home-panel').hide();
-        $('div#'+$(this).data('panel')).show();
-    });
-    var url = window.location;
-    if(url.hash) {
-        // Fragment exists 
-        tab = url.href.split("#")[1];
-        tab_exists = $('div#'+tab).length;
-        if (tab_exists) {
-           $('ul.nav-tabs li').removeClass('active');
-           $('li#'+tab+'-tab').addClass('active');
-           $('div.home-panel').hide();            
-           $('div#'+tab).show();
-        }
-    }
+       loadedTabs = [];
+       
+       $('.nav-tabs a').click(function (e) {
+               e.preventDefault();
+               $(this).tab('show');
+               id = $(this).attr('href').substr(1);
+               if (!(id in loadedTabs)) {
+                       switch(id) {
+                               case 'users':
+                                       //loadUsers();
+                                       loadedTabs[id] = true;
+                               break;
+                       }
+               }
+               
+       });
 
-    /* TODO: factorize into functions */
     $('button#deleteusers').click(function() {
         $('input:checkbox.user').each(function (index) {
             if(this.checked){
@@ -27,14 +24,17 @@ $(document).ready(function() {
                     if(data.success){
                         $('tr[id="'+record_id+'"]').fadeOut("slow");
                         $('tr[id="'+record_id+'"]').remove();
+                        mysliceAlert('Success: user deleted','success', true);
                     }else{
-                        alert("Rest Error for "+record_id+": "+data.error);
-                    }
-                });
-                
-            }
+                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                        //alert("Rest Error for "+record_id+": "+data.error);
+                    }   
+                });     
+            } 
         });
     });
+
+    /* TODO: factorize into functions */
     $('button#deleteslices').click(function() {
         $('input:checkbox.slice').each(function (index) {
             if(this.checked){
@@ -43,11 +43,12 @@ $(document).ready(function() {
                     if(data.success){
                         $('tr[id="'+record_id+'"]').fadeOut("slow");
                         $('tr[id="'+record_id+'"]').remove();
+                        mysliceAlert('Success: slice deleted','success', true);
                     }else{
-                        alert("Rest Error for "+record_id+": "+data.error);
+                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                        //alert("Rest Error for "+record_id+": "+data.error);
                     }
                 });
-                
             }
         });
     });
@@ -56,7 +57,6 @@ $(document).ready(function() {
         /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on...  */
         var month = now.getMonth()+2;
         var one_month_later = now.getFullYear()+"-"+month+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
-        console.log(one_month_later);
         $('input:checkbox.slice').each(function (index) {
             if(this.checked){
                 var record_id = this.id;
@@ -64,8 +64,10 @@ $(document).ready(function() {
                     if(data.success){
                         // TODO: highlight row after success
                         //$('tr[id="'+record_id+'"]').highlight();
+                        mysliceAlert('Success: slice renewed','success', true);
                     }else{
-                        alert("Rest Error for "+record_id+": "+data.error);
+                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                        //alert("Rest Error for "+record_id+": "+data.error);
                     }
                 });
                 
@@ -84,3 +86,13 @@ $(document).ready(function() {
         */
     });
 });
+
+/*function loadUsers() {
+       $('div#users table').load('/table/user/',
+               {
+                       'fields'  : [ 'user_hrn', 'user_first_name', 'user_last_name', 'user_email', 'user_phone' ],
+                       'filters' : { 'parent_authority' : $('div#users').data('authority') },
+                       'options' : [ 'checkbox' ]
+               }
+       );
+}*/