Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[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     $('button#deleteusers').click(function() {
20         $('input:checkbox.user').each(function (index) {
21             if(this.checked){
22                 var record_id = this.id;
23                 $.post("/delete/user/",{'filters':{'user_hrn':this.id}}, function(data) {
24                     if(data.success){
25                         $('tr[id="'+record_id+'"]').fadeOut("slow");
26                         $('tr[id="'+record_id+'"]').remove();
27                         mysliceAlert('Success: user deleted','success', true);
28                     }else{
29                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
30                         //alert("Rest Error for "+record_id+": "+data.error);
31                     }   
32                 });     
33             } 
34         });
35     });
36
37     /* TODO: factorize into functions */
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                         mysliceAlert('Success: slice deleted','success', true);
47                     }else{
48                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
49                         //alert("Rest Error for "+record_id+": "+data.error);
50                     }
51                 });
52             }
53         });
54     });
55     $('button#renewslices').click(function() {
56         var now = new Date();
57         /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on...  */
58         var month = now.getMonth()+2;
59         var one_month_later = now.getFullYear()+"-"+month+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
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                         mysliceAlert('Success: slice renewed','success', true);
68                     }else{
69                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
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 });
89
90 /*function loadUsers() {
91         $('div#users table').load('/table/user/',
92                 {
93                         'fields'  : [ 'user_hrn', 'user_first_name', 'user_last_name', 'user_email', 'user_phone' ],
94                         'filters' : { 'parent_authority' : $('div#users').data('authority') },
95                         'options' : [ 'checkbox' ]
96                 }
97         );
98 }*/