Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[unfold.git] / portal / templates / slice-tab-info.html
1 <div class="col-md-2">
2 </div>
3 <div class="col-md-8">
4         <div id="slice-info"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
5 </div>
6 <div class="col-md-2">
7 </div>
8 <script>
9     $(document).ready(function() {
10         $.post("/rest/slice/",{'filters':{'slice_hrn':'{{slice}}'}}, function( data ) {
11             var table_slices = [];
12             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "user", "slice_urn", "slice_expires" */
13             $.each( data, function( key, val ) {
14                 console.log(val);
15                 if(val.nodes=="undefined" || val.nodes==null){
16                     nodes_length=0;
17                 }else{
18                     nodes_length=val.nodes.length;
19                 }
20
21                 if(val.users=="undefined" || val.users==null){
22                     user_length=0;
23                 }else{
24                     user_length=val.users.length;
25                 }
26
27                 if(val.slice_url=="undefined" || val.slice_url==null){
28                     slice_url="";
29                 }else{
30                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
31                 }
32                 
33                // slice_row = "<tr><td>Description:</b></td><td>"+val.slice_description+"</td></tr>";
34                // slice_row += "<tr><td>url:</td><td><a href='"+val.slice_url+" target='_blank'>"+val.slice_url+"</a></td></tr>";
35                 slice_row = "<tr><td>users:</td><td>"+user_length+"</td></tr>";
36                 //slice_row += "<tr><td>resources:</td><td>"+nodes_length+"</td></tr>";
37                 //slice_row += "<tr><td>created:</td><td>"+val.created+"</td></tr>";
38                 slice_row += "<tr><td>last update:</td><td>"+val.slice_last_updated+"</td></tr>";
39                 //slice_row += "<tr><td>expires:</td><td>"+val.slice_expires+"</td></tr>";
40                 table_slices.push(slice_row);
41             });
42            $("div#slice-info").html("<table>" + table_slices.join( "" ) + "</table>");
43         });
44         $('button#renewslices').click(function() {
45             var now = new Date();
46             /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on...  */
47             var month = now.getMonth()+2;
48             var one_month_later = now.getFullYear()+"-"+month+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();
49             $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'expires':one_month_later}}, function(data) {
50                 if(data.success){
51                     mysliceAlert('Success: slice renewed','success', true);
52                 }
53                 else{
54                     mysliceAlert('Rest Error for: '+data.error,'warning', true);
55                 }
56             });
57         });
58         $('button#deleteslices').click(function() {
59             if (confirm('Are you sure? It will remove the slice permanently.')) {
60                 $.post("/delete/slice/",{'filters':{'slice_hrn':'{{slice}}'}}, function(data) {
61                     if(data.success){
62                         localStorage.clear();
63                         var user_email = [];
64                         user_email.push ('{{username}}');
65                         $.post("/credentials/clear/",{'emails':user_email}, function(data) {
66                         }); // post credentials clear
67                         mysliceAlert('Success: slice deleted','success', true);
68                     }else{
69                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
70                     }
71                     window.location.replace("/");
72                 });
73             } 
74             else {
75                 return false;
76             }
77         });
78     });
79
80 </script>
81
82 <div>
83     <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew slice</button>
84     <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete slice</button>
85 </div>