update pending badge
[unfold.git] / portal / static / js / institution.js
1 $(document).ready(function() {
2     $('a.home-tab').click(function() {
3         $('ul.nav-tabs li').removeClass('active');
4         $(this).parent().addClass('active');
5         $('div.home-panel').hide();
6         $('div#'+$(this).data('panel')).show();
7     });
8     var url = window.location;
9     if(url.hash) {
10         // Fragment exists 
11         tab = url.href.split("#")[1];
12         tab_exists = $('div#'+tab).length;
13         if (tab_exists) {
14            $('ul.nav-tabs li').removeClass('active');
15            $('li#'+tab+'-tab').addClass('active');
16            $('div.home-panel').hide();            
17            $('div#'+tab).show();
18         }
19     }
20
21     /* TODO: factorize into functions */
22     $('button#deleteusers').click(function() {
23         $('input:checkbox.user').each(function (index) {
24             if(this.checked){
25                 var record_id = this.id;
26                 $.post("/delete/user/",{'filters':{'user_hrn':this.id}}, function(data) {
27                     if(data.success){
28                         $('tr[id="'+record_id+'"]').fadeOut("slow");
29                         $('tr[id="'+record_id+'"]').remove();
30                     }else{
31                         alert("Rest Error for "+record_id+": "+data.error);
32                     }
33                 });
34                 
35             }
36         });
37     });
38     $('button#deleteslices').click(function() {
39         $('input:checkbox.slice').each(function (index) {
40             if(this.checked){
41                 var record_id = this.id;
42                 $.post("/delete/slice/",{'filters':{'slice_hrn':this.id}}, function(data) {
43                     if(data.success){
44                         $('tr[id="'+record_id+'"]').fadeOut("slow");
45                         $('tr[id="'+record_id+'"]').remove();
46                     }else{
47                         alert("Rest Error for "+record_id+": "+data.error);
48                     }
49                 });
50                 
51             }
52         });
53     });
54     $('button#renewslices').click(function() {
55         var now = new Date();
56         /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on...  */
57         var month = now.getMonth()+2;
58         var one_month_later = now.getFullYear()+"-"+month+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
59         console.log(one_month_later);
60         $('input:checkbox.slice').each(function (index) {
61             if(this.checked){
62                 var record_id = this.id;
63                 $.post("/update/slice/",{'filters':{'slice_hrn':this.id},'params':{'expires':one_month_later}}, function(data) {
64                     if(data.success){
65                         // TODO: highlight row after success
66                         //$('tr[id="'+record_id+'"]').highlight();
67                     }else{
68                         alert("Rest Error for "+record_id+": "+data.error);
69                     }
70                 });
71                 
72             }
73         });
74         // TODO: refresh table
75         //window.location="/portal/institution#slices";
76     });
77
78     $('button#createslice').click(function() {
79         window.location="/portal/slice_request/";
80     });
81     $('button#slicerequestbtn').click(function() {
82         /*
83         window.location="/portal/slice_request/";
84         */
85     });
86 });