sliceuser: normal user can add users to slice now
[unfold.git] / portal / templates / slice-tab-users-view.html
1 <script type="text/javascript" src="{{STATIC_URL}}/js/jquery-ui.js"></script>
2 <script type="text/javascript" src="{{STATIC_URL}}/js/jquery.qtip.min.js"></script>
3 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.qtip.min.css">
4 <link rel="stylesheet" href="{{ STATIC_URL }}css/jquery-ui.css">
5 <script>
6     function get_users_in_slice(authority_hrn){
7         console.log(authority_hrn);
8         $("table#user-tab").html("<tr><th>+/-</th><th>Email</th><th>User hrn</th></tr>");
9         var slice_users = [];
10         $.post("/rest/user/",{'filters':{'parent_authority': authority_hrn}}, function( data ) {
11                 var list_users = [];
12                 var table_users = [];
13                 /* Available fields
14                 user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
15             user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
16                 */
17                 $.each( data, function( key, val ) {
18                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
19                 user_row = "<tr>";
20                         // checking the box for the users that belong to the selected slice
21                         var flag_checkbox = 0;
22                         for(var data in val.slices) {
23                                 var element = val.slices[data];
24                                 if (element == "{{slice}}"){
25                                         //console.log("the slice is: "+ element);       
26                                         flag_checkbox = 1;
27                                         slice_users.push (val.user_hrn)
28                                         user_row += "<td><input type='checkbox' checked='True' class='user'></td>";
29                                 }
30                         }
31                         if(flag_checkbox != 1){
32                         user_row += "<td><input type='checkbox' class='user'></td>";
33                         }
34                 user_row += "<td>"+val.user_email+"</td>";
35                 user_row += "<td>"+val.user_hrn+"</td>";
36                         //user_row += "<td>"+val.user_enabled+"</td>";
37                 user_row += "</tr>";
38                 table_users.push(user_row);
39             
40                 });
41                 $("table#user-tab tr:first").after(table_users.join( "" ));
42                 $("div#user-tab-loaded").css("display","block");
43                 $("div#user-tab-loading").css("display","none");
44             $("input:checkbox.user").click(function() {
45                 user_hrn = $(this).closest('tr').find('td:eq(2)').html();
46                 if(this.checked){
47                     var record_id = this.id;
48                     slice_users.push (user_hrn);
49                 }else{
50                     console.log(slice_users);
51                 }
52             });
53         }); // post rest/use
54
55                 $('button#addusers').click(function() {
56                 $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
57                         if(data.success){
58                         // TODO: highlight row after success
59                         //$('tr[id="'+record_id+'"]').highlight();
60                         mysliceAlert('Success: slice updated','success', true);
61                         }else{
62                         mysliceAlert('Rest Error for: '+data.error,'warning', true);
63                         }
64                 }); // post update slice
65  
66                 // TODO: refresh table
67                 //window.location="/portal/institution#slices";
68                 }); // button#addusers click
69
70     } // get_users_in_slice
71
72     $(document).ready(function() {
73             // TODO: Add a filter based on the list of authorities
74                 $.post("/rest/authority/",{'fields':['authority_hrn']}, function( data ) {
75                 var list_authorities = [];
76                 $.each( data, function( key, val ) {
77                     auth_hrn = val.authority_hrn;
78                     // Keep only the sub authorities, remove root auth
79                     if(auth_hrn.indexOf(".") > -1){
80                         list_authorities.push(auth_hrn);
81                                                 list_authorities.sort();
82                         if(auth_hrn=="{{user_details.parent_authority}}"){
83                                                         $('#auth_list').val(auth_hrn);
84                                                 }
85                     }
86                 });
87                                 $( "#auth_list" ).autocomplete({
88                                 source: list_authorities,
89                                 minLength: 0,
90                                 select: function (event, ui) {
91                                                 get_users_in_slice(ui.item.value);
92                                 }
93                                 //select: function( event, ui ) {console.log(jQuery(this))}
94                         });
95             }); // post rest/authority
96
97             get_users_in_slice("{{user_details.parent_authority}}");
98
99         $('[title!=""]').qtip();
100     }); // document ready
101 </script>
102
103         <div class="col-md-2">
104                 <div id="select-platform" class="list-group">
105                 </div>
106                         
107                 <ul class="list-group">
108                   <li class="list-group-item">Authority</li>
109                   <li class="list-group-item" style="padding-left:5px;">
110                         <input type="text" id="auth_list"  style ="min-width:190px;" 
111                         title="The default value is  the authority that you belong to and the selected users belong to this slice.
112                                    You can view users of other authorities (organizations) from the list that apears when you click in the field and start to type.
113                                    Use the arrow keys to scroll through the list; type part of the name to narrow down the list."/>
114           </li>
115                 </ul>
116         
117         </div>
118         <div class="col-md-10">
119                 <div class="row">
120                 </div>
121                 <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Useres" /></div>
122                 <div id="user-tab-loaded" style="display:none;">
123                 <table id="user-tab" class="table">
124                 </table>
125
126                 <!-- XXX TODO: for the moment only PIs have access to Update but users that have slice credentials should also have access to that -->
127
128                                 <button id="addusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> Update users</button>
129                 </div>
130