From 37352bba96033069107ca791b10b71c9505ca5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 18 Feb 2013 18:16:19 +0100 Subject: [PATCH 01/11] close file handler after readdir() --- apps/files_trashbin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index a2d4cc0a44d..5d6b5d94e5c 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -37,7 +37,7 @@ if ($dir) { ); } } - closedir($fullpath); + closedir($dirContent); } else { $dirlisting = false; From 9a93db96421b712d8b8485478db4b84594571c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 10:23:34 +0100 Subject: [PATCH 02/11] remove obsolete variables --- apps/files_trashbin/templates/part.list.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index fe8a71f44e6..2de0d7ee91a 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -1,12 +1,8 @@ 200) $relative_date_color = 200; $name = str_replace('+', '%20', urlencode($file['name'])); $name = str_replace('%2F', '/', $name); From 51cef9d8f06586a4e7d4353cb5d7cc3fcddcf97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 10:24:21 +0100 Subject: [PATCH 03/11] allow user to delete selected files from the trash bin permanently --- apps/files_trashbin/ajax/delete.php | 52 ++++++++++++++++++------- apps/files_trashbin/js/trash.js | 30 ++++++++++++-- apps/files_trashbin/templates/index.php | 7 ++++ 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 7a6bd1342ea..d922fafeb26 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -3,22 +3,46 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -$file = $_REQUEST['file']; +$files = $_REQUEST['files']; +$dirlisting = $_REQUEST['dirlisting']; +$list = explode(';', $files); -$path_parts = pathinfo($file); -if ($path_parts['dirname'] == '.') { - $delimiter = strrpos($file, '.d'); - $filename = substr($file, 0, $delimiter); - $timestamp = substr($file, $delimiter+2); -} else { - $filename = $file; - $timestamp = null; +if (!is_array($list)){ + $list = array($list); } -if (OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp)) { - OCP\JSON::success(array("data" => array("filename" => $file))); -} else { - $l = OC_L10N::get('files_trashbin'); - OCP\JSON::error(array("data" => array("message" => $l->t("Couldn't delete %s permanently", array($file))))); +$error = array(); +$success = array(); + +$i = 0; +foreach ($list as $file) { + if ( $dirlisting=='0') { + $delimiter = strrpos($file, '.d'); + $filename = substr($file, 0, $delimiter); + $timestamp = substr($file, $delimiter+2); + } else { + $filename = $file; + $timestamp = null; + } + + if(OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp)) { + $success[$i]['filename'] = $file; + $success[$i]['timestamp'] = $timestamp; + $i++; + } else { + $error[] = $filename; + } } +if ( $error ) { + $filelist = ''; + foreach ( $error as $e ) { + $filelist .= $e.', '; + } + $l = OC_L10N::get('files_trashbin'); + $message = $l->t("Couldn't restore %s", array(rtrim($filelist, ', '))); + OCP\JSON::error(array("data" => array("message" => $message, + "success" => $success, "error" => $error))); +} else { + OCP\JSON::success(array("data" => array("success" => $success))); +} diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 6c810e4c2bd..1f4be9f15ee 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -34,7 +34,7 @@ $(document).ready(function() { deleteAction[0].outerHTML = newHTML; $.post(OC.filePath('files_trashbin','ajax','delete.php'), - {file:tr.attr('data-file') }, + {files:tr.attr('data-file') }, function(result){ if ( result.status == 'success' ) { var row = document.getElementById(result.data.filename); @@ -88,7 +88,7 @@ $(document).ready(function() { } } processSelection(); - }); + }); $('.undelete').click('click',function(event) { var spinner = ''; @@ -113,7 +113,31 @@ $(document).ready(function() { } }); }); - + + $('.delete').click('click',function(event) { + console.log("delete selected"); + var spinner = ''; + var files=getSelectedFiles('file'); + var fileslist=files.join(';'); + var dirlisting=getSelectedFiles('dirlisting')[0]; + + for (var i in files) { + var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date"); + deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner; + } + + $.post(OC.filePath('files_trashbin','ajax','delete.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); + } + if (result.status != 'success') { + OC.dialogs.alert(result.data.message, 'Error'); + } + }); + }); }); diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index c3e51b4becd..c948c94d552 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -25,6 +25,13 @@ t( 'Deleted' ); ?> + + + t('Delete')?> + <?php echo $l->t('Delete')?>" /> + + From 815e964362192483989113af5c48d947084b5512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 11:49:41 +0100 Subject: [PATCH 04/11] use instead of --- apps/files_trashbin/ajax/undelete.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 6320c1d0827..57f62816749 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -3,8 +3,8 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -$files = $_REQUEST['files']; -$dirlisting = $_REQUEST['dirlisting']; +$files = $_POST['files']; +$dirlisting = $_POST['dirlisting']; $list = explode(';', $files); $error = array(); From ac1b2a74ef33609e5ff99f020bf7d65e6bd56725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 11:50:29 +0100 Subject: [PATCH 05/11] add missing paramenter to post request --- apps/files_trashbin/js/trash.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 1f4be9f15ee..1dfe09feca0 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -34,7 +34,7 @@ $(document).ready(function() { deleteAction[0].outerHTML = newHTML; $.post(OC.filePath('files_trashbin','ajax','delete.php'), - {files:tr.attr('data-file') }, + {files:tr.attr('data-file'), dirlisting:tr.attr('data-dirlisting') }, function(result){ if ( result.status == 'success' ) { var row = document.getElementById(result.data.filename); From e6c39fc3e7e11b22c20df361fb891523e8c89a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 12:14:44 +0100 Subject: [PATCH 06/11] change $_REQUEST to $_POST; fix check if file was successfully deleted --- apps/files_trashbin/ajax/delete.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index d922fafeb26..7684d0465e6 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -3,8 +3,8 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -$files = $_REQUEST['files']; -$dirlisting = $_REQUEST['dirlisting']; +$files = $_POST['files']; +$dirlisting = $_POST['dirlisting']; $list = explode(';', $files); if (!is_array($list)){ @@ -24,8 +24,9 @@ foreach ($list as $file) { $filename = $file; $timestamp = null; } - - if(OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp)) { + + OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp); + if (!OCA\Files_Trashbin\Trashbin::file_exists($filename)) { $success[$i]['filename'] = $file; $success[$i]['timestamp'] = $timestamp; $i++; @@ -40,7 +41,7 @@ if ( $error ) { $filelist .= $e.', '; } $l = OC_L10N::get('files_trashbin'); - $message = $l->t("Couldn't restore %s", array(rtrim($filelist, ', '))); + $message = $l->t("Couldn't delete %s permanently", array(rtrim($filelist, ', '))); OCP\JSON::error(array("data" => array("message" => $message, "success" => $success, "error" => $error))); } else { From 7bfbfe6562a7dbcecdc05b60214a0da83760c4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 12:24:51 +0100 Subject: [PATCH 07/11] initialize $result --- apps/files_trashbin/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 5d6b5d94e5c..d0b3030dbf8 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -16,6 +16,7 @@ OCP\Util::addScript('files', 'filelist'); $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : ''; +$result = array(); if ($dir) { $dirlisting = true; $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_trashbin'); From 211e651d7222085b528cc6e9dc8d060d8ea6a60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 19 Feb 2013 12:38:00 +0100 Subject: [PATCH 08/11] add timestamp to function call; fix trash.js to handle multiple delete operation at once --- apps/files_trashbin/ajax/delete.php | 2 +- apps/files_trashbin/js/trash.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 7684d0465e6..915ad9379f6 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -26,7 +26,7 @@ foreach ($list as $file) { } OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp); - if (!OCA\Files_Trashbin\Trashbin::file_exists($filename)) { + if (!OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) { $success[$i]['filename'] = $file; $success[$i]['timestamp'] = $timestamp; $i++; diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 1dfe09feca0..fc38889dc37 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -36,11 +36,11 @@ $(document).ready(function() { $.post(OC.filePath('files_trashbin','ajax','delete.php'), {files:tr.attr('data-file'), dirlisting:tr.attr('data-dirlisting') }, function(result){ - if ( result.status == 'success' ) { - var row = document.getElementById(result.data.filename); + for (var i = 0; i < result.data.success.length; i++) { + var row = document.getElementById(result.data.success[i].filename); row.parentNode.removeChild(row); - } else { - deleteAction[0].outerHTML = oldHTML; + } + if (result.status != 'success') { OC.dialogs.alert(result.data.message, 'Error'); } }); From 3a364639b7649c12dcdd15e1c0344a35432aedc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 20 Feb 2013 15:17:32 +0100 Subject: [PATCH 09/11] use "|" as delimiter instead of ";", since "|" is not allowed in file/folder names --- apps/files_trashbin/ajax/delete.php | 6 +----- apps/files_trashbin/ajax/undelete.php | 2 +- apps/files_trashbin/js/trash.js | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 915ad9379f6..80382147eb7 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -5,11 +5,7 @@ OCP\JSON::callCheck(); $files = $_POST['files']; $dirlisting = $_POST['dirlisting']; -$list = explode(';', $files); - -if (!is_array($list)){ - $list = array($list); -} +$list = explode('|', $files); $error = array(); $success = array(); diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 57f62816749..b76adb2a2a7 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -5,7 +5,7 @@ OCP\JSON::callCheck(); $files = $_POST['files']; $dirlisting = $_POST['dirlisting']; -$list = explode(';', $files); +$list = explode('|', $files); $error = array(); $success = array(); diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index fc38889dc37..c8b862837a6 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -93,7 +93,7 @@ $(document).ready(function() { $('.undelete').click('click',function(event) { var spinner = ''; var files=getSelectedFiles('file'); - var fileslist=files.join(';'); + var fileslist=files.join('|'); var dirlisting=getSelectedFiles('dirlisting')[0]; for (var i in files) { @@ -118,7 +118,7 @@ $(document).ready(function() { console.log("delete selected"); var spinner = ''; var files=getSelectedFiles('file'); - var fileslist=files.join(';'); + var fileslist=files.join('|'); var dirlisting=getSelectedFiles('dirlisting')[0]; for (var i in files) { From 273e1a146b27e197a7450589594edcb9131e3b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 20 Feb 2013 16:33:45 +0100 Subject: [PATCH 10/11] switch to json encoded file list --- apps/files_trashbin/ajax/delete.php | 2 +- apps/files_trashbin/ajax/undelete.php | 2 +- apps/files_trashbin/js/trash.js | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 80382147eb7..34f35c39ccb 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -5,7 +5,7 @@ OCP\JSON::callCheck(); $files = $_POST['files']; $dirlisting = $_POST['dirlisting']; -$list = explode('|', $files); +$list = json_decode($files); $error = array(); $success = array(); diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index b76adb2a2a7..93f2aaf1fa2 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -5,7 +5,7 @@ OCP\JSON::callCheck(); $files = $_POST['files']; $dirlisting = $_POST['dirlisting']; -$list = explode('|', $files); +$list = json_decode($files); $error = array(); $success = array(); diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index c8b862837a6..3841a098147 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -6,9 +6,10 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file', filename); var spinner = ''; var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date"); + var files = tr.attr('data-file'); undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; $.post(OC.filePath('files_trashbin','ajax','undelete.php'), - {files:tr.attr('data-file'), dirlisting:tr.attr('data-dirlisting') }, + {files:JSON.stringify([files]), 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); @@ -31,10 +32,11 @@ $(document).ready(function() { var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete"); var oldHTML = deleteAction[0].outerHTML; var newHTML = ''; + var files = tr.attr('data-file'); deleteAction[0].outerHTML = newHTML; $.post(OC.filePath('files_trashbin','ajax','delete.php'), - {files:tr.attr('data-file'), dirlisting:tr.attr('data-dirlisting') }, + {files:JSON.stringify([files]), 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); @@ -93,7 +95,7 @@ $(document).ready(function() { $('.undelete').click('click',function(event) { var spinner = ''; var files=getSelectedFiles('file'); - var fileslist=files.join('|'); + var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; for (var i in files) { @@ -118,7 +120,7 @@ $(document).ready(function() { console.log("delete selected"); var spinner = ''; var files=getSelectedFiles('file'); - var fileslist=files.join('|'); + var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; for (var i in files) { From c1847aaf5159200c38eb52693a2d2a84aef5cb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 20 Feb 2013 22:32:44 +0100 Subject: [PATCH 11/11] change for loop to make it hopefully work with IE --- apps/files_trashbin/js/trash.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 3841a098147..94fb4358d37 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -123,7 +123,7 @@ $(document).ready(function() { var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; - for (var i in files) { + for (var i=0; i