Templates: small cosmetic changes, wip for filter on authorities for users in a slice
[unfold.git] / portal / templates / slice-tab-users-view.html
1         <div class="col-md-2">
2                 <div id="select-platform" class="list-group">
3                 </div>
4                         
5                 <ul class="list-group">
6                   <li class="list-group-item">Authority:<b> {{user_details.parent_authority}}</b>
7                         <!--<select id="auth_list">
8                                 <option value="ple.upmc">UPMC</option>
9                                 <option value="ple.inria">INRIA</option>
10                                 <option value="ple.nitos">NITOS</option>
11                                 <option value="ple.iminds">iMinds</option>
12                         </select> -->
13                   </li>
14                   <li class="list-group-item">Filter: slice</li>
15                   <li class="list-group-item">...</li>
16                   <li class="list-group-item">...</li>
17                   <li class="list-group-item">...</li>
18                 </ul>
19         
20         </div>
21         <div class="col-md-10">
22                 <div class="row">
23                 </div>
24                 <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Useres" /></div>
25                 <div id="user-tab-loaded" style="display:none;">
26                 <table id="user-tab">
27                         <tr>
28                         <th>+/-</th>
29                         <th>Email</th>
30                         <th>user_hrn</th>
31                         <th>Enabled</th>
32                         </tr>
33                 </table>
34
35                 <!-- XXX TODO: for the moment only PIs have access to Update but users that have slice credentials should also have access to that -->
36
37                                 {% if 'is_pi'  in pi %}
38                                 <button id="addusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> Update users</button>
39                                 {%endif%}
40                 </div>
41 <script>
42     $(document).ready(function() {
43             // TODO: Add a filter based on the list of authorities
44                 $.post("/rest/authority/",{'fields':['authority_hrn']}, function( data ) {
45                 console.log(data);
46             }); // post rest/authority
47
48                         var slice_users = [];
49                 $.post("/rest/user/",{'filters':{'parent_authority': "{{user_details.parent_authority}}"}}, function( data ) {
50                 var list_users = [];
51                 var table_users = [];
52                                 /* Available fields
53                                 user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
54                             user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
55                                 */
56                 $.each( data, function( key, val ) {
57                         list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
58                         user_row = "<tr>";
59                                         // checking the box for the users that belong to the selected slice
60                                         var flag_checkbox = 0;
61                                         for(var data in val.slices) {
62                                         var element = val.slices[data];
63                                                 if (element == "{{slice}}"){
64                                                         //console.log("the slice is: "+ element);       
65                                                         flag_checkbox = 1;
66                                                         slice_users.push (val.user_hrn)
67                                                         user_row += "<td><input type='checkbox' checked='True' class='user'></td>";
68                                                 }
69                                         }
70                                         if(flag_checkbox != 1){
71                                 user_row += "<td><input type='checkbox' class='user'></td>";
72                                         }
73                         user_row += "<td>"+val.user_email+"</td>";
74                         user_row += "<td>"+val.user_hrn+"</td>";
75                                         user_row += "<td>"+val.user_enabled+"</td>";
76                         user_row += "</tr>";
77                         table_users.push(user_row);
78                 
79                 });
80             
81                                 $("table#user-tab tr:last").after(table_users.join( "" ));
82                 $("div#user-tab-loaded").css("display","block");
83                 $("div#user-tab-loading").css("display","none");
84                 $("input:checkbox.user").click(function() {
85                     user_hrn = $(this).closest('tr').find('td:eq(2)').html();
86                     if(this.checked){
87                         var record_id = this.id;
88                         slice_users.push (user_hrn);
89                     }else{
90                         console.log(slice_users);
91                     }
92                 });
93            
94                 }); // post rest/user
95                 $('button#addusers').click(function() {
96                 $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
97                         if(data.success){
98                         // TODO: highlight row after success
99                         //$('tr[id="'+record_id+'"]').highlight();
100                         mysliceAlert('Success: slice updated','success', true);
101                         }else{
102                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
103                         }
104                 }); // post update slice
105             
106                 // TODO: refresh table
107                 //window.location="/portal/institution#slices";
108
109             }); // button#addusers click
110
111     }); // document ready
112 </script>
113