Do not send file list for select all on Download/delete
- When all files are selected, do not send the whole file list - Download will trigger download for the parent folder, also works with root - Delete will send "allfiles" to the server that will find the file list or the passed directory by itself
This commit is contained in:
parent
30662fa7ac
commit
d5397d813c
|
@ -9,8 +9,21 @@ OCP\JSON::callCheck();
|
||||||
// Get data
|
// Get data
|
||||||
$dir = stripslashes($_POST["dir"]);
|
$dir = stripslashes($_POST["dir"]);
|
||||||
$files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
|
$files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
|
||||||
|
$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : $_POST["allfiles"];
|
||||||
|
if ($allFiles === 'true') {
|
||||||
|
$allFiles = true;
|
||||||
|
}
|
||||||
|
|
||||||
$files = json_decode($files);
|
// delete all files in dir ?
|
||||||
|
if ($allFiles) {
|
||||||
|
$files = array();
|
||||||
|
$fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
|
||||||
|
foreach ($fileList as $fileInfo) {
|
||||||
|
$files[] = $fileInfo['name'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$files = json_decode($files);
|
||||||
|
}
|
||||||
$filesWithError = '';
|
$filesWithError = '';
|
||||||
|
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
|
@ -582,30 +582,49 @@ window.FileList={
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
do_delete:function(files) {
|
do_delete:function(files, dir) {
|
||||||
if (files.substr) {
|
var params;
|
||||||
|
if (files && files.substr) {
|
||||||
files=[files];
|
files=[files];
|
||||||
}
|
}
|
||||||
for (var i=0; i<files.length; i++) {
|
if (files) {
|
||||||
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
|
for (var i=0; i<files.length; i++) {
|
||||||
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
|
||||||
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Finish any existing actions
|
// Finish any existing actions
|
||||||
if (FileList.lastAction) {
|
if (FileList.lastAction) {
|
||||||
FileList.lastAction();
|
FileList.lastAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileNames = JSON.stringify(files);
|
var params = {
|
||||||
|
dir: dir || FileList.getCurrentDirectory()
|
||||||
|
};
|
||||||
|
if (files) {
|
||||||
|
params.files = JSON.stringify(files);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// no files passed, delete all in current dir
|
||||||
|
params.allfiles = true;
|
||||||
|
}
|
||||||
|
|
||||||
$.post(OC.filePath('files', 'ajax', 'delete.php'),
|
$.post(OC.filePath('files', 'ajax', 'delete.php'),
|
||||||
{dir:$('#dir').val(),files:fileNames},
|
params,
|
||||||
function(result) {
|
function(result) {
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') {
|
||||||
$.each(files,function(index,file) {
|
if (params.allfiles) {
|
||||||
var files = FileList.findFileEl(file);
|
// clear whole list
|
||||||
files.remove();
|
$('#fileList tr').remove();
|
||||||
files.find('input[type="checkbox"]').removeAttr('checked');
|
}
|
||||||
files.removeClass('selected');
|
else {
|
||||||
});
|
$.each(files,function(index,file) {
|
||||||
|
var files = FileList.findFileEl(file);
|
||||||
|
files.remove();
|
||||||
|
files.find('input[type="checkbox"]').removeAttr('checked');
|
||||||
|
files.removeClass('selected');
|
||||||
|
});
|
||||||
|
}
|
||||||
procesSelection();
|
procesSelection();
|
||||||
checkTrashStatus();
|
checkTrashStatus();
|
||||||
FileList.updateFileSummary();
|
FileList.updateFileSummary();
|
||||||
|
@ -622,10 +641,17 @@ window.FileList={
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
OC.Notification.hide();
|
OC.Notification.hide();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
$.each(files,function(index,file) {
|
if (params.allfiles) {
|
||||||
var deleteAction = FileList.findFileEl(file).find('.action.delete');
|
// reload the page as we don't know what files were deleted
|
||||||
deleteAction.removeClass('progress-icon').addClass('delete-icon');
|
// and which ones remain
|
||||||
});
|
FileList.reload();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$.each(files,function(index,file) {
|
||||||
|
var deleteAction = FileList.findFileEl(file).find('.action.delete');
|
||||||
|
deleteAction.removeClass('progress-icon').addClass('delete-icon');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -794,6 +820,13 @@ window.FileList={
|
||||||
$(e).removeClass("searchresult");
|
$(e).removeClass("searchresult");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Returns whether all files are selected
|
||||||
|
* @return true if all files are selected, false otherwise
|
||||||
|
*/
|
||||||
|
isAllSelected: function() {
|
||||||
|
return $('#select_all').prop('checked');
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the download URL of the given file
|
* Returns the download URL of the given file
|
||||||
|
@ -801,10 +834,13 @@ window.FileList={
|
||||||
* @param dir optional directory in which the file name is, defaults to the current directory
|
* @param dir optional directory in which the file name is, defaults to the current directory
|
||||||
*/
|
*/
|
||||||
getDownloadUrl: function(filename, dir) {
|
getDownloadUrl: function(filename, dir) {
|
||||||
|
var files = filename;
|
||||||
|
if ($.isArray(filename)) {
|
||||||
|
files = JSON.stringify(filename);
|
||||||
|
}
|
||||||
var params = {
|
var params = {
|
||||||
files: filename,
|
|
||||||
dir: dir || FileList.getCurrentDirectory(),
|
dir: dir || FileList.getCurrentDirectory(),
|
||||||
download: null
|
files: files
|
||||||
};
|
};
|
||||||
return OC.filePath('files', 'ajax', 'download.php') + '?' + OC.buildQueryString(params);
|
return OC.filePath('files', 'ajax', 'download.php') + '?' + OC.buildQueryString(params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,23 +364,26 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.download').click('click',function(event) {
|
$('.download').click('click',function(event) {
|
||||||
var files=getSelectedFilesTrash('name');
|
var files;
|
||||||
var fileslist = JSON.stringify(files);
|
var dir = FileList.getCurrentDirectory();
|
||||||
var dir=$('#dir').val()||'/';
|
if (FileList.isAllSelected()) {
|
||||||
OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
|
files = OC.basename(dir);
|
||||||
// use special download URL if provided, e.g. for public shared files
|
dir = OC.dirname(dir) || '/';
|
||||||
var downloadURL = document.getElementById("downloadURL");
|
|
||||||
if ( downloadURL ) {
|
|
||||||
window.location = downloadURL.value+"&download&files=" + encodeURIComponent(fileslist);
|
|
||||||
} else {
|
|
||||||
window.location = OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist });
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
files = getSelectedFilesTrash('name');
|
||||||
|
}
|
||||||
|
OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
|
||||||
|
OC.redirect(FileList.getDownloadUrl(files, dir));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.delete-selected').click(function(event) {
|
$('.delete-selected').click(function(event) {
|
||||||
var files=getSelectedFilesTrash('name');
|
var files=getSelectedFilesTrash('name');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (FileList.isAllSelected()) {
|
||||||
|
files = null;
|
||||||
|
}
|
||||||
FileList.do_delete(files);
|
FileList.do_delete(files);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -69,7 +69,7 @@ describe('FileActions tests', function() {
|
||||||
$tr.find('.action[data-action=Download]').click();
|
$tr.find('.action[data-action=Download]').click();
|
||||||
|
|
||||||
expect(redirectStub.calledOnce).toEqual(true);
|
expect(redirectStub.calledOnce).toEqual(true);
|
||||||
expect(redirectStub.getCall(0).args[0]).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?files=test%20download%20File.txt&dir=%2Fsubdir&download');
|
expect(redirectStub.getCall(0).args[0]).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=test%20download%20File.txt');
|
||||||
redirectStub.restore();
|
redirectStub.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,8 +58,15 @@ describe('FileList tests', function() {
|
||||||
expect($tr.attr('data-permissions')).toEqual('31');
|
expect($tr.attr('data-permissions')).toEqual('31');
|
||||||
//expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
|
//expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
|
||||||
});
|
});
|
||||||
it('returns correct download URL', function() {
|
describe('Download Url', function() {
|
||||||
expect(FileList.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?files=some%20file.txt&dir=%2Fsubdir&download');
|
it('returns correct download URL for single files', function() {
|
||||||
expect(FileList.getDownloadUrl('some file.txt', '/anotherpath/abc')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?files=some%20file.txt&dir=%2Fanotherpath%2Fabc&download');
|
expect(FileList.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=some%20file.txt');
|
||||||
|
expect(FileList.getDownloadUrl('some file.txt', '/anotherpath/abc')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fanotherpath%2Fabc&files=some%20file.txt');
|
||||||
|
$('#dir').val('/');
|
||||||
|
expect(FileList.getDownloadUrl('some file.txt')).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=some%20file.txt');
|
||||||
|
});
|
||||||
|
it('returns correct download URL for multiple files', function() {
|
||||||
|
expect(FileList.getDownloadUrl(['a b c.txt', 'd e f.txt'])).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3
|
||||||
|
* or later.
|
||||||
|
*
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* global OC, FileList, FileActions */
|
||||||
|
|
||||||
// Override download path to files_sharing/public.php
|
// Override download path to files_sharing/public.php
|
||||||
function fileDownloadPath(dir, file) {
|
function fileDownloadPath(dir, file) {
|
||||||
var url = $('#downloadURL').val();
|
var url = $('#downloadURL').val();
|
||||||
|
@ -28,12 +40,20 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// override since the format is different
|
// override since the format is different
|
||||||
FileList.getDownloadUrl = function(filename, dir) {
|
FileList.getDownloadUrl = function(filename, dir) {
|
||||||
// we use this because we need the service and token attributes
|
if ($.isArray(filename)) {
|
||||||
var tr = FileList.findFileEl(filename);
|
filename = JSON.stringify(filename);
|
||||||
if (tr.length > 0) {
|
|
||||||
return $(tr).find('a.name').attr('href') + '&download';
|
|
||||||
}
|
}
|
||||||
return null;
|
var path = dir || FileList.getCurrentDirectory();
|
||||||
|
var params = {
|
||||||
|
service: 'files',
|
||||||
|
t: $('#sharingToken').val(),
|
||||||
|
path: path,
|
||||||
|
download: null
|
||||||
|
};
|
||||||
|
if (filename) {
|
||||||
|
params.files = filename;
|
||||||
|
}
|
||||||
|
return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,12 @@ class OC_Files {
|
||||||
if ($xsendfile) {
|
if ($xsendfile) {
|
||||||
$filename = OC_Helper::moveToNoClean($filename);
|
$filename = OC_Helper::moveToNoClean($filename);
|
||||||
}
|
}
|
||||||
$name = $files . '.zip';
|
// downloading root ?
|
||||||
|
if ($files === '') {
|
||||||
|
$name = 'download.zip';
|
||||||
|
} else {
|
||||||
|
$name = $files . '.zip';
|
||||||
|
}
|
||||||
set_time_limit($executionTime);
|
set_time_limit($executionTime);
|
||||||
} else {
|
} else {
|
||||||
$zip = false;
|
$zip = false;
|
||||||
|
@ -198,6 +203,8 @@ class OC_Files {
|
||||||
$dirname=basename($dir);
|
$dirname=basename($dir);
|
||||||
$zip->addEmptyDir($internalDir.$dirname);
|
$zip->addEmptyDir($internalDir.$dirname);
|
||||||
$internalDir.=$dirname.='/';
|
$internalDir.=$dirname.='/';
|
||||||
|
// prevent absolute dirs
|
||||||
|
$internalDir = ltrim($internalDir, '/');
|
||||||
$files=OC_Files::getDirectoryContent($dir);
|
$files=OC_Files::getDirectoryContent($dir);
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
$filename=$file['name'];
|
$filename=$file['name'];
|
||||||
|
|
Loading…
Reference in New Issue