From 80c8666d3abae0a4004e48ad9f580397e98c6ac0 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 30 Oct 2013 22:34:37 +0100 Subject: Deleting all files in trash now only sends a single flag To prevent having to send the list of all files for deletion, only set a flag "allfiles". This should make it a bit smoother when deleting 5000+ files. Also fixes some "empty trash" message issues. --- apps/files_trashbin/js/filelist.js | 7 ++++++ apps/files_trashbin/js/trash.js | 48 ++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 10 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/filelist.js b/apps/files_trashbin/js/filelist.js index cd5a67ddfe0..f42abb6d029 100644 --- a/apps/files_trashbin/js/filelist.js +++ b/apps/files_trashbin/js/filelist.js @@ -22,3 +22,10 @@ FileList.reload = function(){ FileList.linkTo = function(dir){ return OC.linkTo('files_trashbin', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); } + +FileList.updateEmptyContent = function(){ + var $fileList = $('#fileList'); + var exists = $fileList.find('tr:first').exists(); + $('#emptycontent').toggleClass('hidden', exists); + $('#filestable th').toggleClass('hidden', !exists); +} diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 4e6a1e93fa4..84c23d66992 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -19,6 +19,7 @@ $(document).ready(function() { } enableActions(); FileList.updateFileSummary(); + FileList.updateEmptyContent(); } ); @@ -45,6 +46,7 @@ $(document).ready(function() { } enableActions(); FileList.updateFileSummary(); + FileList.updateEmptyContent(); } ); @@ -122,34 +124,60 @@ $(document).ready(function() { } enableActions(); FileList.updateFileSummary(); + FileList.updateEmptyContent(); } ); }); $('.delete').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 = {}; + if (allFiles) { + params = { + allfiles: true + }; + } + else { + files = getSelectedFiles('file'); + params = { + files: JSON.stringify(files), + dirlisting: getSelectedFiles('dirlisting')[0] + }; + }; disableActions(); - for (var i = 0; i < files.length; i++) { - var deleteAction = $('tr').filterAttr('data-file', files[i]).children("td.date").children(".action.delete"); - deleteAction.removeClass('delete-icon').addClass('progress-icon'); + if (allFiles) { + FileList.showMask(); + } + else { + for (var i = 0; i < files.length; i++) { + var deleteAction = $('tr').filterAttr('data-file', files[i]).children("td.date").children(".action.delete"); + deleteAction.removeClass('delete-icon').addClass('progress-icon'); + } } $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), - {files: fileslist, dirlisting: dirlisting}, + params, 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 (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') { OC.dialogs.alert(result.data.message, t('core', 'Error')); } enableActions(); FileList.updateFileSummary(); + FileList.updateEmptyContent(); } ); -- cgit v1.2.3 From 71589e65d24657a6d61fc22b3c67d5a1f5b1404a Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 29 Nov 2013 16:43:50 +0100 Subject: fix restore from files in sub-folders --- apps/files_trashbin/ajax/undelete.php | 1 + apps/files_trashbin/js/trash.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index e39004cc0d5..876ad269a70 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -13,6 +13,7 @@ $success = array(); $i = 0; foreach ($list as $file) { if ( $dirlisting === '0') { + $file = ltrim($file, '/'); $delimiter = strrpos($file, '.d'); $filename = substr($file, 0, $delimiter); $timestamp = substr($file, $delimiter+2); diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 84c23d66992..2c1af34ccec 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -8,7 +8,7 @@ $(document).ready(function() { deleteAction.removeClass('delete-icon').addClass('progress-icon'); disableActions(); $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), - {files: JSON.stringify([filename]), dirlisting: tr.attr('data-dirlisting')}, + {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); @@ -229,7 +229,7 @@ function getSelectedFiles(property){ elements.each(function(i,element){ var file={ name:$(element).attr('data-filename'), - file:$(element).attr('data-file'), + file:$('#dir').val() + "/" + $(element).attr('data-file'), timestamp:$(element).attr('data-timestamp'), type:$(element).attr('data-type'), dirlisting:$(element).attr('data-dirlisting') -- cgit v1.2.3 From 8ce3ea3e2c0fba2073cc9f279ab14f9d2bdbfdc4 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Dec 2013 11:39:53 +0100 Subject: fix delete files from trash bin --- apps/files_trashbin/ajax/delete.php | 30 ++++++++++++++++-------------- apps/files_trashbin/js/trash.js | 5 +++-- apps/files_trashbin/lib/trashbin.php | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 16 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 5498250dbf5..7b1949e3154 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -6,10 +6,18 @@ OCP\JSON::callCheck(); // "empty trash" command $deleteAll = false; if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){ - $user = \OCP\User::getUser(); - $list = OCA\Files_Trashbin\Helper::getTrashFiles('/'); - $deleteAll = true; - $dirlisting = '0'; + $folder = isset($_POST['dir']) ? $_POST['dir'] : '/'; + if ($folder === '/') { + OCA\Files_Trashbin\Trashbin::deleteAll(); + $list = array(); + } else { + if ( strlen(dirname($folder)) > 1 ) { + $dirlisting = '1'; + } else { + $dirlisting = '0'; + } + $list[] = $folder; + } } else { $files = $_POST['files']; @@ -19,19 +27,13 @@ else { $error = array(); $success = array(); - $i = 0; foreach ($list as $file) { if ( $dirlisting === '0') { - if ($deleteAll) { - $filename = $file['name']; - $timestamp = $file['timestamp']; - } - else { - $delimiter = strrpos($file, '.d'); - $filename = substr($file, 0, $delimiter); - $timestamp = substr($file, $delimiter+2); - } + $file = ltrim($file, '/'); + $delimiter = strrpos($file, '.d'); + $filename = substr($file, 0, $delimiter); + $timestamp = substr($file, $delimiter+2); } else { $filename = $file; $timestamp = null; diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 2c1af34ccec..b157fdf1025 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -35,7 +35,7 @@ $(document).ready(function() { deleteAction.removeClass('delete-icon').addClass('progress-icon'); disableActions(); $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), - {files: JSON.stringify([filename]), dirlisting: tr.attr('data-dirlisting')}, + {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); @@ -136,7 +136,8 @@ $(document).ready(function() { var params = {}; if (allFiles) { params = { - allfiles: true + allfiles: true, + dir: $('#dir').val() }; } else { diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index bb6bdd547a0..48d43b059fa 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -564,6 +564,21 @@ class Trashbin { return $size; } + /** + * @brief delete all files from the trash + */ + public static function deleteAll() { + $user = \OCP\User::getUser(); + $view = new \OC\Files\View('/' . $user); + $view->deleteAll('files_trashbin'); + self::setTrashbinSize($user, 0); + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?'); + $query->execute(array($user)); + + return true; + } + + /** * @brief delete file from trash bin permanently * -- cgit v1.2.3 From ee66db447fc12aed4ef441710a29fab2e03aa47e Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 2 Dec 2013 15:27:40 +0100 Subject: make it possible to select folders --- apps/files_trashbin/css/trash.css | 3 +++ apps/files_trashbin/index.php | 1 + apps/files_trashbin/js/trash.js | 41 +++++------------------------ apps/files_trashbin/lib/helper.php | 2 ++ apps/files_trashbin/templates/part.list.php | 13 +++++---- 5 files changed, 20 insertions(+), 40 deletions(-) create mode 100644 apps/files_trashbin/css/trash.css (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/css/trash.css b/apps/files_trashbin/css/trash.css new file mode 100644 index 00000000000..97819f4e80b --- /dev/null +++ b/apps/files_trashbin/css/trash.css @@ -0,0 +1,3 @@ +#fileList td a.file, #fileList td a.file span { + cursor: default; +} diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index d079af3fb6d..93f385dd30b 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -10,6 +10,7 @@ OCP\Util::addScript('files', 'fileactions'); $tmpl = new OCP\Template('files_trashbin', 'index', 'user'); OCP\Util::addStyle('files', 'files'); +OCP\Util::addStyle('files_trashbin', 'trash'); OCP\Util::addScript('files', 'filelist'); // filelist overrides OCP\Util::addScript('files_trashbin', 'filelist'); diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index b157fdf1025..48e9629f7de 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -66,41 +66,6 @@ $(document).ready(function() { procesSelection(); }); - $('#fileList').on('click', 'td.filename a', function(event) { - if (event.shiftKey) { - event.preventDefault(); - var last = $(lastChecked).parent().parent().prevAll().length; - var first = $(this).parent().parent().prevAll().length; - var start = Math.min(first, last); - var end = Math.max(first, last); - var rows = $(this).parent().parent().parent().children('tr'); - for (var i = start; i < end; i++) { - $(rows).each(function(index) { - if (index == i) { - var checkbox = $(this).children().children('input:checkbox'); - $(checkbox).attr('checked', 'checked'); - $(checkbox).parent().parent().addClass('selected'); - } - }); - } - } - var checkbox = $(this).parent().children('input:checkbox'); - lastChecked = checkbox; - if ($(checkbox).attr('checked')) { - $(checkbox).removeAttr('checked'); - $(checkbox).parent().parent().removeClass('selected'); - $('#select_all').removeAttr('checked'); - } else { - $(checkbox).attr('checked', 'checked'); - $(checkbox).parent().parent().toggleClass('selected'); - var selectedCount = $('td.filename input:checkbox:checked').length; - if (selectedCount == $('td.filename input:checkbox').length) { - $('#select_all').attr('checked', 'checked'); - } - } - procesSelection(); - }); - $('.undelete').click('click', function(event) { event.preventDefault(); var files = getSelectedFiles('file'); @@ -184,6 +149,12 @@ $(document).ready(function() { }); + $('#fileList').on('click', 'td.filename input', function() { + var checkbox = $(this).parent().children('input:checkbox'); + $(checkbox).parent().parent().toggleClass('selected'); + procesSelection(); + }); + $('#fileList').on('click', 'td.filename a', function(event) { var mime = $(this).parent().parent().data('mime'); if (mime !== 'httpd/unix-directory') { diff --git a/apps/files_trashbin/lib/helper.php b/apps/files_trashbin/lib/helper.php index 4f442ee9304..c454b35a5f2 100644 --- a/apps/files_trashbin/lib/helper.php +++ b/apps/files_trashbin/lib/helper.php @@ -44,8 +44,10 @@ class Helper } $files = array(); + $id = 0; foreach ($result as $r) { $i = array(); + $i['id'] = $id++; $i['name'] = $r['id']; $i['date'] = \OCP\Util::formatDate($r['timestamp']); $i['timestamp'] = $r['timestamp']; diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 78709d986ae..c32d9fd54da 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -35,18 +35,21 @@ > - + + + + - + - + - + - + -- cgit v1.2.3