provide undo button when deleting files from the web interface

This commit is contained in:
Robin Appelman 2011-08-04 00:22:44 +02:00
parent 4851a55c1d
commit e209511f86
5 changed files with 79 additions and 60 deletions

View File

@ -52,3 +52,16 @@ table thead.fixed {height:2em}
/* add breadcrumb divider to the File item in navigation panel */
#navigation>ul>li:first-child { background:url('../../core/img/breadcrumb-divider-start.png') no-repeat 12.5em 0px; width:12.5em; padding-right:1em; }
#notification{
z-index:150;
border-radius:10px;
background-color:#eee;
border:1px solid #ccc;
padding-left:1em;
padding-right:1em;
display:none;
position:fixed;
top:2.8em;
left:40%;
}

View File

@ -118,29 +118,7 @@ FileActions.register('all','Download',OC.imagePath('core','actions/download'),fu
});
FileActions.register('all','Delete',OC.imagePath('core','actions/delete'),function(filename){
$( "#delete-confirm" ).dialog({
resizable: false,
height:200,
title:"Delete "+filename,
modal: true,
buttons: {
"Delete": function() {
$( this ).dialog( "close" );
$.ajax({
url: 'ajax/delete.php',
data: "dir="+encodeURIComponent($('#dir').val())+"&file="+encodeURIComponent(filename),
complete: function(data){
boolOperationFinished(data, function(){
FileList.remove(filename);
});
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
FileList.delete(filename);
});
FileActions.register('all','Rename',OC.imagePath('core','actions/rename'),function(filename){

View File

@ -149,5 +149,66 @@ FileList={
input.blur(function(){
form.trigger('submit');
});
},
delete:function(files){
if(FileList.deleteFiles){//finish any ongoing deletes first
FileList.finishDelete(function(){
FileList.delete(files);
});
return;
}
if(files.substr){
files=[files];
}
$.each(files,function(index,file){
$('tr[data-file="'+file+'"]').hide();
$('tr[data-file="'+file+'"]').find('input[type="checkbox"]').removeAttr('checked');
$('tr[data-file="'+file+'"]').removeClass('selected');
});
procesSelection();
FileList.deleteCanceled=false;
FileList.deleteFiles=files;
$('#notification').text(files.length+' file'+((files.length>1)?'s':'')+' deleted, click here to undo');
$('#notification').show();
},
finishDelete:function(ready,sync){
if(!FileList.deleteCanceled && FileList.deleteFiles){
var fileNames=FileList.deleteFiles.join(';');
$.ajax({
url: 'ajax/delete.php',
async:!sync,
data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(fileNames),
complete: function(data){
boolOperationFinished(data, function(){
$('#notification').hide();
$.each(FileList.deleteFiles,function(index,file){
// alert(file);
FileList.remove(file);
});
FileList.deleteCanceled=true;
FileList.deleteFiles=null;
if(ready){
ready();
}
});
}
});
}
}
}
$(document).ready(function(){
$('#notification').click(function(){
FileList.deleteCanceled=true;
$('#notification').hide();
$.each(FileList.deleteFiles,function(index,file){
$('tr[data-file="'+file+'"]').show();
// alert(file);
});
FileList.deleteFiles=null;
});
$(window).bind('beforeunload', function (){
FileList.finishDelete(null,true);
});
});

View File

@ -92,43 +92,9 @@ $(document).ready(function() {
});
$('.delete').click(function(event) {
var fileNames=getSelectedFiles('name');
var files=fileNames.join(';');
var lastFileName=fileNames.pop();
if(fileNames.length>0){
fileNames=fileNames.join(', ')+' and '+lastFileName;
}else{
fileNames=lastFileName;
}
$( "#delete-confirm" ).dialog({
resizable: false,
height:200,
modal: true,
title:"Delete "+fileNames,
buttons: {
"Delete": function() {
$( this ).dialog( "close" );
$.ajax({
url: 'ajax/delete.php',
data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(files),
complete: function(data){
boolOperationFinished(data, function(){
var files=getSelectedFiles('name');
for(var i=0;i<files.length;i++){
FileList.remove(files[i]);
}
procesSelection();
});
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
var files=getSelectedFiles('name');
event.preventDefault();
FileList.delete(files);
return false;
});

View File

@ -20,6 +20,7 @@
<div id="file_action_panel">
</div>
</div>
<div id='notification'></div>
<table cellspacing="0">
<thead>