clear_creds in slice-user add or remove
[myslice.git] / portal / templates / slice-tab-users-view.html
index 22fd93e..82acd01 100644 (file)
@@ -6,7 +6,10 @@
     function get_users_in_slice(authority_hrn){
         console.log(authority_hrn);
         $("table#user-tab").html("<tr><th>+/-</th><th>Email</th><th>User hrn</th></tr>");
-       var slice_users = [];
+       var slice_users = [];
+       var slice_users_removed = [];
+               var slice_users_emails = [];
+       var slice_users_emails_removed = [];
        $.post("/rest/user/",{'filters':{'parent_authority': authority_hrn}}, function( data ) {
                var list_users = [];
                var table_users = [];
                $("div#user-tab-loading").css("display","none");
             $("input:checkbox.user").click(function() {
                 user_hrn = $(this).closest('tr').find('td:eq(2)').html();
+                user_email = $(this).closest('tr').find('td:eq(1)').html();
                 if(this.checked){
                     var record_id = this.id;
                     slice_users.push (user_hrn);
+                                       slice_users_removed.splice($.inArray(user_hrn, slice_users_removed),1);
+                    slice_users_emails.push (user_email);
+                                       slice_users_emails_removed.splice($.inArray(user_email, slice_users_emails_removed),1); 
+       
                 }else{
-                    console.log(slice_users);
+                    slice_users_removed.push (user_hrn);
+                                       slice_users.splice($.inArray(user_hrn, slice_users),1);
+                    slice_users_emails_removed.push (user_email);
+                                       // this one is removing from the list wrong user when u uncheck
+                                       //slice_users_emails.splice($.inArray(user_email, slice_users_emails),1);
+                                       //this one is still buggy cz it still keeps users in both arrays
+                                       // but it's ok for the moment
+                                       slice_users_emails;
+       
                 }
             });
-       }); // post rest/user
-    }
+       }); // post rest/use
+
+               $('button#addusers').click(function() {
+               $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
+                       if(data.success){
+                       // TODO: highlight row after success
+                       //$('tr[id="'+record_id+'"]').highlight();
+                       mysliceAlert('Success: slice updated','success', true);
+                       }else{
+                       mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                       }
+               }); // post update slice
+                       emails = slice_users_emails.concat(slice_users_emails_removed);
+               $.post("/credentials/clear/",{'emails':emails}, function(data) {
+               }); // post credentials clear
+
+               }); // button#addusers click
+
+    } // get_users_in_slice
 
     $(document).ready(function() {
             // TODO: Add a filter based on the list of authorities
                                $( "#auth_list" ).autocomplete({
                                source: list_authorities,
                                minLength: 0,
-                               change: function (event, ui) {
-                                               get_users_in_slice(this.value); 
-                                       if(!ui.item){
-                               //http://api.jqueryui.com/autocomplete/#event-change -
-                               //The item selected from the menu, if any. Otherwise the property is null
-                               //so clear the item for force selection
-                                       jQuery("#auth_list").val("");
-                                       }
+                               select: function (event, ui) {
+                                               get_users_in_slice(ui.item.value);
                                }
                                //select: function( event, ui ) {console.log(jQuery(this))}
                        });
 
             get_users_in_slice("{{user_details.parent_authority}}");
 
-               $('button#addusers').click(function() {
-                $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
-                       if(data.success){
-                       // TODO: highlight row after success
-                       //$('tr[id="'+record_id+'"]').highlight();
-                       mysliceAlert('Success: slice updated','success', true);
-                       }else{
-                       mysliceAlert('Rest Error for: '+data.error,'warning', true);
-                       }
-                }); // post update slice
-            
-               // TODO: refresh table
-               //window.location="/portal/institution#slices";
-
-            }); // button#addusers click
        $('[title!=""]').qtip();
     }); // document ready
 </script>
                  <li class="list-group-item">Authority</li>
                  <li class="list-group-item" style="padding-left:5px;">
                        <input type="text" id="auth_list"  style ="min-width:190px;" 
-                       title="This is the authority that you belong to. You can view users of other authorities (organization) from the list that apears when you click in the field and start to type.
-                                Use the arrow keys to scroll through the list; type part of the name to narrow down the list."/>
+                       title="The default value is  the authority that you belong to and the selected users belong to this slice.
+                                  You can view users of other authorities (organizations) from the list that apears when you click in the field and start to type.
+                                  Use the arrow keys to scroll through the list; type part of the name to narrow down the list."/>
           </li>
                </ul>
        
 
                 <!-- XXX TODO: for the moment only PIs have access to Update but users that have slice credentials should also have access to that -->
 
-                               {% if 'is_pi'  in pi %}
                                <button id="addusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> Update users</button>
-                               {%endif%}
                </div>