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'] : '';
|
||||
$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')));
|
||||
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)));
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
$name = str_replace('%2F', '/', $name);
|
||||
$directory = str_replace('+', '%20', urlencode($file['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-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>"
|
||||
data-mime="<?php echo $file['mimetype']?>"
|
||||
|
|
Loading…
Reference in New Issue