summaryrefslogtreecommitdiffstats
path: root/settings
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2012-07-04 14:28:08 +0100
committerSam Tuke <samtuke@owncloud.com>2012-07-04 14:30:42 +0100
commit825d92d59c54a5274f94e7058c4458238f9586a3 (patch)
treedec78cb2f353781181f6ec23169bda6dba79c0c3 /settings
parent6d3afb3857f30f69fd883bb3f933568a9e2f4115 (diff)
downloadnextcloud-server-825d92d59c54a5274f94e7058c4458238f9586a3.tar.gz
nextcloud-server-825d92d59c54a5274f94e7058c4458238f9586a3.zip
Added undo functionality to delete user procedure on user settings page
Diffstat (limited to 'settings')
-rw-r--r--settings/js/users.js96
-rw-r--r--settings/templates/users.php2
2 files changed, 89 insertions, 9 deletions
diff --git a/settings/js/users.js b/settings/js/users.js
index c04df81d82f..dfa28e4c4cb 100644
--- a/settings/js/users.js
+++ b/settings/js/users.js
@@ -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);
+ });
});
diff --git a/settings/templates/users.php b/settings/templates/users.php
index c042f2664e2..55112424561 100644
--- a/settings/templates/users.php
+++ b/settings/templates/users.php
@@ -52,6 +52,8 @@ foreach($_["groups"] as $group) {
</div>
</div>
+<div id='notification'></div>
+
<table data-groups="<?php echo implode(', ',$allGroups);?>">
<thead>
<tr>