institution style
[unfold.git] / portal / static / js / institution.js
index 17858fe..e8c863e 100644 (file)
@@ -1,22 +1,20 @@
 $(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() {
@@ -51,6 +49,29 @@ $(document).ready(function() {
             }
         });
     });
+    $('button#renewslices').click(function() {
+        var now = new Date();
+        /* 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;
+                $.post("/update/slice/",{'filters':{'slice_hrn':this.id},'params':{'expires':one_month_later}}, function(data) {
+                    if(data.success){
+                        // TODO: highlight row after success
+                        //$('tr[id="'+record_id+'"]').highlight();
+                    }else{
+                        alert("Rest Error for "+record_id+": "+data.error);
+                    }
+                });
+                
+            }
+        });
+        // TODO: refresh table
+        //window.location="/portal/institution#slices";
+    });
 
     $('button#createslice').click(function() {
         window.location="/portal/slice_request/";
@@ -61,3 +82,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' ]
+               }
+       );
+}