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

View File

@ -4,15 +4,36 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck(); OCP\JSON::callCheck();
$files = $_POST['files']; $files = $_POST['files'];
$dirlisting = $_POST['dirlisting']; $dir = '/';
$list = json_decode($files); 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(); $error = array();
$success = array(); $success = array();
$i = 0; $i = 0;
foreach ($list as $file) { foreach ($list as $file) {
if ( $dirlisting === '0') { $path = $dir . '/' . $file;
if ($dir === '/') {
$file = ltrim($file, '/'); $file = ltrim($file, '/');
$delimiter = strrpos($file, '.d'); $delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter); $filename = substr($file, 0, $delimiter);
@ -23,9 +44,9 @@ foreach ($list as $file) {
$timestamp = null; $timestamp = null;
} }
if ( !OCA\Files_Trashbin\Trashbin::restore($file, $filename, $timestamp) ) { if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) {
$error[] = $filename; $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 { } else {
$success[$i]['filename'] = $file; $success[$i]['filename'] = $file;
$success[$i]['timestamp'] = $timestamp; $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() { $(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') { if (typeof FileActions !== 'undefined') {
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) { 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"); var deleteAction = tr.children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon'); deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions(); disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
{files: JSON.stringify([$('#dir').val() + '/' + filename]), dirlisting: tr.attr('data-dirlisting')}, files: JSON.stringify([filename]),
function(result) { dir: FileList.getCurrentDirectory()
for (var i = 0; i < result.data.success.length; i++) { },
var row = document.getElementById(result.data.success[i].filename); removeCallback
row.parentNode.removeChild(row);
}
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
FileList.updateFileSummary();
FileList.updateEmptyContent();
}
); );
}); });
}; };
@ -34,22 +48,12 @@ $(document).ready(function() {
var deleteAction = tr.children("td.date").children(".action.delete"); var deleteAction = tr.children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon'); deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions(); disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
{files: JSON.stringify([$('#dir').val() + '/' +filename]), dirlisting: tr.attr('data-dirlisting')}, files: JSON.stringify([filename]),
function(result) { dir: FileList.getCurrentDirectory()
for (var i = 0; i < result.data.success.length; i++) { },
var row = document.getElementById(result.data.success[i].filename); removeCallback
row.parentNode.removeChild(row);
}
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
FileList.updateFileSummary();
FileList.updateEmptyContent();
}
); );
}); });
// Sets the select_all checkbox behaviour : // Sets the select_all checkbox behaviour :
@ -68,28 +72,44 @@ $(document).ready(function() {
$('.undelete').click('click', function(event) { $('.undelete').click('click', function(event) {
event.preventDefault(); event.preventDefault();
var files = getSelectedFiles('file'); var allFiles = $('#select_all').is(':checked');
var fileslist = JSON.stringify(files); var files = [];
var dirlisting = getSelectedFiles('dirlisting')[0]; var params = {};
disableActions(); disableActions();
if (allFiles) {
FileList.showMask();
params = {
allfiles: true,
dir: FileList.getCurrentDirectory()
};
}
else {
files = getSelectedFiles('name');
for (var i = 0; i < files.length; i++) { for (var i = 0; i < files.length; i++) {
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete"); var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon'); deleteAction.removeClass('delete-icon').addClass('progress-icon');
} }
params = {
files: JSON.stringify(files),
dir: FileList.getCurrentDirectory()
};
}
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
{files: fileslist, dirlisting: dirlisting}, params,
function(result) { function(result) {
for (var i = 0; i < result.data.success.length; i++) { if (allFiles) {
var row = document.getElementById(result.data.success[i].filename);
row.parentNode.removeChild(row);
}
if (result.status !== 'success') { if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error')); OC.dialogs.alert(result.data.message, t('core', 'Error'));
} }
FileList.hideMask();
// simply remove all files
FileList.update('');
enableActions(); enableActions();
FileList.updateFileSummary(); }
FileList.updateEmptyContent(); else {
removeCallback(result);
}
} }
); );
}); });
@ -102,16 +122,16 @@ $(document).ready(function() {
if (allFiles) { if (allFiles) {
params = { params = {
allfiles: true, allfiles: true,
dir: $('#dir').val() dir: FileList.getCurrentDirectory()
}; };
} }
else { else {
files = getSelectedFiles('file'); files = getSelectedFiles('name');
params = { params = {
files: JSON.stringify(files), files: JSON.stringify(files),
dirlisting: getSelectedFiles('dirlisting')[0] dir: FileList.getCurrentDirectory()
};
}; };
}
disableActions(); disableActions();
if (allFiles) { if (allFiles) {
@ -128,22 +148,17 @@ $(document).ready(function() {
params, params,
function(result) { function(result) {
if (allFiles) { if (allFiles) {
FileList.hideMask();
// simply remove all files
$('#fileList').empty();
}
else {
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') { if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('core', 'Error')); OC.dialogs.alert(result.data.message, t('core', 'Error'));
} }
FileList.hideMask();
// simply remove all files
FileList.update('');
enableActions(); enableActions();
FileList.updateFileSummary(); }
FileList.updateEmptyContent(); else {
removeCallback(result);
}
} }
); );
@ -208,11 +223,9 @@ function getSelectedFiles(property){
var files=[]; var files=[];
elements.each(function(i,element){ elements.each(function(i,element){
var file={ var file={
name:$(element).attr('data-filename'), name:$(element).attr('data-file'),
file:$('#dir').val() + "/" + $(element).attr('data-file'),
timestamp:$(element).attr('data-timestamp'), timestamp:$(element).attr('data-timestamp'),
type:$(element).attr('data-type'), type:$(element).attr('data-type')
dirlisting:$(element).attr('data-dirlisting')
}; };
if(property){ if(property){
files.push(file[property]); files.push(file[property]);