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