allow user to delete selected files from the trash bin permanently
This commit is contained in:
parent
9a93db9642
commit
51cef9d8f0
3 changed files with 72 additions and 17 deletions
|
@ -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 {
|
||||
$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');
|
||||
OCP\JSON::error(array("data" => array("message" => $l->t("Couldn't delete %s permanently", array($file)))));
|
||||
$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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loader.gif') +'"></a>';
|
||||
|
@ -113,7 +113,31 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('.delete').click('click',function(event) {
|
||||
console.log("delete selected");
|
||||
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'Delete permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
|
||||
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');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
</th>
|
||||
<th id="headerDate">
|
||||
<span id="modified"><?php echo $l->t( 'Deleted' ); ?></span>
|
||||
<span class="selectedActions">
|
||||
<a href="" class="delete">
|
||||
<?php echo $l->t('Delete')?>
|
||||
<img class="svg" alt="<?php echo $l->t('Delete')?>"
|
||||
src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" />
|
||||
</a>
|
||||
</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
Loading…
Reference in a new issue