]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added undo functionality to delete user procedure on user settings page
authorSam Tuke <samtuke@owncloud.com>
Wed, 4 Jul 2012 13:28:08 +0000 (14:28 +0100)
committerSam Tuke <samtuke@owncloud.com>
Wed, 4 Jul 2012 13:30:42 +0000 (14:30 +0100)
settings/js/users.js
settings/templates/users.php

index c04df81d82fe39694c7ac88f63bc3a4f7a61f6b5..dfa28e4c4cb39a9f40c2c4e002471f0ea5f1978c 100644 (file)
@@ -4,6 +4,72 @@
  * See the COPYING-README file.
  */
 
+UserList={
+       useUndo:true,
+       
+       /**
+        * @brief Initiate user deletion process in UI
+        * @param string uid the user ID to be deleted
+        *
+        * Does not actually delete the user; it sets them for
+        * deletion when the current page is unloaded, at which point 
+        * finishDelete() completes the process. This allows for 'undo'.
+        */
+       do_delete:function( uid ) {
+               
+               UserList.deleteUid = uid;
+               
+               // Set undo flag
+               UserList.deleteCanceled = false;
+               
+               // Hide user in table to reflect deletion
+               $(this).parent().parent().hide();
+               $('tr').filterAttr( 'data-uid', UserList.deleteUid ).hide();
+               
+               // Provide user with option to undo
+               $('#notification').text(t('files','undo delete user'));
+               $('#notification').data('deleteuser',true);
+               $('#notification').fadeIn();
+                       
+       },
+       
+       /**
+        * @brief Delete a user via ajax
+        * @param bool ready whether to use ready() upon completion
+        *
+        * Executes deletion via ajax of user identified by property deleteUid 
+        * if 'undo' has not been used.  Completes the user deletion procedure 
+        * and reflects success in UI.
+        */
+       finishDelete:function( ready ){
+               
+               // Check deletion has not been undone
+               if( !UserList.deleteCanceled && UserList.deleteUid ){
+                       
+                       // Delete user via ajax
+                       $.post(
+                               OC.filePath('settings','ajax','removeuser.php'),
+                               {username:UserList.deleteUid},
+                               function(result){
+                                       
+                                       // Remove undo option, & remove user from table
+                                       boolOperationFinished( 
+                                               data, function(){
+                                                       $('#notification').fadeOut();
+                                                       $('tr').filterAttr( 'data-uid', username ).remove();
+                                                       UserList.deleteCanceled=true;
+                                                       UserList.deleteFiles=null;
+                                                       if( ready ){
+                                                               ready();
+                                                       }
+                                               }
+                                       );
+                               }
+                       );
+               }
+       }
+}
+
 $(document).ready(function(){
        function setQuota(uid,quota,ready){
                $.post(
@@ -61,15 +127,12 @@ $(document).ready(function(){
        });
        
        $('td.remove>img').live('click',function(event){
-               var uid=$(this).parent().parent().data('uid');
-               $.post(
-                       OC.filePath('settings','ajax','removeuser.php'),
-                       {username:uid},
-                       function(result){
-                       
-                       }
-               );
-               $(this).parent().parent().remove();
+               
+               var uid = $(this).parent().parent().data('uid');
+               
+               // Call function for handling delete/undo
+               UserList.do_delete( uid );
+               
        });
        
        $('td.password>img').live('click',function(event){
@@ -222,4 +285,19 @@ $(document).ready(function(){
                        }
                );
        });
+       // Handle undo notifications
+       $('#notification').hide();
+       $('#notification').click(function(){
+               if($('#notification').data('deleteuser'))
+               {
+                       $( 'tr' ).filterAttr( 'data-uid', UserList.deleteUid ).show();
+                       UserList.deleteCanceled=true;
+                       UserList.deleteFiles=null;
+               }
+               $('#notification').fadeOut();
+       });
+       UserList.useUndo=('onbeforeunload' in window)
+       $(window).bind('beforeunload', function (){
+               UserList.finishDelete(null);
+       });
 });
index c042f2664e2955cf26facb546b19b21b071ecbd9..551124245610840f60a4b4a487a4de9e4c39887b 100644 (file)
@@ -52,6 +52,8 @@ foreach($_["groups"] as $group) {
        </div>
 </div>
 
+<div id='notification'></div>
+
 <table data-groups="<?php echo implode(', ',$allGroups);?>">
        <thead>
                <tr>