allow user to delete selected files from the trash bin permanently

This commit is contained in:
Björn Schießle 2013-02-19 10:24:21 +01:00
parent 9a93db9642
commit 51cef9d8f0
3 changed files with 72 additions and 17 deletions

View file

@ -3,22 +3,46 @@
OCP\JSON::checkLoggedIn(); OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck(); OCP\JSON::callCheck();
$file = $_REQUEST['file']; $files = $_REQUEST['files'];
$dirlisting = $_REQUEST['dirlisting'];
$list = explode(';', $files);
$path_parts = pathinfo($file); if (!is_array($list)){
if ($path_parts['dirname'] == '.') { $list = array($list);
$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)) { $error = array();
OCP\JSON::success(array("data" => array("filename" => $file))); $success = array();
} else {
$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'); $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)));
} }

View file

@ -34,7 +34,7 @@ $(document).ready(function() {
deleteAction[0].outerHTML = newHTML; deleteAction[0].outerHTML = newHTML;
$.post(OC.filePath('files_trashbin','ajax','delete.php'), $.post(OC.filePath('files_trashbin','ajax','delete.php'),
{file:tr.attr('data-file') }, {files:tr.attr('data-file') },
function(result){ function(result){
if ( result.status == 'success' ) { if ( result.status == 'success' ) {
var row = document.getElementById(result.data.filename); var row = document.getElementById(result.data.filename);
@ -88,7 +88,7 @@ $(document).ready(function() {
} }
} }
processSelection(); processSelection();
}); });
$('.undelete').click('click',function(event) { $('.undelete').click('click',function(event) {
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loader.gif') +'"></a>'; 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');
}
});
});
}); });

View file

@ -25,6 +25,13 @@
</th> </th>
<th id="headerDate"> <th id="headerDate">
<span id="modified"><?php echo $l->t( 'Deleted' ); ?></span> <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> </th>
</tr> </tr>
</thead> </thead>