Skip to content

Commit

Permalink
Added button to empty trash in one go
Browse files Browse the repository at this point in the history
When people have too many files, it is currently difficult to select
them all since the browser is unresponsive when updating so many
elements.

The empty trash button will send a simple POST request to delete ALL
files in the trashbin.

Fixes #2860
  • Loading branch information
Vincent Petry committed Oct 30, 2013
1 parent c1730d2 commit 90253ab
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
5 changes: 3 additions & 2 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,9 @@ var FileList={
var $fileList = $('#fileList');
var permissions = $('#permissions').val();
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
$('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').exists());
$('#filestable th').toggleClass('hidden', $fileList.find('tr').exists() === false);
var exists = $fileList.find('tr:first').exists();
$('#emptycontent').toggleClass('hidden', !isCreatable || exists);
$('#filestable th').toggleClass('hidden', !exists);
},
showMask: function() {
// in case one was shown before
Expand Down
31 changes: 23 additions & 8 deletions apps/files_trashbin/ajax/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,43 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();

$files = $_POST['files'];
$dirlisting = $_POST['dirlisting'];
$list = json_decode($files);

// "empty trash" command
$deleteAll = false;
if (isset($_POST['deleteall']) and $_POST['deleteall'] === 'true'){
$user = \OCP\User::getUser();
$list = OCA\Files_Trashbin\Helper::getTrashFiles('/');
$deleteAll = true;
$dirlisting = '0';
}
else {
$files = $_POST['files'];
$dirlisting = $_POST['dirlisting'];
$list = json_decode($files);
}
$error = array();
$success = array();


$i = 0;
foreach ($list as $file) {
if ( $dirlisting === '0') {
$delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter);
$timestamp = substr($file, $delimiter+2);
if ($deleteAll) {
$filename = $file['name'];
$timestamp = $file['timestamp'];
}
else {
$delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter);
$timestamp = substr($file, $delimiter+2);
}
} else {
$filename = $file;
$timestamp = null;
}

OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp);
if (!OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) {
$success[$i]['filename'] = $file;
$success[$i]['filename'] = $filename;
$success[$i]['timestamp'] = $timestamp;
$i++;
} else {
Expand Down
6 changes: 6 additions & 0 deletions apps/files_trashbin/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ FileList.reload = function(){
FileList.linkTo = function(dir){
return OC.linkTo('files_trashbin', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
}

FileList.oldUpdateEmptyContent = FileList.updateEmptyContent;
FileList.updateEmptyContent = function(){
FileList.oldUpdateEmptyContent.apply(this, arguments);
$('#trash').prop('disabled', !$('#fileList tr:first').exists());
}
20 changes: 20 additions & 0 deletions apps/files_trashbin/js/trash.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ $(document).ready(function() {
$('#controls').delegate('.crumb:not(.home) a', 'click', onClickBreadcrumb);
});

$('#trash').click(function() {
OC.dialogs.confirm(t('files_trashbin', 'ALL files will be DELETED PERMANENTLY. Are you sure ?'), t('files_trashbin', 'PERMANENT DELETION'), function(answer){
if (!answer){
return;
}
FileList.showMask();
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
{deleteall: true},
function(result) {
FileList.hideMask();
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
FileList.changeDirectory('/', true, true);
}
);
});
return false;
});

FileActions.actions.dir = {
// only keep 'Open' action for navigation
'Open': FileActions.actions.dir.Open
Expand Down
1 change: 1 addition & 0 deletions apps/files_trashbin/templates/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div id="controls">
<?php print_unescaped($_['breadcrumb']); ?>
<div id="file_action_panel"></div>
<input id="trash" type="button" value="<?php p($l->t('Delete ALL files permanently'));?>" class="button" <?php (isset($_['files']) && count($_['files']) === 0 && $_['dirlisting'] === false && !$_['ajaxLoad']) ? p('disabled') : '' ?>></input>
</div>
<div id='notification'></div>

Expand Down

0 comments on commit 90253ab

Please sign in to comment.