Institution: delete users and slices - this only works if the user has an authority...
[unfold.git] / portal / templates / institution.html
1 {% extends "layout.html" %}
2 {% block head %} 
3 <script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
4 {% endblock head %}
5 {% block content %}
6 <div class="row">
7         <h1><img src="{{ STATIC_URL }}img/icon_authority_color_small.png" alt="" /> Institution: {{user_details.parent_authority}}</h1>
8 </div>
9 <div class="row" id="institution">
10     <ul class="nav nav-tabs">
11       <li class="active" id="authority-tab"><a class="home-tab" data-panel="institution" href="#">INFO</a></li>
12       <li id="users-tab"><a class="home-tab" data-panel="users" href="#">USERS</a></li>
13       <li id="slices-tab"><a class="home-tab" data-panel="slices" href="#">SLICES</a></li>
14     </ul>
15     <div class="home-panel" id="institution">
16         <div id="authority-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Authority" /></div>
17         <div id="authority-tab-loaded" style="display:none;">
18             <div id="authority-data" style="float:left; width:50%;"></div>
19             <div id="onelab_membership" style="float:right; width:50%;">
20                 <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
21                 <div id="onelab-data"></div>
22             </div>
23         </div>
24     </div>
25     <div class="home-panel" id="users" style="display:none;">
26         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
27         <div id="user-tab-loaded" style="display:none;">
28             <table id="user-tab">
29                 <tr>
30                     <th>+/-</th>
31                     <th>Email</th>
32                     <th>user_hrn</th>
33                     <th>First name</th>
34                     <th>Last name</th>
35                     <th>Enabled</th>
36                 </tr>
37             </table>
38             <br>
39             <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
40         </div>
41         </div>
42     <div class="home-panel" id="slices" style="display:none;">
43         <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
44         <div id="slice-tab-loaded" style="display:none;">
45             <table id="slice-tab">
46                 <tr>
47                     <th>+/-</th>
48                     <th>slice_hrn</th>
49                     <th>users</th>
50                     <th>url</th>
51                     <th>nodes</th>
52                     <th>expiration</th>
53                 </tr>
54             </table>
55             <br>
56             <div>
57                 <button id="renewslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
58                 <button id="deleteslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
59             </div>
60         </div>
61     </div>
62 </div>
63 <script>
64     $(document).ready(function() {
65         {% if person %}
66         {% if user_details.parent_authority %}
67         $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
68             var authority_data = [];
69             var onelab_data = [];
70                         /* 'city','enabled','legal','longitude','onelab_membership','address','parent_authority','slice','user','country',
71             'tech','abbreviated_name','url','postcode','description','scientific','authority_hrn','latitude','name'     */
72             $.each( data, function( key, val ) {
73                 authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.gif' alt='' /><br>";
74                 authority_row += "<br>";
75                 authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
76                 authority_row += "<br>";
77                 authority_row += "<b>"+val.name+"</b><br>";
78                 authority_row += "<br>";
79                 authority_row += "<b>Address:</b> "+val.address+"<br>";
80                 authority_row += "<b>City:</b> "+val.postcode+" "+val.city+"<br>";
81                 authority_row += "<br>";
82                 authority_row += "<b>Country:</b> "+val.country+"<br>";
83                 authority_row += "<br>";
84                 authority_row += "<br>";
85                 authority_row += "<h2>Contacts</h2>";
86                 authority_row += "<b>Legal:</b> ";
87                 /*
88
89                 TODO: find a way to express JSON correctly given the constrains: CSV / JSON
90
91                 legal = jQuery.parseJSON(val.legal);
92                 if($.isArray(legal)){
93                     $.each(legal, function(k,v){
94                         authority_row += k+" "+v+"<br>";
95                     });
96                 }else{
97                 */
98                     authority_row += val.legal+"<br>";
99                 //}
100                 authority_row += "<br>";
101                 authority_row += "<b>Scientific:</b> ";
102                 /*
103                 scientific = jQuery.parseJSON(val.scientific);
104                 if($.isArray(scientific)){
105                     $.each(scientific, function(v){
106                         authority_row += v+", ";
107                     });
108                 }else{
109                 */
110                     authority_row += val.scientific+"<br>";
111                 //}
112                 onelab_membership = "<b>Status: </b>"+val.onelab_membership;
113                 onelab_data.push(onelab_membership);
114                 authority_data.push(authority_row);
115             });
116             $("div#authority-data").html(authority_data.join( "" ));
117             $("div#onelab-data").html(onelab_data.join( "" ));
118             $("div#authority-tab-loaded").css("display","block");
119             $("div#authority-tab-loading").css("display","none");
120          });
121
122         $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
123             var list_slices = [];
124             var table_slices = [];
125             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "user", "slice_urn", "slice_expires" */
126             $.each( data, function( key, val ) {
127                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
128                 if(val.nodes=="undefined" || val.nodes==null){
129                     nodes_length=0;
130                 }else{
131                     nodes_length=val.nodes.length;
132                 }
133
134                 if(val.user=="undefined" || val.user==null){
135                     user_length=0;
136                 }else{
137                     user_length=val.user.length;
138                 }
139
140                 if(val.slice_url=="undefined" || val.slice_url==null){
141                     slice_url="";
142                 }else{
143                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
144                 }
145                 
146                 slice_row = "<tr id='"+val.slice_hrn+"'>";
147                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
148                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
149                 slice_row += "<td>"+user_length+"</td>";
150                 slice_row += "<td>"+slice_url+"</td>";
151                 slice_row += "<td>"+nodes_length+"</td>";
152                 slice_row += "<td>"+val.slice_expires+"</td>";
153                 slice_row += "</tr>";
154                 table_slices.push(slice_row);
155                 
156             });
157            
158             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
159             $("table#slice-tab tr:last").after(table_slices.join( "" ));
160             $("div#slice-tab-loaded").css("display","block");
161             $("div#slice-tab-loading").css("display","none");
162         });
163
164         $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
165             var list_users = [];
166             var table_users = [];
167                         /*
168                         "enabled", "keys", "parent_authority", "user_first_name", "user_last_name", "user_phone", "user_hrn", "slice", "user_email"
169                         */
170             $.each( data, function( key, val ) {
171                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
172
173                 user_row = "<tr id='"+val.user_hrn+"'>";
174                 user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
175                 user_row += "<td>"+val.user_email+"</td>";
176                 user_row += "<td>"+val.user_hrn+"</td>";
177                 user_row += "<td>"+val.user_first_name+"</td>";
178                 user_row += "<td>"+val.user_last_name+"</td>";
179                                 user_row += "<td>"+val.enabled+"</td>";
180                 user_row += "</tr>";
181                 table_users.push(user_row);
182                 
183             });
184             $("table#user-tab tr:last").after(table_users.join( "" ));
185             $("div#user-tab-loaded").css("display","block");
186             $("div#user-tab-loading").css("display","none");
187          });
188          {% endif %}
189          {% endif %}
190     });
191 </script>
192 {% endblock %}