Merge pull request #5230 from owncloud/trashbin_fixes

Trashbin fixes
This commit is contained in:
Björn Schießle 2013-10-09 08:27:54 -07:00
commit 223adc3167
3 changed files with 130 additions and 151 deletions

View File

@ -5,7 +5,6 @@ OCP\User::checkLoggedIn();
OCP\App::setActiveNavigationEntry('files_index');
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');
@ -15,6 +14,7 @@ OCP\Util::addScript('files', 'filelist');
// filelist overrides
OCP\Util::addScript('files_trashbin', 'filelist');
OCP\Util::addscript('files', 'files');
OCP\Util::addScript('files_trashbin', 'trash');
$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';

View File

@ -3,15 +3,13 @@ $(document).ready(function() {
if (typeof FileActions !== 'undefined') {
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) {
var tr=$('tr').filterAttr('data-file', filename);
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
var undeleteAction = $('tr').filterAttr('data-file',filename).children("td.date");
var files = tr.attr('data-file');
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
var tr = $('tr').filterAttr('data-file', filename);
var deleteAction = $('tr').filterAttr('data-file', filename).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions();
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
{files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') },
function(result){
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
{files: JSON.stringify([filename]), 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);
row.parentNode.removeChild(row);
@ -21,26 +19,23 @@ $(document).ready(function() {
}
enableActions();
FileList.updateFileSummary();
});
}
);
});
};
FileActions.register('all', 'Delete', OC.PERMISSION_READ, function () {
FileActions.register('all', 'Delete', OC.PERMISSION_READ, function() {
return OC.imagePath('core', 'actions/delete');
}, function (filename) {
}, function(filename) {
$('.tipsy').remove();
var tr=$('tr').filterAttr('data-file', filename);
var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete");
var oldHTML = deleteAction[0].outerHTML;
var newHTML = '<img class="move2trash" data-action="Delete" title="'+t('files', 'delete file permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
var files = tr.attr('data-file');
deleteAction[0].outerHTML = newHTML;
var tr = $('tr').filterAttr('data-file', filename);
var deleteAction = $('tr').filterAttr('data-file', filename).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions();
$.post(OC.filePath('files_trashbin','ajax','delete.php'),
{files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') },
function(result){
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
{files: JSON.stringify([filename]), 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);
row.parentNode.removeChild(row);
@ -50,26 +45,28 @@ $(document).ready(function() {
}
enableActions();
FileList.updateFileSummary();
});
}
);
});
// Sets the select_all checkbox behaviour :
$('#select_all').click(function() {
if($(this).attr('checked')){
if ($(this).attr('checked')) {
// Check all
$('td.filename input:checkbox').attr('checked', true);
$('td.filename input:checkbox').parent().parent().addClass('selected');
}else{
} else {
// Uncheck all
$('td.filename input:checkbox').attr('checked', false);
$('td.filename input:checkbox').parent().parent().removeClass('selected');
}
processSelection();
procesSelection();
});
$('td.filename input:checkbox').live('change',function(event) {
$('#fileList').on('click', 'td.filename a', function(event) {
if (event.shiftKey) {
event.preventDefault();
var last = $(lastChecked).parent().parent().prevAll().length;
var first = $(this).parent().parent().prevAll().length;
var start = Math.min(first, last);
@ -77,7 +74,7 @@ $(document).ready(function() {
var rows = $(this).parent().parent().parent().children('tr');
for (var i = start; i < end; i++) {
$(rows).each(function(index) {
if (index === i) {
if (index == i) {
var checkbox = $(this).children().children('input:checkbox');
$(checkbox).attr('checked', 'checked');
$(checkbox).parent().parent().addClass('selected');
@ -85,33 +82,37 @@ $(document).ready(function() {
});
}
}
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);
var checkbox = $(this).parent().children('input:checkbox');
lastChecked = checkbox;
if ($(checkbox).attr('checked')) {
$(checkbox).removeAttr('checked');
$(checkbox).parent().parent().removeClass('selected');
$('#select_all').removeAttr('checked');
} else {
$(checkbox).attr('checked', 'checked');
$(checkbox).parent().parent().toggleClass('selected');
var selectedCount = $('td.filename input:checkbox:checked').length;
if (selectedCount == $('td.filename input:checkbox').length) {
$('#select_all').attr('checked', 'checked');
}
}
processSelection();
procesSelection();
});
$('.undelete').click('click',function(event) {
$('.undelete').click('click', function(event) {
event.preventDefault();
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
var files=getSelectedFiles('file');
var files = getSelectedFiles('file');
var fileslist = JSON.stringify(files);
var dirlisting=getSelectedFiles('dirlisting')[0];
var dirlisting = getSelectedFiles('dirlisting')[0];
disableActions();
for (var i=0; i<files.length; i++) {
var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
for (var i = 0; i < files.length; i++) {
var deleteAction = $('tr').filterAttr('data-file', files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
}
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
{files:fileslist, dirlisting:dirlisting},
function(result){
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.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);
@ -120,26 +121,26 @@ $(document).ready(function() {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
});
FileList.updateFileSummary();
}
);
});
$('.delete').click('click',function(event) {
$('.delete').click('click', function(event) {
event.preventDefault();
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 files = getSelectedFiles('file');
var fileslist = JSON.stringify(files);
var dirlisting=getSelectedFiles('dirlisting')[0];
var dirlisting = getSelectedFiles('dirlisting')[0];
disableActions();
for (var i=0; i<files.length; i++) {
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner;
for (var i = 0; i < files.length; i++) {
var deleteAction = $('tr').filterAttr('data-file', files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
}
$.post(OC.filePath('files_trashbin','ajax','delete.php'),
{files:fileslist, dirlisting:dirlisting},
function(result){
$.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);
@ -148,7 +149,10 @@ $(document).ready(function() {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
}
enableActions();
});
FileList.updateFileSummary();
}
);
});
$('#fileList').on('click', 'td.filename a', function(event) {
@ -182,34 +186,6 @@ $(document).ready(function() {
};
});
function processSelection(){
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){
selection += n('files', '%n folder', '%n folders', selectedFolders.length);
if(selectedFiles.length>0){
selection+=' & ';
}
}
if(selectedFiles.length>0){
selection += n('files', '%n file', '%n files', 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

View File

@ -17,7 +17,9 @@
<thead>
<tr>
<th id='headerName'>
<div id="headerName-container">
<input type="checkbox" id="select_all" />
<label for="select_all"></label>
<span class='name'><?php p($l->t( 'Name' )); ?></span>
<span class='selectedActions'>
<a href="" class="undelete">
@ -26,6 +28,7 @@
<?php p($l->t('Restore'))?>
</a>
</span>
</div>
</th>
<th id="headerDate">
<span id="modified"><?php p($l->t( 'Deleted' )); ?></span>