use dav trash api for removing from trashbin
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
dea1e55b62
commit
0c6e154b50
2 changed files with 67 additions and 73 deletions
|
@ -17,12 +17,21 @@ OCA.Trashbin = {};
|
|||
*/
|
||||
OCA.Trashbin.App = {
|
||||
_initialized: false,
|
||||
/** @type {OC.Files.Client} */
|
||||
client: null,
|
||||
|
||||
initialize: function($el) {
|
||||
initialize: function ($el) {
|
||||
if (this._initialized) {
|
||||
return;
|
||||
}
|
||||
this._initialized = true;
|
||||
|
||||
this.client = new OC.Files.Client({
|
||||
host: OC.getHost(),
|
||||
port: OC.getPort(),
|
||||
root: OC.linkToRemoteBase('dav') + '/trashbin/' + OC.getCurrentUser().uid,
|
||||
useHTTPS: OC.getProtocol() === 'https'
|
||||
});
|
||||
var urlParams = OC.Util.History.parseUrlQuery();
|
||||
this.fileList = new OCA.Trashbin.FileList(
|
||||
$('#app-content-trashbin'), {
|
||||
|
@ -31,22 +40,24 @@ OCA.Trashbin.App = {
|
|||
scrollTo: urlParams.scrollto,
|
||||
config: OCA.Files.App.getFilesConfig(),
|
||||
multiSelectMenu: [
|
||||
{
|
||||
name: 'restore',
|
||||
displayName: t('files', 'Restore'),
|
||||
iconClass: 'icon-history',
|
||||
},
|
||||
{
|
||||
name: 'delete',
|
||||
displayName: t('files', 'Delete'),
|
||||
iconClass: 'icon-delete',
|
||||
}
|
||||
]
|
||||
{
|
||||
name: 'restore',
|
||||
displayName: t('files', 'Restore'),
|
||||
iconClass: 'icon-history',
|
||||
},
|
||||
{
|
||||
name: 'delete',
|
||||
displayName: t('files', 'Delete'),
|
||||
iconClass: 'icon-delete',
|
||||
}
|
||||
],
|
||||
client: this.client
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
_createFileActions: function() {
|
||||
_createFileActions: function () {
|
||||
var client = this.client;
|
||||
var fileActions = new OCA.Files.FileActions();
|
||||
fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
|
||||
var dir = context.fileList.getCurrentDirectory();
|
||||
|
@ -62,7 +73,7 @@ OCA.Trashbin.App = {
|
|||
mime: 'all',
|
||||
permissions: OC.PERMISSION_READ,
|
||||
iconClass: 'icon-history',
|
||||
actionHandler: function(filename, context) {
|
||||
actionHandler: function (filename, context) {
|
||||
var fileList = context.fileList;
|
||||
var tr = fileList.findFileEl(filename);
|
||||
var deleteAction = tr.children("td.date").children(".action.delete");
|
||||
|
@ -82,33 +93,34 @@ OCA.Trashbin.App = {
|
|||
mime: 'all',
|
||||
permissions: OC.PERMISSION_READ,
|
||||
iconClass: 'icon-delete',
|
||||
render: function(actionSpec, isDefault, context) {
|
||||
render: function (actionSpec, isDefault, context) {
|
||||
var $actionLink = fileActions._makeActionLink(actionSpec, context);
|
||||
$actionLink.attr('original-title', t('files_trashbin', 'Delete permanently'));
|
||||
$actionLink.children('img').attr('alt', t('files_trashbin', 'Delete permanently'));
|
||||
context.$file.find('td:last').append($actionLink);
|
||||
return $actionLink;
|
||||
},
|
||||
actionHandler: function(filename, context) {
|
||||
actionHandler: function (filename, context) {
|
||||
var fileList = context.fileList;
|
||||
$('.tipsy').remove();
|
||||
var tr = fileList.findFileEl(filename);
|
||||
var deleteAction = tr.children("td.date").children(".action.delete");
|
||||
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
|
||||
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
|
||||
files: JSON.stringify([filename]),
|
||||
dir: fileList.getCurrentDirectory()
|
||||
},
|
||||
_.bind(fileList._removeCallback, fileList)
|
||||
);
|
||||
client.remove('trash/' + filename)
|
||||
.then(
|
||||
fileList._removeCallback.bind(fileList, [filename]),
|
||||
function () {
|
||||
OC.Notification.show(t('files_trashbin', 'Error while removing file from trashbin'));
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
return fileActions;
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#app-content-trashbin').one('show', function() {
|
||||
$(document).ready(function () {
|
||||
$('#app-content-trashbin').one('show', function () {
|
||||
var App = OCA.Trashbin.App;
|
||||
App.initialize($('#app-content-trashbin'));
|
||||
// force breadcrumb init
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
* @param [options] map of options
|
||||
*/
|
||||
var FileList = function($el, options) {
|
||||
this.client = options.client;
|
||||
this.initialize($el, options);
|
||||
};
|
||||
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
|
||||
|
@ -51,12 +52,6 @@
|
|||
* @private
|
||||
*/
|
||||
initialize: function() {
|
||||
this.client = new OC.Files.Client({
|
||||
host: OC.getHost(),
|
||||
port: OC.getPort(),
|
||||
root: OC.linkToRemoteBase('dav') + '/trashbin/' + OC.getCurrentUser().uid,
|
||||
useHTTPS: OC.getProtocol() === 'https'
|
||||
});
|
||||
this.client.addFileInfoParser(function(response, data) {
|
||||
var props = response.propStat[0].properties;
|
||||
return {
|
||||
|
@ -143,15 +138,10 @@
|
|||
this.$el.find('#filestable th').toggleClass('hidden', !exists);
|
||||
},
|
||||
|
||||
_removeCallback: function(result) {
|
||||
if (result.status !== 'success') {
|
||||
OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
|
||||
}
|
||||
|
||||
var files = result.data.success;
|
||||
_removeCallback: function(files) {
|
||||
var $el;
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
$el = this.remove(OC.basename(files[i].filename), {updateSummary: false});
|
||||
$el = this.remove(OC.basename(files[i]), {updateSummary: false});
|
||||
this.fileSummary.remove({type: $el.attr('data-type'), size: $el.attr('data-size')});
|
||||
}
|
||||
this.fileSummary.update();
|
||||
|
@ -208,50 +198,42 @@
|
|||
event.preventDefault();
|
||||
var self = this;
|
||||
var allFiles = this.$el.find('.select-all').is(':checked');
|
||||
var files = [];
|
||||
var params = {};
|
||||
if (allFiles) {
|
||||
params = {
|
||||
allfiles: true,
|
||||
dir: this.getCurrentDirectory()
|
||||
};
|
||||
}
|
||||
else {
|
||||
files = _.pluck(this.getSelectedFiles(), 'name');
|
||||
params = {
|
||||
files: JSON.stringify(files),
|
||||
dir: this.getCurrentDirectory()
|
||||
};
|
||||
var files = _.pluck(this.getSelectedFiles(), 'name');
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var tr = this.findFileEl(files[i]);
|
||||
this.showFileBusyState(tr, true);
|
||||
}
|
||||
|
||||
this.fileMultiSelectMenu.toggleLoading('delete', true);
|
||||
if (allFiles) {
|
||||
this.showMask();
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var deleteAction = this.findFileEl(files[i]).children("td.date").children(".action.delete");
|
||||
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
|
||||
}
|
||||
}
|
||||
|
||||
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
|
||||
params,
|
||||
function(result) {
|
||||
if (allFiles) {
|
||||
if (result.status !== 'success') {
|
||||
OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
|
||||
}
|
||||
return this.client.remove('trash/' + this.getCurrentDirectory())
|
||||
.then(
|
||||
function() {
|
||||
self.hideMask();
|
||||
// simply remove all files
|
||||
self.setFiles([]);
|
||||
},
|
||||
function() {
|
||||
OC.Notification.show(t('files_trashbin', 'Error while emptying trashbin'));
|
||||
}
|
||||
else {
|
||||
self._removeCallback(result);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.fileMultiSelectMenu.toggleLoading('delete', true);
|
||||
var deletePromises = files.map(function(file) {
|
||||
return self.client.remove('trash/' + self.getCurrentDirectory() + '/' + file)
|
||||
.then(
|
||||
function() {
|
||||
self._removeCallback([file]);
|
||||
}
|
||||
);
|
||||
});
|
||||
return Promise.all(deletePromises).then(
|
||||
function() {
|
||||
self.fileMultiSelectMenu.toggleLoading('delete', false);
|
||||
},
|
||||
function() {
|
||||
OC.Notification.show(t('files_trashbin', 'Error while removing files from trashbin'));
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
_onClickFile: function(event) {
|
||||
|
|
Loading…
Reference in a new issue