Trashbin select all now doesn't send file list

- Fixed "delete" and "restore" actions to not send the file list when
  all files are selected
- When some files are selected, sends the current dir
- Removed "dirListing" attribute as the backend is able to compute the
  value based on the current dir
This commit is contained in:
Vincent Petry 2014-02-17 18:26:29 +01:00
parent d5397d813c
commit 94b3296a71
3 changed files with 109 additions and 79 deletions

View File

@ -2,42 +2,38 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
// "empty trash" command
if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){
$deleteAll = true;
$folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
if ($folder === '/' || $folder === '') {
OCA\Files_Trashbin\Trashbin::deleteAll();
$list = array();
} else {
$dirname = dirname($folder);
if ( $dirname !== '/' && $dirname !== '.' ) {
$dirlisting = '1';
} else {
$dirlisting = '0';
}
$list[] = $folder;
$folder = dirname($folder);
}
}
else {
$deleteAll = false;
$files = $_POST['files'];
$dirlisting = $_POST['dirlisting'];
$list = json_decode($files);
}
$folder = rtrim($folder, '/') . '/';
$error = array();
$success = array();
$i = 0;
foreach ($list as $file) {
if ( $dirlisting === '0') {
if ($folder === '/') {
$file = ltrim($file, '/');
$delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter);
$timestamp = substr($file, $delimiter+2);
} else {
$filename = $file;
$filename = $folder . '/' . $file;
$timestamp = null;
}

View File

@ -4,15 +4,36 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$files = $_POST['files'];
$dirlisting = $_POST['dirlisting'];
$list = json_decode($files);
$dir = '/';
if (isset($_POST['dir'])) {
$dir = rtrim($_POST['dir'], '/'). '/';
}
$allFiles = false;
if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true') {
$allFiles = true;
$list = array();
$dirListing = true;
if ($dir === '' || $dir === '/') {
$dirListing = false;
}
foreach (OCA\Files_Trashbin\Helper::getTrashFiles($dir) as $file) {
$fileName = $file['name'];
if (!$dirListing) {
$fileName .= '.d' . $file['timestamp'];
}
$list[] = $fileName;
}
} else {
$list = json_decode($files);
}
$error = array();
$success = array();
$i = 0;
foreach ($list as $file) {
if ( $dirlisting === '0') {
$path = $dir . '/' . $file;
if ($dir === '/') {
$file = ltrim($file, '/');
$delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter);
@ -23,9 +44,9 @@ foreach ($list as $file) {
$timestamp = null;
}
if ( !OCA\Files_Trashbin\Trashbin::restore($file, $filename, $timestamp) ) {
if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) {
$error[] = $filename;
OC_Log::write('trashbin','can\'t restore ' . $filename, OC_Log::ERROR);
OC_Log::write('trashbin', 'can\'t restore ' . $filename, OC_Log::ERROR);
} else {
$success[$i]['filename'] = $file;
$success[$i]['timestamp'] = $timestamp;

View File

@ -1,5 +1,29 @@
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
/* global OC, t, FileList, FileActions */
$(document).ready(function() {
function removeCallback(result) {
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
var files = result.data.success;
for (var i = 0; i < files.length; i++) {
FileList.findFileEl(OC.basename(files[i].filename)).remove();
}
FileList.updateFileSummary();
FileList.updateEmptyContent();
enableActions();
}
if (typeof FileActions !== 'undefined') {
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) {
@ -7,22 +31,12 @@ $(document).ready(function() {
var deleteAction = tr.children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
{files: JSON.stringify([$('#dir').val() + '/' + filename]), dirlisting: tr.attr('data-dirlisting')},
function(result) {
for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename);
row.parentNode.removeChild(row);
}
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
FileList.updateFileSummary();
FileList.updateEmptyContent();
}
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
files: JSON.stringify([filename]),
dir: FileList.getCurrentDirectory()
},
removeCallback
);
});
};
@ -34,22 +48,12 @@ $(document).ready(function() {
var deleteAction = tr.children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
{files: JSON.stringify([$('#dir').val() + '/' +filename]), dirlisting: tr.attr('data-dirlisting')},
function(result) {
for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename);
row.parentNode.removeChild(row);
}
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
FileList.updateFileSummary();
FileList.updateEmptyContent();
}
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
files: JSON.stringify([filename]),
dir: FileList.getCurrentDirectory()
},
removeCallback
);
});
// Sets the select_all checkbox behaviour :
@ -68,29 +72,45 @@ $(document).ready(function() {
$('.undelete').click('click', function(event) {
event.preventDefault();
var files = getSelectedFiles('file');
var fileslist = JSON.stringify(files);
var dirlisting = getSelectedFiles('dirlisting')[0];
var allFiles = $('#select_all').is(':checked');
var files = [];
var params = {};
disableActions();
for (var i = 0; i < files.length; i++) {
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
if (allFiles) {
FileList.showMask();
params = {
allfiles: true,
dir: FileList.getCurrentDirectory()
};
}
else {
files = getSelectedFiles('name');
for (var i = 0; i < files.length; i++) {
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
}
params = {
files: JSON.stringify(files),
dir: FileList.getCurrentDirectory()
};
}
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
{files: fileslist, dirlisting: dirlisting},
function(result) {
for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename);
row.parentNode.removeChild(row);
}
params,
function(result) {
if (allFiles) {
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
FileList.hideMask();
// simply remove all files
FileList.update('');
enableActions();
FileList.updateFileSummary();
FileList.updateEmptyContent();
}
else {
removeCallback(result);
}
}
);
});
@ -101,17 +121,17 @@ $(document).ready(function() {
var params = {};
if (allFiles) {
params = {
allfiles: true,
dir: $('#dir').val()
allfiles: true,
dir: FileList.getCurrentDirectory()
};
}
else {
files = getSelectedFiles('file');
files = getSelectedFiles('name');
params = {
files: JSON.stringify(files),
dirlisting: getSelectedFiles('dirlisting')[0]
dir: FileList.getCurrentDirectory()
};
};
}
disableActions();
if (allFiles) {
@ -128,22 +148,17 @@ $(document).ready(function() {
params,
function(result) {
if (allFiles) {
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
FileList.hideMask();
// simply remove all files
$('#fileList').empty();
FileList.update('');
enableActions();
}
else {
for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename);
row.parentNode.removeChild(row);
}
removeCallback(result);
}
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
FileList.updateFileSummary();
FileList.updateEmptyContent();
}
);
@ -208,11 +223,9 @@ function getSelectedFiles(property){
var files=[];
elements.each(function(i,element){
var file={
name:$(element).attr('data-filename'),
file:$('#dir').val() + "/" + $(element).attr('data-file'),
name:$(element).attr('data-file'),
timestamp:$(element).attr('data-timestamp'),
type:$(element).attr('data-type'),
dirlisting:$(element).attr('data-dirlisting')
type:$(element).attr('data-type')
};
if(property){
files.push(file[property]);