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