From d60522893713df7359d0e02c841f35a65d2186aa Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 18 Jan 2013 13:11:29 +0100 Subject: first version of the trash bin app --- apps/files_trashbin/js/trash.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 apps/files_trashbin/js/trash.js (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js new file mode 100644 index 00000000000..37e9a4bf10d --- /dev/null +++ b/apps/files_trashbin/js/trash.js @@ -0,0 +1,37 @@ +// Override download path to files_sharing/public.php +function fileDownloadPath(dir, file) { + var url = $('#downloadURL').val(); + if (url.indexOf('&path=') != -1) { + url += '/'+file; + } + return url; +} + +$(document).ready(function() { + + if (typeof FileActions !== 'undefined') { + FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) { + var tr=$('tr').filterAttr('data-file', filename); + console.log("tr: " + tr.attr('data-timestamp') + " name: " + name); + $.post(OC.filePath('files_trashbin','ajax','undelete.php'), + {timestamp:tr.attr('data-timestamp'),filename:tr.attr('data-filename')}, + function(result){ + if (result.status == 'success') { + return; + var date=new Date(); + FileList.addFile(name,0,date,false,hidden); + var tr=$('tr').filterAttr('data-file',name); + tr.data('mime','text/plain').data('id',result.data.id); + tr.attr('data-id', result.data.id); + getMimeIcon('text/plain',function(path){ + tr.find('td.filename').attr('style','background-image:url('+path+')'); + }); + } else { + OC.dialogs.alert(result.data.message, 'Error'); + } + }); + + }); + }; + +}); \ No newline at end of file -- cgit v1.2.3 From a3da82261bf03ff4b54b0ebf3836d339fe2d4177 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 18 Jan 2013 14:09:22 +0100 Subject: remove item in the trash bin view after successful undelete --- apps/files_trashbin/ajax/undelete.php | 9 ++++---- apps/files_trashbin/js/trash.js | 12 ++-------- apps/files_trashbin/lib/trash.php | 35 +++++++++++++++++------------ apps/files_trashbin/templates/part.list.php | 3 ++- 4 files changed, 30 insertions(+), 29 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index c5480348285..f55629d695c 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -7,7 +7,8 @@ if(!OC_User::isLoggedIn()) { $timestamp = isset( $_REQUEST['timestamp'] ) ? $_REQUEST['timestamp'] : ''; $filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : ''; -OCA_Trash\Trashbin::restore($filename, $timestamp); - -//TODO: return useful data after succsessful restore operation and remove restored files from the list view -OCP\JSON::success(array("data" => array('content'=>'foo', 'id' => 'bar'))); \ No newline at end of file +if ( OCA_Trash\Trashbin::restore($filename, $timestamp) ) { + OCP\JSON::success(array("data" => array('filename'=>$filename, 'timestamp' => $timestamp))); +} else { + OCP\JSON::error(array("data" => array("message" => "Couldn't restore ".$filename))); +} diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 37e9a4bf10d..b9088944fd4 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -12,20 +12,12 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) { var tr=$('tr').filterAttr('data-file', filename); - console.log("tr: " + tr.attr('data-timestamp') + " name: " + name); $.post(OC.filePath('files_trashbin','ajax','undelete.php'), {timestamp:tr.attr('data-timestamp'),filename:tr.attr('data-filename')}, function(result){ if (result.status == 'success') { - return; - var date=new Date(); - FileList.addFile(name,0,date,false,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.data('mime','text/plain').data('id',result.data.id); - tr.attr('data-id', result.data.id); - getMimeIcon('text/plain',function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); + var row = document.getElementById(result.data.filename+'.d'+result.data.timestamp); + row.parentNode.removeChild(row); } else { OC.dialogs.alert(result.data.message, 'Error'); } diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 384a865ce05..322f5679b7d 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -86,7 +86,8 @@ class Trashbin { \OC_Log::write('files_trashbin', 'trash bin database inconsistent!', OC_Log::ERROR); return false; } - + + // if location no longer exists, restore file in the root directory $location = $result[0]['location']; if ( $result[0]['location'] != '/' && !$view->is_dir('files'.$result[0]['location']) ) { $location = '/'; @@ -95,23 +96,29 @@ class Trashbin { $source = 'files_trashbin/'.$filename.'.d'.$timestamp; $target = \OC_Filesystem::normalizePath('files/'.$location.'/'.$filename); + // we need a extension in case a file/dir with the same name already exists $ext = self::getUniqueExtension($location, $filename, $view); - $view->rename($source, $target.$ext); - - if ( \OCP\App::isEnabled('files_versions') ) { - if ( $result[0][type] == 'dir' ) { - $view->rename('versions_trashbin/'. $filename.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext); - } else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) { - foreach ($versions as $v) { - $view->rename('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + if( $view->rename($source, $target.$ext) ) { + + // if versioning app is enabled, copy versions from the trash bin back to the original location + if ( $return && \OCP\App::isEnabled('files_versions') ) { + if ( $result[0][type] == 'dir' ) { + $view->rename('versions_trashbin/'. $filename.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext); + } else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) { + foreach ($versions as $v) { + $view->rename('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + } } - } + } + + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $query->execute(array($user,$filename,$timestamp)); + + return true; } - - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); - $query->execute(array($user,$filename,$timestamp)); - + + return false; } /** diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index d022854330d..c9a641a2e23 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -24,7 +24,8 @@ $name = str_replace('%2F', '/', $name); $directory = str_replace('+', '%20', urlencode($file['directory'])); $directory = str_replace('%2F', '/', $directory); ?> - Date: Fri, 18 Jan 2013 14:11:55 +0100 Subject: remove unneeded function --- apps/files_trashbin/js/trash.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index b9088944fd4..075dc6c3159 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -1,12 +1,3 @@ -// Override download path to files_sharing/public.php -function fileDownloadPath(dir, file) { - var url = $('#downloadURL').val(); - if (url.indexOf('&path=') != -1) { - url += '/'+file; - } - return url; -} - $(document).ready(function() { if (typeof FileActions !== 'undefined') { -- cgit v1.2.3 From 1255791ef2535aac96889f6be8c8b5b163b45be6 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 18 Jan 2013 17:50:44 +0100 Subject: handle group restore --- apps/files_trashbin/ajax/undelete.php | 33 ++++++-- apps/files_trashbin/css/trash.css | 4 +- apps/files_trashbin/js/trash.js | 135 ++++++++++++++++++++++++++++++-- apps/files_trashbin/lib/trash.php | 2 +- apps/files_trashbin/templates/index.php | 9 +-- 5 files changed, 165 insertions(+), 18 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index f55629d695c..05b5e7a5ee4 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -4,11 +4,34 @@ if(!OC_User::isLoggedIn()) { exit; } -$timestamp = isset( $_REQUEST['timestamp'] ) ? $_REQUEST['timestamp'] : ''; -$filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : ''; +$files = $_REQUEST['files']; +$list = explode(';', $files); -if ( OCA_Trash\Trashbin::restore($filename, $timestamp) ) { - OCP\JSON::success(array("data" => array('filename'=>$filename, 'timestamp' => $timestamp))); +$error = array(); + +$i = 0; +foreach ($list as $file) { + $delimiter = strrpos($file, '.d'); + $filename = substr($file, 0, $delimiter); + $timestamp = substr($file, $delimiter+2); + + if ( !OCA_Trash\Trashbin::restore($filename, $timestamp) ) { + $error[] = $filename; + } else { + $success[$i]['filename'] = $filename; + $success[$i]['timestamp'] = $timestamp; + $i++; + } + +} + +if ( $error ) { + $filelist = ''; + foreach ( $error as $e ) { + $filelist .= $e.', '; + } + OCP\JSON::error(array("data" => array("message" => "Couldn't restore ".rtrim($filelist,', '), "success" => $success, "error" => $error))); } else { - OCP\JSON::error(array("data" => array("message" => "Couldn't restore ".$filename))); + OCP\JSON::success(array("data" => array("success" => $success))); } + diff --git a/apps/files_trashbin/css/trash.css b/apps/files_trashbin/css/trash.css index bd6341c6fb2..e0dd8c6e939 100644 --- a/apps/files_trashbin/css/trash.css +++ b/apps/files_trashbin/css/trash.css @@ -19,12 +19,12 @@ body { color:#fff; } -#header #download { +#header #undelete { font-weight:700; margin-left:2em; } -#header #download img { +#header #undelete img { padding-left:.1em; padding-right:.3em; vertical-align:text-bottom; diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 075dc6c3159..8f3786f15e1 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -1,20 +1,145 @@ + $(document).ready(function() { if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) { var tr=$('tr').filterAttr('data-file', filename); $.post(OC.filePath('files_trashbin','ajax','undelete.php'), - {timestamp:tr.attr('data-timestamp'),filename:tr.attr('data-filename')}, + {files:tr.attr('data-filename')+'.d'+tr.attr('data-timestamp')}, function(result){ - if (result.status == 'success') { - var row = document.getElementById(result.data.filename+'.d'+result.data.timestamp); + for (var i = 0; i < result.data.success.length; i++) { + var row = document.getElementById(result.data.success[i].filename+'.d'+result.data.success[i].timestamp); row.parentNode.removeChild(row); - } else { + } + if (result.status != 'success') { OC.dialogs.alert(result.data.message, 'Error'); } }); }); }; + + // 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(); + }); + + $('td.filename input:checkbox').live('change',function(event) { + if (event.shiftKey) { + 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 selectedCount=$('td.filename input:checkbox:checked').length; + $(this).parent().parent().toggleClass('selected'); + if(!$(this).attr('checked')){ + $('#select_all').attr('checked',false); + }else{ + if(selectedCount==$('td.filename input:checkbox').length){ + $('#select_all').attr('checked',true); + } + } + procesSelection(); + }); + + $('.undelete').click('click',function(event) { + var fileslist=getSelectedFiles('file').join(';'); + $.post(OC.filePath('files_trashbin','ajax','undelete.php'), + {files:fileslist}, + function(result){ + for (var i = 0; i < result.data.success.length; i++) { + var row = document.getElementById(result.data.success[i].filename+'.d'+result.data.success[i].timestamp); + row.parentNode.removeChild(row); + } + if (result.status != 'success') { + OC.dialogs.alert(result.data.message, 'Error'); + } + }); + }); + + +}); -}); \ No newline at end of file +function procesSelection(){ + var selected=getSelectedFiles(); + var selectedFiles=selected.filter(function(el){return el.type=='file'}); + var selectedFolders=selected.filter(function(el){return el.type=='dir'}); + if(selectedFiles.length==0 && selectedFolders.length==0) { + $('#headerName>span.name').text(t('files','Name')); + $('#modified').text(t('files','Deleted')); + $('table').removeClass('multiselect'); + $('.selectedActions').hide(); + } + else { + $('.selectedActions').show(); + var selection=''; + if(selectedFolders.length>0){ + if(selectedFolders.length==1){ + selection+=t('files','1 folder'); + }else{ + selection+=t('files','{count} folders',{count: selectedFolders.length}); + } + if(selectedFiles.length>0){ + selection+=' & '; + } + } + if(selectedFiles.length>0){ + if(selectedFiles.length==1){ + selection+=t('files','1 file'); + }else{ + selection+=t('files','{count} files',{count: selectedFiles.length}); + } + } + $('#headerName>span.name').text(selection); + $('#modified').text(''); + $('table').addClass('multiselect'); + } +} + +/** + * @brief get a list of selected files + * @param string property (option) the property of the file requested + * @return array + * + * possible values for property: name, mime, size and type + * if property is set, an array with that property for each file is returnd + * if it's ommited an array of objects with all properties is returned + */ +function getSelectedFiles(property){ + var elements=$('td.filename input:checkbox:checked').parent().parent(); + var files=[]; + elements.each(function(i,element){ + var file={ + name:$(element).attr('data-filename'), + file:$(element).attr('data-file'), + timestamp:$(element).attr('data-timestamp'), + type:$(element).attr('data-type') + }; + if(property){ + files.push(file[property]); + }else{ + files.push(file); + } + }); + return files; +} \ No newline at end of file diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 1b0b9cef4bd..abfcf847ac4 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -77,7 +77,7 @@ class Trashbin { * @param $timestamp time when the file was deleted */ public static function restore($filename, $timestamp) { - + $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index a412379d533..a9cb216b1f7 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -16,13 +16,12 @@ t( 'Name' ); ?> - - - Download + + t('Undelete')?> - -- cgit v1.2.3 From 81ab0affef47c99239e7bff77e5964788a61aa2a Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 22 Jan 2013 12:00:04 +0100 Subject: allow to restore single files/folder from a deleted folder --- apps/files_trashbin/ajax/undelete.php | 15 ++++-- apps/files_trashbin/index.php | 15 ++++-- apps/files_trashbin/js/trash.js | 8 ++-- apps/files_trashbin/lib/trash.php | 74 +++++++++++++++++++---------- apps/files_trashbin/templates/part.list.php | 16 +++++-- 5 files changed, 87 insertions(+), 41 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 05b5e7a5ee4..5aa6436ae53 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -5,17 +5,24 @@ if(!OC_User::isLoggedIn()) { } $files = $_REQUEST['files']; +$dirlisting = $_REQUEST['dirlisting']; $list = explode(';', $files); $error = array(); $i = 0; foreach ($list as $file) { - $delimiter = strrpos($file, '.d'); - $filename = substr($file, 0, $delimiter); - $timestamp = substr($file, $delimiter+2); + if ( $dirlisting=='0') { + $delimiter = strrpos($file, '.d'); + $filename = substr($file, 0, $delimiter); + $timestamp = substr($file, $delimiter+2); + } else { + $path_parts = pathinfo($file); + $filename = $path_parts['basename']; + $timestamp = null; + } - if ( !OCA_Trash\Trashbin::restore($filename, $timestamp) ) { + if ( !OCA_Trash\Trashbin::restore($file, $filename, $timestamp) ) { $error[] = $filename; } else { $success[$i]['filename'] = $filename; diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 2925223197b..97bb64c6262 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -28,7 +28,6 @@ if ($dir) { $tmp = substr($dir, 0, $pos); $pos = strrpos($tmp, '.d'); $timestamp = substr($tmp,$pos+2); - error_log("timestamp: $timestamp"); $result[] = array( 'id' => $entryName, 'timestamp' => $timestamp, @@ -68,17 +67,23 @@ foreach ($result as $r) { } // Make breadcrumb -$breadcrumb = array('dir' => '', 'name' => 'Trash'); +$breadcrumb = array(array('dir' => '', 'name' => 'Trash')); $pathtohere = ''; foreach (explode('/', $dir) as $i) { - if ($i != '') { + if ($i != '') { + if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) { + error_log("match!"); + $name = $match[1]; + } else { + $name = $i; + } $pathtohere .= '/' . $i; - $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i); + $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); } } $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); -$breadcrumbNav->assign('breadcrumb', array(array('dir' => '', 'name' => 'Trash')), false); +$breadcrumbNav->assign('breadcrumb', $breadcrumb, false); $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=', false); $list = new OCP\Template('files_trashbin', 'part.list', ''); diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 8f3786f15e1..355e25d97dc 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -5,7 +5,7 @@ $(document).ready(function() { FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) { var tr=$('tr').filterAttr('data-file', filename); $.post(OC.filePath('files_trashbin','ajax','undelete.php'), - {files:tr.attr('data-filename')+'.d'+tr.attr('data-timestamp')}, + {files:tr.attr('data-file'), 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+'.d'+result.data.success[i].timestamp); @@ -64,8 +64,9 @@ $(document).ready(function() { $('.undelete').click('click',function(event) { var fileslist=getSelectedFiles('file').join(';'); + var dirlisting=getSelectedFiles('dirlisting')[0]; $.post(OC.filePath('files_trashbin','ajax','undelete.php'), - {files:fileslist}, + {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+'.d'+result.data.success[i].timestamp); @@ -133,7 +134,8 @@ function getSelectedFiles(property){ name:$(element).attr('data-filename'), file:$(element).attr('data-file'), timestamp:$(element).attr('data-timestamp'), - type:$(element).attr('data-type') + type:$(element).attr('data-type'), + dirlisting:$(element).attr('data-dirlisting') }; if(property){ files.push(file[property]); diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index abfcf847ac4..9b891e773bf 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -73,49 +73,63 @@ class Trashbin { /** * restore files from trash bin + * @param $file path to the deleted file * @param $filename name of the file * @param $timestamp time when the file was deleted */ - public static function restore($filename, $timestamp) { + public static function restore($file, $filename, $timestamp) { $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); - $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); - $result = $query->execute(array($user,$filename,$timestamp))->fetchAll(); - - if ( count($result) != 1 ) { - \OC_Log::write('files_trashbin', 'trash bin database inconsistent!', OC_Log::ERROR); - return false; - } - - // if location no longer exists, restore file in the root directory - $location = $result[0]['location']; - if ( $result[0]['location'] != '/' && !$view->is_dir('files'.$result[0]['location']) ) { - $location = '/'; + if ( $timestamp ) { + $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $result = $query->execute(array($user,$filename,$timestamp))->fetchAll(); + if ( count($result) != 1 ) { + \OC_Log::write('files_trashbin', 'trash bin database inconsistent!', OC_Log::ERROR); + return false; + } + + // if location no longer exists, restore file in the root directory + $location = $result[0]['location']; + if ( $result[0]['location'] != '/' && !$view->is_dir('files'.$result[0]['location']) ) { + $location = ''; + } + } else { + $path_parts = pathinfo($filename); + $result[] = array( + 'location' => $path_parts['dirname'], + 'type' => $view->is_dir('/files_trashbin/'.$file) ? 'dir' : 'files', + ); + $location = ''; } - $source = 'files_trashbin/'.$filename.'.d'.$timestamp; + $source = \OC_Filesystem::normalizePath('files_trashbin/'.$file); $target = \OC_Filesystem::normalizePath('files/'.$location.'/'.$filename); // we need a extension in case a file/dir with the same name already exists $ext = self::getUniqueExtension($location, $filename, $view); if( $view->rename($source, $target.$ext) ) { - // if versioning app is enabled, copy versions from the trash bin back to the original location - if ( $return && \OCP\App::isEnabled('files_versions') ) { - if ( $result[0][type] == 'dir' ) { - $view->rename('versions_trashbin/'. $filename.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext); - } else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) { + if ( \OCP\App::isEnabled('files_versions') ) { + if ( $result[0]['type'] == 'dir' ) { + $view->rename(\OC_Filesystem::normalizePath('versions_trashbin/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext)); + } else if ( $versions = self::getVersionsFromTrash($file, $timestamp) ) { foreach ($versions as $v) { - $view->rename('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + if ($timestamp ) { + $view->rename('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + } else { + $view->rename('versions_trashbin/'.$file.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + } } } } - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); - $query->execute(array($user,$filename,$timestamp)); + if ( $timestamp ) { + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $query->execute(array($user,$filename,$timestamp)); + } return true; } @@ -189,12 +203,22 @@ class Trashbin { $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename); $versions = array(); + if ($timestamp ) { // fetch for old versions - $matches = glob( $versionsName.'.v*.d'.$timestamp ); + $matches = glob( $versionsName.'.v*.d'.$timestamp ); + $offset = -strlen($timestamp)-2; + } else { + $matches = glob( $versionsName.'.v*' ); + } foreach( $matches as $ma ) { - $parts = explode( '.v', substr($ma, 0, -strlen($timestamp)-2) ); - $versions[] = ( end( $parts ) ); + if ( $timestamp ) { + $parts = explode( '.v', substr($ma, 0, $offset) ); + $versions[] = ( end( $parts ) ); + } else { + $parts = explode( '.v', $ma ); + $versions[] = ( end( $parts ) ); + } } return $versions; } diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 72359da299c..6faddcf4856 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -24,13 +24,21 @@ $name = str_replace('%2F', '/', $name); $directory = str_replace('+', '%20', urlencode($file['directory'])); $directory = str_replace('%2F', '/', $directory); ?> - ' + + id="" + data-file="" + data-timestamp='' + data-dirlisting=1 + + id="" + data-file="" data-timestamp='' - data-permissions=''> + data-dirlisting=0 + > style="background-image:url()" -- cgit v1.2.3 From 97e69e537441abe1082bada0c96e8947a14a2083 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 22 Jan 2013 12:13:50 +0100 Subject: remove table row in trash bin view after undelete --- apps/files_trashbin/ajax/undelete.php | 2 +- apps/files_trashbin/js/trash.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 5aa6436ae53..178d85ccf38 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -25,7 +25,7 @@ foreach ($list as $file) { if ( !OCA_Trash\Trashbin::restore($file, $filename, $timestamp) ) { $error[] = $filename; } else { - $success[$i]['filename'] = $filename; + $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 355e25d97dc..92a431d495a 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -8,7 +8,7 @@ $(document).ready(function() { {files:tr.attr('data-file'), 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+'.d'+result.data.success[i].timestamp); + var row = document.getElementById(result.data.success[i].filename); row.parentNode.removeChild(row); } if (result.status != 'success') { @@ -69,7 +69,7 @@ $(document).ready(function() { {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+'.d'+result.data.success[i].timestamp); + var row = document.getElementById(result.data.success[i].filename); row.parentNode.removeChild(row); } if (result.status != 'success') { -- cgit v1.2.3 From f919230f63aade2df7b12a9c9ab28c7cd59868d4 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 22 Jan 2013 17:59:33 +0100 Subject: remove inline JavaScript --- apps/files_trashbin/js/part.list.php | 19 +++++++++++++++++++ apps/files_trashbin/templates/part.list.php | 13 +------------ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 apps/files_trashbin/js/part.list.php (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/part.list.php b/apps/files_trashbin/js/part.list.php new file mode 100644 index 00000000000..c4ecd1ca959 --- /dev/null +++ b/apps/files_trashbin/js/part.list.php @@ -0,0 +1,19 @@ + +* This file is licensed under the Affero General Public License version 3 or +* later. +* See the COPYING-README file. +*/ + +// Set the content type to Javascript +header("Content-type: text/javascript"); + +// Disallow caching +header("Cache-Control: no-cache, must-revalidate"); +header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); + +echo " +var disableDownloadActions = true; +var disableSharing = true; +"; diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 205e11c286d..c7783e8a4f5 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -1,15 +1,4 @@ - + Date: Wed, 23 Jan 2013 11:30:42 +0100 Subject: code clean-up --- apps/files_trashbin/index.php | 1 + apps/files_trashbin/js/disableDefaultActions.js | 3 +++ apps/files_trashbin/js/part.list.php | 19 ------------------- apps/files_trashbin/templates/part.list.php | 2 -- 4 files changed, 4 insertions(+), 21 deletions(-) create mode 100644 apps/files_trashbin/js/disableDefaultActions.js delete mode 100644 apps/files_trashbin/js/part.list.php (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index d415ef263ec..20f9cb8daff 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -5,6 +5,7 @@ OCP\User::checkLoggedIn(); OCP\Util::addStyle('files_trashbin', 'trash'); OCP\Util::addScript('files_trashbin', 'trash'); +OCP\Util::addScript('files_trashbin', 'disableDefaultActions'); OCP\Util::addScript('files', 'fileactions'); $tmpl = new OCP\Template('files_trashbin', 'index', 'user'); diff --git a/apps/files_trashbin/js/disableDefaultActions.js b/apps/files_trashbin/js/disableDefaultActions.js new file mode 100644 index 00000000000..56b95407dd3 --- /dev/null +++ b/apps/files_trashbin/js/disableDefaultActions.js @@ -0,0 +1,3 @@ +/* disable download and sharing actions */ +var disableDownloadActions = true; +var disableSharing = true; diff --git a/apps/files_trashbin/js/part.list.php b/apps/files_trashbin/js/part.list.php deleted file mode 100644 index c4ecd1ca959..00000000000 --- a/apps/files_trashbin/js/part.list.php +++ /dev/null @@ -1,19 +0,0 @@ - -* This file is licensed under the Affero General Public License version 3 or -* later. -* See the COPYING-README file. -*/ - -// Set the content type to Javascript -header("Content-type: text/javascript"); - -// Disallow caching -header("Cache-Control: no-cache, must-revalidate"); -header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); - -echo " -var disableDownloadActions = true; -var disableSharing = true; -"; diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index c7783e8a4f5..7d2f09c62c6 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -1,5 +1,3 @@ - - Date: Tue, 29 Jan 2013 10:03:04 +0100 Subject: icons added; empty trash bin message added --- apps/files/js/filelist.js | 2 +- apps/files_trashbin/index.php | 1 + apps/files_trashbin/js/trash.js | 2 +- apps/files_trashbin/lib/trash.php | 2 +- apps/files_trashbin/templates/index.php | 9 ++++----- core/img/actions/undelete.png | Bin 0 -> 680 bytes 6 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 core/img/actions/undelete.png (limited to 'apps/files_trashbin/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 40d75aae932..5cb8849ffea 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -292,7 +292,7 @@ var FileList={ procesSelection(); } }); - }, + } }; $(document).ready(function(){ diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index 20f9cb8daff..2e978ae190b 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -95,6 +95,7 @@ $list->assign('dirlisting', $dirlisting); $list->assign('disableDownloadActions', true); $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage(), false); $tmpl->assign('fileList', $list->fetchPage(), false); +$tmpl->assign('files', $files); $tmpl->assign('dir', OC_Filesystem::normalizePath($view->getAbsolutePath())); $tmpl->printPage(); diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 92a431d495a..553e4cbc6f0 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -2,7 +2,7 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { - FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) { + FileActions.register('all', 'Undelete', OC.PERMISSION_READ, OC.imagePath('core', 'actions/undelete.png'), function(filename) { var tr=$('tr').filterAttr('data-file', filename); $.post(OC.filePath('files_trashbin','ajax','undelete.php'), {files:tr.attr('data-file'), dirlisting:tr.attr('data-dirlisting') }, diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index e81ba12758e..fad96e5222a 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -54,7 +54,7 @@ class Trashbin { self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view); $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)"); - $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user)); + $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user)); if ( \OCP\App::isEnabled('files_versions') ) { if ( $view->is_dir('files_versions'.$file_path) ) { diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index a9cb216b1f7..ebabec2d4d0 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -5,8 +5,8 @@
- -
t('Nothing in here. Upload something!')?>
+ +
t('Nothing in here. Trash bin empty!')?>
@@ -17,9 +17,8 @@ t( 'Name' ); ?> - + Undelete" /> t('Undelete')?> diff --git a/core/img/actions/undelete.png b/core/img/actions/undelete.png new file mode 100644 index 00000000000..9f728252394 Binary files /dev/null and b/core/img/actions/undelete.png differ -- cgit v1.2.3 From a6e5f4b85c0aea807f95347e68f88faf08dfbee1 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 30 Jan 2013 13:01:53 +0100 Subject: some minor improvements --- apps/files_trashbin/ajax/undelete.php | 3 ++- apps/files_trashbin/js/trash.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 178d85ccf38..a7bb5b9de2d 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -1,6 +1,6 @@ Date: Wed, 30 Jan 2013 15:35:24 +0100 Subject: add spinner for undelete operation for visualisation --- apps/files_trashbin/js/trash.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 31d16436b2c..0aa9f8dade2 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -4,6 +4,9 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Undelete', OC.PERMISSION_READ, OC.imagePath('core', 'actions/undelete.png'), function(filename) { var tr=$('tr').filterAttr('data-file', filename); + var spinner = ''; + var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date"); + 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') }, function(result){ @@ -63,8 +66,16 @@ $(document).ready(function() { }); $('.undelete').click('click',function(event) { - var fileslist=getSelectedFiles('file').join(';'); + var spinner = ''; + var files=getSelectedFiles('file'); + var fileslist=files.join(';'); var dirlisting=getSelectedFiles('dirlisting')[0]; + + for (var i in files) { + var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date"); + undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; + } + $.post(OC.filePath('files_trashbin','ajax','undelete.php'), {files:fileslist, dirlisting:dirlisting}, function(result){ -- cgit v1.2.3 From 9ca0a93847dfbf9266f7e76e90c018d4dcff7f5b Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 30 Jan 2013 16:20:13 +0100 Subject: make spinner title translatable --- apps/files/js/filelist.js | 2 +- apps/files_trashbin/js/trash.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 28230409d2b..d0810f70145 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -277,7 +277,7 @@ var FileList={ for (var i in files) { var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date").children(".action.delete"); var oldHTML = deleteAction[0].outerHTML; - var newHTML = ''; + var newHTML = ''; deleteAction[0].outerHTML = newHTML; } // Finish any existing actions diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 0aa9f8dade2..8a407b88a01 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -4,7 +4,7 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Undelete', OC.PERMISSION_READ, OC.imagePath('core', 'actions/undelete.png'), function(filename) { var tr=$('tr').filterAttr('data-file', filename); - var spinner = ''; + var spinner = ''; var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date"); undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; $.post(OC.filePath('files_trashbin','ajax','undelete.php'), @@ -66,7 +66,7 @@ $(document).ready(function() { }); $('.undelete').click('click',function(event) { - var spinner = ''; + var spinner = ''; var files=getSelectedFiles('file'); var fileslist=files.join(';'); var dirlisting=getSelectedFiles('dirlisting')[0]; -- cgit v1.2.3 From 2ddd40ed417b09c6eab5a562eae418623417fc16 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 31 Jan 2013 10:06:02 +0100 Subject: rename 'undelete' to 'restore' --- apps/files_trashbin/js/trash.js | 4 ++-- apps/files_trashbin/templates/index.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 8a407b88a01..3ad0ab04fb9 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -2,9 +2,9 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { - FileActions.register('all', 'Undelete', OC.PERMISSION_READ, OC.imagePath('core', 'actions/undelete.png'), function(filename) { + FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/undelete.png'), function(filename) { var tr=$('tr').filterAttr('data-file', filename); - var spinner = ''; + var spinner = ''; var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date"); undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; $.post(OC.filePath('files_trashbin','ajax','undelete.php'), diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index 104d93ce496..c3e51b4becd 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -17,9 +17,9 @@ t( 'Name' ); ?> - Undelete" /> - t('Undelete')?> + t('Restore')?> -- cgit v1.2.3