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">
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>");
10 var slice_users_removed = [];
11 var slice_users_emails = [];
12 var slice_users_emails_removed = [];
13 $.post("/rest/user/",{'filters':{'parent_authority': authority_hrn}}, function( data ) {
17 user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
18 user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
20 $.each( data, function( key, val ) {
21 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
23 // checking the box for the users that belong to the selected slice
24 var flag_checkbox = 0;
25 for(var data in val.slices) {
26 var element = val.slices[data];
27 if (element == "{{slice}}"){
28 //console.log("the slice is: "+ element);
30 slice_users.push (val.user_hrn)
31 user_row += "<td><input type='checkbox' checked='True' class='user'></td>";
34 if(flag_checkbox != 1){
35 user_row += "<td><input type='checkbox' class='user'></td>";
37 user_row += "<td>"+val.user_email+"</td>";
38 user_row += "<td>"+val.user_hrn+"</td>";
39 //user_row += "<td>"+val.user_enabled+"</td>";
41 table_users.push(user_row);
44 $("table#user-tab tr:first").after(table_users.join( "" ));
45 $("div#user-tab-loaded").css("display","block");
46 $("div#user-tab-loading").css("display","none");
47 $("input:checkbox.user").click(function() {
48 user_hrn = $(this).closest('tr').find('td:eq(2)').html();
49 user_email = $(this).closest('tr').find('td:eq(1)').html();
51 var record_id = this.id;
52 slice_users.push (user_hrn);
53 slice_users_removed.splice($.inArray(user_hrn, slice_users_removed),1);
54 slice_users_emails.push (user_email);
55 slice_users_emails_removed.splice($.inArray(user_email, slice_users_emails_removed),1);
58 slice_users_removed.push (user_hrn);
59 slice_users.splice($.inArray(user_hrn, slice_users),1);
60 slice_users_emails_removed.push (user_email);
61 // this one is removing from the list wrong user when u uncheck
62 //slice_users_emails.splice($.inArray(user_email, slice_users_emails),1);
63 //this one is still buggy cz it still keeps users in both arrays
64 // but it's ok for the moment
71 $('button#addusers').click(function() {
72 $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
74 // TODO: highlight row after success
75 //$('tr[id="'+record_id+'"]').highlight();
76 mysliceAlert('Success: slice updated','success', true);
78 mysliceAlert('Rest Error for: '+data.error,'warning', true);
80 }); // post update slice
81 emails = slice_users_emails.concat(slice_users_emails_removed);
82 $.post("/credentials/clear/",{'emails':emails}, function(data) {
83 }); // post credentials clear
85 }); // button#addusers click
87 } // get_users_in_slice
89 $(document).ready(function() {
90 // TODO: Add a filter based on the list of authorities
91 $.post("/rest/authority/",{'fields':['authority_hrn']}, function( data ) {
92 var list_authorities = [];
93 $.each( data, function( key, val ) {
94 auth_hrn = val.authority_hrn;
95 // Keep only the sub authorities, remove root auth
96 if(auth_hrn.indexOf(".") > -1){
97 list_authorities.push(auth_hrn);
98 list_authorities.sort();
99 if(auth_hrn=="{{user_details.parent_authority}}"){
100 $('#auth_list').val(auth_hrn);
104 $( "#auth_list" ).autocomplete({
105 source: list_authorities,
107 select: function (event, ui) {
108 get_users_in_slice(ui.item.value);
110 //select: function( event, ui ) {console.log(jQuery(this))}
112 }); // post rest/authority
114 get_users_in_slice("{{user_details.parent_authority}}");
116 $('[title!=""]').qtip();
117 }); // document ready
120 <div class="col-md-2">
121 <div id="select-platform" class="list-group">
124 <ul class="list-group">
125 <li class="list-group-item">Authority</li>
126 <li class="list-group-item" style="padding-left:5px;">
127 <input type="text" id="auth_list" style ="min-width:190px;"
128 title="The default value is the authority that you belong to and the selected users belong to this slice.
129 You can view users of other authorities (organizations) from the list that apears when you click in the field and start to type.
130 Use the arrow keys to scroll through the list; type part of the name to narrow down the list."/>
135 <div class="col-md-10">
138 <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Useres" /></div>
139 <div id="user-tab-loaded" style="display:none;">
140 <table id="user-tab" class="table">
143 <!-- XXX TODO: for the moment only PIs have access to Update but users that have slice credentials should also have access to that -->
145 <button id="addusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> Update users</button>