5595b3e0fcda7c4e11c84982c3c2ad8a10feaa37
[unfold.git] / portal / static / js / institution.js
1 $(document).ready(function() {
2         loadedTabs = [];
3         
4         $('.nav-tabs a').click(function (e) {
5                 e.preventDefault();
6                 $(this).tab('show');
7                 id = $(this).attr('href').substr(1);
8                 if (!(id in loadedTabs)) {
9                         switch(id) {
10                                 case 'users':
11                                         //loadUsers();
12                                         loadedTabs[id] = true;
13                                 break;
14                         }
15                 }
16                 
17         });
18
19     /* TODO: factorize into functions */
20     $('button#deleteslices').click(function() {
21         $('input:checkbox.slice').each(function (index) {
22             if(this.checked){
23                 var record_id = this.id;
24                 $.post("/delete/slice/",{'filters':{'slice_hrn':this.id}}, function(data) {
25                     if(data.success){
26                         $('tr[id="'+record_id+'"]').fadeOut("slow");
27                         $('tr[id="'+record_id+'"]').remove();
28                     }else{
29                         alert("Rest Error for "+record_id+": "+data.error);
30                     }
31                 });
32                 
33             }
34         });
35     });
36     $('button#renewslices').click(function() {
37         var now = new Date();
38         /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on...  */
39         var month = now.getMonth()+2;
40         var one_month_later = now.getFullYear()+"-"+month+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
41         console.log(one_month_later);
42         $('input:checkbox.slice').each(function (index) {
43             if(this.checked){
44                 var record_id = this.id;
45                 $.post("/update/slice/",{'filters':{'slice_hrn':this.id},'params':{'expires':one_month_later}}, function(data) {
46                     if(data.success){
47                         // TODO: highlight row after success
48                         //$('tr[id="'+record_id+'"]').highlight();
49                     }else{
50                         alert("Rest Error for "+record_id+": "+data.error);
51                     }
52                 });
53                 
54             }
55         });
56         // TODO: refresh table
57         //window.location="/portal/institution#slices";
58     });
59
60     $('button#createslice').click(function() {
61         window.location="/portal/slice_request/";
62     });
63     $('button#slicerequestbtn').click(function() {
64         /*
65         window.location="/portal/slice_request/";
66         */
67     });
68 });
69
70 /*function loadUsers() {
71         $('div#users table').load('/table/user/',
72                 {
73                         'fields'  : [ 'user_hrn', 'user_first_name', 'user_last_name', 'user_email', 'user_phone' ],
74                         'filters' : { 'parent_authority' : $('div#users').data('authority') },
75                         'options' : [ 'checkbox' ]
76                 }
77         );
78 }*/