summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-02-12 14:50:23 +0100
committerVincent Petry <pvince81@owncloud.com>2014-04-28 14:55:00 +0200
commit9c2fbea6a4396a29ce8c966c9ea7646aa8fc9be5 (patch)
tree5ec4d52ab001b7078397bc676d8fdac6a3bfdde9 /apps/files_trashbin/js
parent9f62059efa869ff677130f06bf1b46be49950515 (diff)
downloadnextcloud-server-9c2fbea6a4396a29ce8c966c9ea7646aa8fc9be5.tar.gz
nextcloud-server-9c2fbea6a4396a29ce8c966c9ea7646aa8fc9be5.zip
Fix file selection for infinite scrolling
- moved file selection code to FileList - fix selection summary when all files are selected - nextPage now auto-selects files if "select all" checkbox is checked - fixed trashbin to use the same selection logic as FileList
Diffstat (limited to 'apps/files_trashbin/js')
-rw-r--r--apps/files_trashbin/js/filelist.js126
-rw-r--r--apps/files_trashbin/js/trash.js163
2 files changed, 128 insertions, 161 deletions
diff --git a/apps/files_trashbin/js/filelist.js b/apps/files_trashbin/js/filelist.js
index 7795daf2775..6c9b345086a 100644
--- a/apps/files_trashbin/js/filelist.js
+++ b/apps/files_trashbin/js/filelist.js
@@ -75,4 +75,130 @@
$('#emptycontent').toggleClass('hidden', exists);
$('#filestable th').toggleClass('hidden', !exists);
};
+
+ var oldInit = FileList.initialize;
+ FileList.initialize = function() {
+ var result = oldInit.apply(this, arguments);
+ $('.undelete').click('click', FileList._onClickRestoreSelected);
+ return result;
+ };
+
+ FileList._removeCallback = function(result) {
+ if (result.status !== 'success') {
+ OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
+ }
+
+ var files = result.data.success;
+ var $el;
+ for (var i = 0; i < files.length; i++) {
+ $el = FileList.remove(OC.basename(files[i].filename), {updateSummary: false});
+ FileList.fileSummary.remove({type: $el.attr('data-type'), size: $el.attr('data-size')});
+ }
+ FileList.fileSummary.update();
+ FileList.updateEmptyContent();
+ enableActions();
+ }
+
+ FileList._onClickRestoreSelected = function(event) {
+ event.preventDefault();
+ var allFiles = $('#select_all').is(':checked');
+ var files = [];
+ var params = {};
+ disableActions();
+ if (allFiles) {
+ FileList.showMask();
+ params = {
+ allfiles: true,
+ dir: FileList.getCurrentDirectory()
+ };
+ }
+ else {
+ files = FileList.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'),
+ params,
+ function(result) {
+ if (allFiles) {
+ if (result.status !== 'success') {
+ OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
+ }
+ FileList.hideMask();
+ // simply remove all files
+ FileList.update('');
+ enableActions();
+ }
+ else {
+ FileList._removeCallback(result);
+ }
+ }
+ );
+ };
+
+ FileList._onClickDeleteSelected = function(event) {
+ event.preventDefault();
+ var allFiles = $('#select_all').is(':checked');
+ var files = [];
+ var params = {};
+ if (allFiles) {
+ params = {
+ allfiles: true,
+ dir: FileList.getCurrentDirectory()
+ };
+ }
+ else {
+ files = FileList.getSelectedFiles('name');
+ params = {
+ files: JSON.stringify(files),
+ dir: FileList.getCurrentDirectory()
+ };
+ }
+
+ disableActions();
+ if (allFiles) {
+ FileList.showMask();
+ }
+ else {
+ 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');
+ }
+ }
+
+ $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
+ params,
+ function(result) {
+ if (allFiles) {
+ if (result.status !== 'success') {
+ OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
+ }
+ FileList.hideMask();
+ // simply remove all files
+ FileList.setFiles([]);
+ enableActions();
+ }
+ else {
+ FileList._removeCallback(result);
+ }
+ }
+ );
+ };
+
+ var oldClickFile = FileList._onClickFile;
+ FileList._onClickFile = function(event) {
+ var mime = $(this).parent().parent().data('mime');
+ if (mime !== 'httpd/unix-directory') {
+ event.preventDefault();
+ }
+ return oldClickFile.apply(this, arguments);
+ };
+
})();
diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js
index 4ed5ba1c76e..5f2436de809 100644
--- a/apps/files_trashbin/js/trash.js
+++ b/apps/files_trashbin/js/trash.js
@@ -28,22 +28,6 @@ $(document).ready(function() {
return name;
}
- function removeCallback(result) {
- if (result.status !== 'success') {
- OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
- }
-
- var files = result.data.success;
- var $el;
- for (var i = 0; i < files.length; i++) {
- $el = FileList.remove(OC.basename(files[i].filename), {updateSummary: false});
- FileList.fileSummary.remove({type: $el.attr('data-type'), size: $el.attr('data-size')});
- }
- FileList.fileSummary.update();
- FileList.updateEmptyContent();
- enableActions();
- }
-
Files.updateStorageStatistics = function() {
// no op because the trashbin doesn't have
// storage info like free space / used space
@@ -59,7 +43,7 @@ $(document).ready(function() {
files: JSON.stringify([filename]),
dir: FileList.getCurrentDirectory()
},
- removeCallback
+ FileList._removeCallback
);
}, t('files_trashbin', 'Restore'));
};
@@ -76,153 +60,10 @@ $(document).ready(function() {
files: JSON.stringify([filename]),
dir: FileList.getCurrentDirectory()
},
- removeCallback
+ FileList._removeCallback
);
});
- // Sets the select_all checkbox behaviour :
- $('#select_all').click(function() {
- if ($(this).attr('checked')) {
- // Check all
- $('td.filename input:checkbox').attr('checked', true);
- $('td.filename input:checkbox').parent().parent().addClass('selected');
- } else {
- // Uncheck all
- $('td.filename input:checkbox').attr('checked', false);
- $('td.filename input:checkbox').parent().parent().removeClass('selected');
- }
- procesSelection();
- });
- $('.undelete').click('click', function(event) {
- event.preventDefault();
- var allFiles = $('#select_all').is(':checked');
- var files = [];
- var params = {};
- disableActions();
- if (allFiles) {
- FileList.showMask();
- params = {
- allfiles: true,
- dir: FileList.getCurrentDirectory()
- };
- }
- else {
- files = 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'),
- params,
- function(result) {
- if (allFiles) {
- if (result.status !== 'success') {
- OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
- }
- FileList.hideMask();
- // simply remove all files
- FileList.update('');
- enableActions();
- }
- else {
- removeCallback(result);
- }
- }
- );
- });
-
- $('.delete').click('click', function(event) {
- event.preventDefault();
- var allFiles = $('#select_all').is(':checked');
- var files = [];
- var params = {};
- if (allFiles) {
- params = {
- allfiles: true,
- dir: FileList.getCurrentDirectory()
- };
- }
- else {
- files = Files.getSelectedFiles('name');
- params = {
- files: JSON.stringify(files),
- dir: FileList.getCurrentDirectory()
- };
- }
-
- disableActions();
- if (allFiles) {
- FileList.showMask();
- }
- else {
- 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');
- }
- }
-
- $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
- params,
- function(result) {
- if (allFiles) {
- if (result.status !== 'success') {
- OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
- }
- FileList.hideMask();
- // simply remove all files
- FileList.setFiles([]);
- enableActions();
- }
- else {
- removeCallback(result);
- }
- }
- );
-
- });
-
- $('#fileList').on('click', 'td.filename input', function() {
- var checkbox = $(this).parent().children('input:checkbox');
- $(checkbox).parent().parent().toggleClass('selected');
- if ($(checkbox).is(':checked')) {
- var selectedCount = $('td.filename input:checkbox:checked').length;
- if (selectedCount === $('td.filename input:checkbox').length) {
- $('#select_all').prop('checked', true);
- }
- } else {
- $('#select_all').prop('checked',false);
- }
- procesSelection();
- });
-
- $('#fileList').on('click', 'td.filename a', function(event) {
- var mime = $(this).parent().parent().data('mime');
- if (mime !== 'httpd/unix-directory') {
- event.preventDefault();
- }
- var filename = $(this).parent().parent().attr('data-file');
- var tr = FileList.findFileEl(filename);
- var renaming = tr.data('renaming');
- if(!renaming){
- if(mime.substr(0, 5) === 'text/'){ //no texteditor for now
- return;
- }
- var type = $(this).parent().parent().data('type');
- var permissions = $(this).parent().parent().data('permissions');
- var action = FileActions.getDefault(mime, type, permissions);
- if(action){
- event.preventDefault();
- action(filename);
- }
- }
- });
-
/**
* Override crumb URL maker (hacky!)
*/