delete_local_user available from rest, check if user is a pi of the authority for...
[unfold.git] / portal / templates / fed4fire / fed4fire_institution.html
1 {% extends "layout_wide.html" %}
2
3 {% block head %} 
4 <script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
5 {% endblock head %}
6
7 {% block content %}
8 <div class="container">
9         <div class="row">
10                 <div class="col-md-12">
11                          <div class="breadcrumbs">
12                 {% if project %}
13                                 Management &nbsp;>&nbsp; Project: <span id="authority_name">{{user_details.parent_authority}}</span>
14                 {% else %}
15                                 Management &nbsp;>&nbsp; Institution: <span id="authority_name">{{user_details.parent_authority}}</span>
16                 {% endif %}
17                          </div>
18                 </div>
19         </div>
20 </div>
21 <div class="container">
22         <div class="row">
23                 <div class="col-md-12">
24                         <ul class="nav nav-tabs nav-section">
25                                 <li class="active"><a href="#about">About</a></li>
26                                 <li><a href="#users">Users</a></li>
27                 {% if not project %}
28                                 <li><a href="#projects">Projects</a></li>
29                 {% endif %}
30                                 <li><a href="#slices">Slices</a></li>
31                                 <li><a href="#requests">Requests</a></li>
32                         </ul>
33             </div>
34         </div>
35 </div>
36 <div class="container tab-content">
37         <div class="tab-pane active row" id="about">
38         <div class="col-md-12 el">
39         <h2>{{user_details.parent_authority}}</h2>
40         </div>
41         </div>
42         
43         <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
44                 <div class="col-md-12 el">
45                         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
46                                 <div id="user-tab-loaded" style="display:none;">
47                                 <table id="user-tab" class="table">
48                                         <tr>
49                                         <th>+/-</th>
50                             {% if not project %}
51                                         <th>Email</th>
52                             {% endif %}
53                                         <th>User hrn</th>
54                             <!--
55                                         <th>First name</th>
56                                         <th>Last name</th>
57                                         <th>Enabled</th>
58                             -->
59                                         </tr>
60                                 </table>
61                                 
62                         </div>
63                         {%if  pi %}     
64                         <div>
65                 {% if project %}
66                                 <button id="removepi" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove from project</button>
67                 {% else %}
68                                 <button id="makepi" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-up"></span> Upgrade to PI</button>
69                                 <button id="removepi" type="button" class="btn"><span class="glyphicon glyphicon-arrow-down"></span> Downgrade to  user</button>
70                                 <button id="deleteusers" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected users</button>
71                 {% endif %}
72                         </div>
73                         {% endif %}
74                 </div>
75         </div>
76
77     {% if not project %}
78         <div class="tab-pane row" id="projects" data-authority="{{user_details.parent_authority}}">
79                 <div class="col-md-12 el">
80                         <div id="project-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Projects" /></div>
81                                 <div id="project-tab-loaded" style="display:none;">
82                                 <table id="project-tab" class="table">
83                                         <tr>
84                                         <th>+/-</th>
85                                         <th>Project hrn</th>
86                                         </tr>
87                                 </table>
88                                 
89                         </div>
90                         <div>
91                 {% if  pi %}
92                         <button id="createproject" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create project</button>
93                         <button id="deleteprojects" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected projects</button>
94                         {% else %}
95                         <button id="createproject" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request project</button>
96                         {% endif %}
97                         </div>
98                 </div>
99         </div>
100    {% endif %}
101         <div class="tab-pane row" id="slices">
102                 <div class="col-md-12 el">
103             <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
104             <div id="slice-tab-loaded" style="display:none;">
105                 <table id="slice-tab" class="table">
106                     <tr>
107                         <th>+/-</th>
108                         <th>Slice hrn</th>
109                         <th>Users</th>
110                         <th>Url</th>
111                         <!-- <th>nodes</th> -->
112                         <th>Creation</th>
113                     </tr>
114                 </table>                        
115             </div>
116         <div>
117                 {% if pi %}
118                         <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
119             <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
120             <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
121                         {% else %}
122                         <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
123                         {% endif %}
124         </div>
125            </div>
126         </div>
127         <div class="tab-pane row" id="requests">
128         </div>
129 </div>
130 <script>
131 $(document).ready(function() {
132     {% if person %}
133     {% if user_details.parent_authority %}
134
135         $.post("/rest/myslice:slice/",{'fields':['slice_hrn','users','url','slice_date_created'],'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
136             var list_slices = [];
137             var table_slices = [];
138             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
139             $.each( data, function( key, val ) {
140                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
141                 if(val.nodes=="undefined" || val.nodes==null){
142                     nodes_length=0;
143                 }else{
144                     nodes_length=val.nodes.length;
145                 }
146                 //console.log(val);
147                 if(val.users=="undefined" || val.users==null){
148                     users_length=0;
149                 }else{
150                     users_length=val.users.length;
151                 }
152
153                 if(val.url=="undefined" || val.url==null){
154                     slice_url="";
155                 }else{
156                     slice_url="<a href='"+val.url+"' target='_blank'>"+val.url+"</a>";
157                 }
158                 
159                 slice_row = "<tr id='"+val.slice_hrn+"'>";
160                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
161
162                 // filter links to slices, only those that the user has credentials for
163                 s = myslice.user.slices;
164                 if(s.length > 0 && $.inArray(val.slice_hrn, myslice.user.slices)!=-1){
165                     slice_row += "<td><a href='/slice/"+val.slice_hrn+"'>" + val.slice_hrn + "</a></td>";
166                 }else{
167                     slice_row += "<td>" + val.slice_hrn + "</td>";
168                 }
169                 slice_row += "<td>"+users_length+"</td>";
170                 slice_row += "<td>"+slice_url+"</td>";
171                 //slice_row += "<td>"+nodes_length+"</td>";
172                 slice_row += "<td>"+val.slice_date_created+"</td>";
173                 slice_row += "</tr>";
174                 table_slices.push(slice_row);
175                 
176             });
177            
178             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
179             $("table#slice-tab tr:last").after(table_slices.join( "" ));
180             $("div#slice-tab-loaded").css("display","block");
181             $("div#slice-tab-loading").css("display","none");
182         });
183                 
184         {% if project %}
185                 $.post("/rest/myslice:authority/",{'fields':['pi_users'],'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
186            
187             var table_users = [];
188             $.each( data[0].pi_users, function( key, val ) {
189                 //console.log(val);
190                 user_row = "<tr id='"+val+"'>";
191                 user_row += "<td><input type='checkbox' class='user' id='"+val+"'></td>";
192                 user_row += "<td>"+val+"</td>";
193                 user_row += "</tr>";
194                 table_users.push(user_row);
195             });
196             $("table#user-tab tr:last").after(table_users.join( "" ));
197             $("div#user-tab-loaded").css("display","block");
198             $("div#user-tab-loading").css("display","none");
199
200         });
201         {% else %}
202         $.post("/rest/myslice:user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
203             var list_users = [];
204             var table_users = [];
205                     /* Available fields
206                     user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
207                     user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
208                     */
209             $.each( data, function( key, val ) {
210                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
211                 user_row = "<tr id='"+val.user_hrn+"'>";
212                 user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"' data-email='"+val.user_email+"'></td>";
213                 user_row += "<td>"+val.user_email+"</td>";
214                 user_row += "<td>"+val.user_hrn+"</td>";
215                 /*
216                 user_row += "<td>"+val.user_first_name+"</td>";
217                 user_row += "<td>"+val.user_last_name+"</td>";
218                             user_row += "<td>"+val.user_enabled+"</td>";
219                 */
220                 user_row += "</tr>";
221                 table_users.push(user_row);
222             });
223             $("table#user-tab tr:last").after(table_users.join( "" ));
224             $("div#user-tab-loaded").css("display","block");
225             $("div#user-tab-loading").css("display","none");
226         });
227                 $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS{{user_details.parent_authority}}'}}, function( data ) {
228            
229             var table_projects = [];
230             $.each( data, function( key, val ) {
231                 console.log(val);
232                 project_row = "<tr id='"+val.authority_hrn+"'>";
233                 project_row += "<td><input type='checkbox' class='project' id='"+val.authority_hrn+"'></td>";
234
235                 // filter links to projects, only those that the user has credentials for
236                 p = myslice.projects;
237                 if(p.length > 0 && $.inArray(val.authority_hrn, p)!=-1){
238                     project_row += "<td><a href='/portal/project/"+val.authority_hrn+"'>"+val.authority_hrn+"</a></td>";
239                 }else{
240                     project_row += "<td>"+val.authority_hrn+"</td>";
241                 }
242                 project_row += "</tr>";
243                 table_projects.push(project_row);
244             });
245             $("table#project-tab tr:last").after(table_projects.join( "" ));
246             $("div#project-tab-loaded").css("display","block");
247             $("div#project-tab-loading").css("display","none");
248
249         });
250
251         {% endif %}
252     {% endif %}
253     {% endif %}
254
255 }); // End document.ready
256
257 $(document).ready(function() {
258         $('.nav-tabs a').click(function (e) {
259                 e.preventDefault();
260                 $(this).tab('show');
261         var id = $(this).attr('href').substr(1);
262         if ((id == 'requests')){
263                 $("#" + id).load('/management/' + id);
264         }
265         /*
266         if ((id == 'requests') || (id == 'about'))
267                 $("#" + id).load('/management/' + id);
268         */
269         });
270         var hash = window.location.hash;
271         if (hash) {
272                 $('.nav-tabs a[href='+hash+']').click();
273         } else {
274                 $('.nav-tabs a[href=#about]').click();
275         }
276 });
277
278 //upgrade users to PI
279 $(document).ready(function() {
280     $('button#makepi').click(function() {
281         var flag = false;
282         var pi_users = [];
283         $.post("/rest/myslice:authority/",{'filters':{'authority_hrn': '{{user_details.parent_authority}}'}}, function( data ) {
284             pi_users = data[0]["pi_users"];
285             $('input:checkbox.user').each(function (index) {
286                 if(this.checked){
287                     var record_id = this.id;
288                     pi_users.push(record_id)
289                     flag = true;                
290                 }
291             });
292             if(flag == true){
293                 $.post("/update/myslice:authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'},'params':{'pi_users':pi_users}}, function(data) {
294                     if(data.success){
295                         mysliceAlert('Success: User rights added to: {{user_details.parent_authority}}','success', true);
296                     }else{
297                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
298                         //alert("Rest Error for "+record_id+": "+data.error);
299                     }
300                 });
301             }
302         });
303     });
304 });
305 //downgrade to user [in projects:remove from project]
306 $(document).ready(function() {
307     $('button#removepi').click(function() {
308         var flag = false;
309         var pi_users = [];
310         $.post("/rest/myslice:authority/",{'filters':{'authority_hrn': '{{user_details.parent_authority}}'}}, function( data ) {
311             pi_users = data[0]["pi_users"];
312                         // http://stackoverflow.com/questions/9792927/javascript-array-search-and-remove-string
313             $('input:checkbox.user').each(function (index) {
314                 if(this.checked){
315                     var record_id = this.id;
316                                         for (var i=pi_users.length-1; i>=0; i--) {
317                                         if (pi_users[i] === record_id) {
318                                                 pi_users.splice(i, 1);
319                                         }
320                                         }
321                     flag = true;                
322                 }
323             });
324             if(flag == true){
325                 $.post("/update/myslice:authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'},'params':{'pi_users':pi_users}}, function(data) {
326                     if(data.success){
327                         mysliceAlert('Success: User rights removed from: {{user_details.parent_authority}}','success', true);
328                         {% if project %}
329                         // remove the user from the list of pis of the project displayed
330                         $('input:checkbox.user').each(function (index) {
331                            if(this.checked){
332                                var record_id = this.id;
333                                $('tr[id="'+record_id+'"]').fadeOut("slow");
334                                $('tr[id="'+record_id+'"]').remove();
335                             }
336
337                         });
338                         {% endif %}
339                     }else{
340                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
341                         //alert("Rest Error for "+record_id+": "+data.error);
342                     }
343                 });
344             }
345         });
346     });
347 });
348
349
350
351 </script>
352 {% endblock %}