remove item in the trash bin view after successful undelete
This commit is contained in:
parent
d605228937
commit
a3da82261b
|
@ -7,7 +7,8 @@ if(!OC_User::isLoggedIn()) {
|
||||||
$timestamp = isset( $_REQUEST['timestamp'] ) ? $_REQUEST['timestamp'] : '';
|
$timestamp = isset( $_REQUEST['timestamp'] ) ? $_REQUEST['timestamp'] : '';
|
||||||
$filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : '';
|
$filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : '';
|
||||||
|
|
||||||
OCA_Trash\Trashbin::restore($filename, $timestamp);
|
if ( OCA_Trash\Trashbin::restore($filename, $timestamp) ) {
|
||||||
|
OCP\JSON::success(array("data" => array('filename'=>$filename, 'timestamp' => $timestamp)));
|
||||||
//TODO: return useful data after succsessful restore operation and remove restored files from the list view
|
} else {
|
||||||
OCP\JSON::success(array("data" => array('content'=>'foo', 'id' => 'bar')));
|
OCP\JSON::error(array("data" => array("message" => "Couldn't restore ".$filename)));
|
||||||
|
}
|
||||||
|
|
|
@ -12,20 +12,12 @@ $(document).ready(function() {
|
||||||
if (typeof FileActions !== 'undefined') {
|
if (typeof FileActions !== 'undefined') {
|
||||||
FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) {
|
FileActions.register('all', 'Undelete', OC.PERMISSION_READ, '', function(filename) {
|
||||||
var tr=$('tr').filterAttr('data-file', 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'),
|
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
|
||||||
{timestamp:tr.attr('data-timestamp'),filename:tr.attr('data-filename')},
|
{timestamp:tr.attr('data-timestamp'),filename:tr.attr('data-filename')},
|
||||||
function(result){
|
function(result){
|
||||||
if (result.status == 'success') {
|
if (result.status == 'success') {
|
||||||
return;
|
var row = document.getElementById(result.data.filename+'.d'+result.data.timestamp);
|
||||||
var date=new Date();
|
row.parentNode.removeChild(row);
|
||||||
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 {
|
} else {
|
||||||
OC.dialogs.alert(result.data.message, 'Error');
|
OC.dialogs.alert(result.data.message, 'Error');
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@ class Trashbin {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if location no longer exists, restore file in the root directory
|
||||||
$location = $result[0]['location'];
|
$location = $result[0]['location'];
|
||||||
if ( $result[0]['location'] != '/' && !$view->is_dir('files'.$result[0]['location']) ) {
|
if ( $result[0]['location'] != '/' && !$view->is_dir('files'.$result[0]['location']) ) {
|
||||||
$location = '/';
|
$location = '/';
|
||||||
|
@ -95,23 +96,29 @@ class Trashbin {
|
||||||
$source = 'files_trashbin/'.$filename.'.d'.$timestamp;
|
$source = 'files_trashbin/'.$filename.'.d'.$timestamp;
|
||||||
$target = \OC_Filesystem::normalizePath('files/'.$location.'/'.$filename);
|
$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);
|
$ext = self::getUniqueExtension($location, $filename, $view);
|
||||||
|
|
||||||
$view->rename($source, $target.$ext);
|
if( $view->rename($source, $target.$ext) ) {
|
||||||
|
|
||||||
if ( \OCP\App::isEnabled('files_versions') ) {
|
// if versioning app is enabled, copy versions from the trash bin back to the original location
|
||||||
if ( $result[0][type] == 'dir' ) {
|
if ( $return && \OCP\App::isEnabled('files_versions') ) {
|
||||||
$view->rename('versions_trashbin/'. $filename.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext);
|
if ( $result[0][type] == 'dir' ) {
|
||||||
} else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) {
|
$view->rename('versions_trashbin/'. $filename.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext);
|
||||||
foreach ($versions as $v) {
|
} else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) {
|
||||||
$view->rename('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
|
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=?');
|
return false;
|
||||||
$query->execute(array($user,$filename,$timestamp));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
$name = str_replace('%2F', '/', $name);
|
$name = str_replace('%2F', '/', $name);
|
||||||
$directory = str_replace('+', '%20', urlencode($file['directory']));
|
$directory = str_replace('+', '%20', urlencode($file['directory']));
|
||||||
$directory = str_replace('%2F', '/', $directory); ?>
|
$directory = str_replace('%2F', '/', $directory); ?>
|
||||||
<tr data-file="<?php echo $file['name'].'.d'.$file['timestamp'];?>"
|
<tr id="<?php echo $file['name'].'.d'.$file['timestamp'];?>"
|
||||||
|
data-file="<?php echo $file['name'].'.d'.$file['timestamp'];?>"
|
||||||
data-filename="<?php echo $file['name'];?>"
|
data-filename="<?php echo $file['name'];?>"
|
||||||
data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>"
|
data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>"
|
||||||
data-mime="<?php echo $file['mimetype']?>"
|
data-mime="<?php echo $file['mimetype']?>"
|
||||||
|
|
Loading…
Reference in New Issue