2014-05-08 20:06:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
2013-10-28 19:22:06 +00:00
|
|
|
(function() {
|
2014-05-08 20:06:30 +00:00
|
|
|
var DELETED_REGEXP = new RegExp(/^(.+)\.d[0-9]+$/);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a file name in the format filename.d12345 to the real file name.
|
|
|
|
* This will use basename.
|
|
|
|
* The name will not be changed if it has no ".d12345" suffix.
|
2014-06-23 21:56:10 +00:00
|
|
|
* @param {String} name file name
|
|
|
|
* @return {String} converted file name
|
2013-10-28 19:22:06 +00:00
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
function getDeletedFileName(name) {
|
2013-10-28 19:22:06 +00:00
|
|
|
name = OC.basename(name);
|
2014-05-08 20:06:30 +00:00
|
|
|
var match = DELETED_REGEXP.exec(name);
|
2013-10-28 19:22:06 +00:00
|
|
|
if (match && match.length > 1) {
|
|
|
|
name = match[1];
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
return name;
|
2014-05-08 20:06:30 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
/**
|
|
|
|
* @class OCA.Trashbin.FileList
|
|
|
|
* @augments OCA.Files.FileList
|
|
|
|
* @classdesc List of deleted files
|
|
|
|
*
|
|
|
|
* @param $el container element with existing markup for the #controls
|
|
|
|
* and a table
|
|
|
|
* @param [options] map of options
|
|
|
|
*/
|
2014-05-20 14:01:34 +00:00
|
|
|
var FileList = function($el, options) {
|
|
|
|
this.initialize($el, options);
|
2013-10-28 19:22:06 +00:00
|
|
|
};
|
2014-06-23 21:56:10 +00:00
|
|
|
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
|
|
|
|
/** @lends OCA.Trashbin.FileList.prototype */ {
|
2014-05-12 17:54:20 +00:00
|
|
|
id: 'trashbin',
|
2014-05-08 20:06:30 +00:00
|
|
|
appName: t('files_trashbin', 'Deleted files'),
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
initialize: function() {
|
|
|
|
var result = OCA.Files.FileList.prototype.initialize.apply(this, arguments);
|
|
|
|
this.$el.find('.undelete').click('click', _.bind(this._onClickRestoreSelected, this));
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
this.setSort('mtime', 'desc');
|
|
|
|
/**
|
|
|
|
* Override crumb making to add "Deleted Files" entry
|
|
|
|
* and convert files with ".d" extensions to a more
|
|
|
|
* user friendly name.
|
|
|
|
*/
|
|
|
|
this.breadcrumb._makeCrumbs = function() {
|
|
|
|
var parts = OCA.Files.BreadCrumb.prototype._makeCrumbs.apply(this, arguments);
|
|
|
|
for (var i = 1; i < parts.length; i++) {
|
|
|
|
parts[i].name = getDeletedFileName(parts[i].name);
|
|
|
|
}
|
|
|
|
return parts;
|
|
|
|
};
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-12-01 15:17:28 +00:00
|
|
|
OC.Plugins.attach('OCA.Trashbin.FileList', this);
|
2014-05-08 20:06:30 +00:00
|
|
|
return result;
|
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
/**
|
|
|
|
* Override to only return read permissions
|
|
|
|
*/
|
|
|
|
getDirectoryPermissions: function() {
|
|
|
|
return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
_setCurrentDir: function(targetDir) {
|
|
|
|
OCA.Files.FileList.prototype._setCurrentDir.apply(this, arguments);
|
2014-02-12 13:50:23 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
var baseDir = OC.basename(targetDir);
|
|
|
|
if (baseDir !== '') {
|
|
|
|
this.setPageTitle(getDeletedFileName(baseDir));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_createRow: function() {
|
|
|
|
// FIXME: MEGAHACK until we find a better solution
|
|
|
|
var tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
|
|
|
|
tr.find('td.filesize').remove();
|
|
|
|
return tr;
|
|
|
|
},
|
|
|
|
|
|
|
|
_renderRow: function(fileData, options) {
|
|
|
|
options = options || {};
|
|
|
|
var dir = this.getCurrentDirectory();
|
|
|
|
var dirListing = dir !== '' && dir !== '/';
|
|
|
|
// show deleted time as mtime
|
|
|
|
if (fileData.mtime) {
|
|
|
|
fileData.mtime = parseInt(fileData.mtime, 10);
|
|
|
|
}
|
|
|
|
if (!dirListing) {
|
|
|
|
fileData.displayName = fileData.name;
|
|
|
|
fileData.name = fileData.name + '.d' + Math.floor(fileData.mtime / 1000);
|
|
|
|
}
|
|
|
|
return OCA.Files.FileList.prototype._renderRow.call(this, fileData, options);
|
|
|
|
},
|
2014-02-12 13:50:23 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
getAjaxUrl: function(action, params) {
|
|
|
|
var q = '';
|
|
|
|
if (params) {
|
|
|
|
q = '?' + OC.buildQueryString(params);
|
|
|
|
}
|
|
|
|
return OC.filePath('files_trashbin', 'ajax', action + '.php') + q;
|
|
|
|
},
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
setupUploadEvents: function() {
|
|
|
|
// override and do nothing
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
linkTo: function(dir){
|
2014-05-12 17:54:20 +00:00
|
|
|
return OC.linkTo('files', 'index.php')+"?view=trashbin&dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
|
2014-05-08 20:06:30 +00:00
|
|
|
},
|
|
|
|
|
2015-08-25 09:29:35 +00:00
|
|
|
elementToFile: function($el) {
|
|
|
|
var fileInfo = OCA.Files.FileList.prototype.elementToFile($el);
|
|
|
|
if (this.getCurrentDirectory() === '/') {
|
|
|
|
fileInfo.displayName = getDeletedFileName(fileInfo.name);
|
|
|
|
}
|
|
|
|
// no size available
|
|
|
|
delete fileInfo.size;
|
|
|
|
return fileInfo;
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
updateEmptyContent: function(){
|
|
|
|
var exists = this.$fileList.find('tr:first').exists();
|
|
|
|
this.$el.find('#emptycontent').toggleClass('hidden', exists);
|
|
|
|
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'));
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
var files = result.data.success;
|
|
|
|
var $el;
|
2014-02-12 13:50:23 +00:00
|
|
|
for (var i = 0; i < files.length; i++) {
|
2014-05-08 20:06:30 +00:00
|
|
|
$el = this.remove(OC.basename(files[i].filename), {updateSummary: false});
|
|
|
|
this.fileSummary.remove({type: $el.attr('data-type'), size: $el.attr('data-size')});
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
this.fileSummary.update();
|
|
|
|
this.updateEmptyContent();
|
|
|
|
this.enableActions();
|
|
|
|
},
|
2014-02-12 13:50:23 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
_onClickRestoreSelected: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var self = this;
|
2014-05-12 17:54:20 +00:00
|
|
|
var allFiles = this.$el.find('.select-all').is(':checked');
|
2014-05-08 20:06:30 +00:00
|
|
|
var files = [];
|
|
|
|
var params = {};
|
|
|
|
this.disableActions();
|
|
|
|
if (allFiles) {
|
|
|
|
this.showMask();
|
|
|
|
params = {
|
|
|
|
allfiles: true,
|
|
|
|
dir: this.getCurrentDirectory()
|
|
|
|
};
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
else {
|
|
|
|
files = _.pluck(this.getSelectedFiles(), 'name');
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
var deleteAction = this.findFileEl(files[i]).children("td.date").children(".action.delete");
|
2014-09-22 16:24:32 +00:00
|
|
|
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
|
2014-05-08 20:06:30 +00:00
|
|
|
}
|
|
|
|
params = {
|
|
|
|
files: JSON.stringify(files),
|
|
|
|
dir: this.getCurrentDirectory()
|
|
|
|
};
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
|
2014-02-12 13:50:23 +00:00
|
|
|
params,
|
|
|
|
function(result) {
|
|
|
|
if (allFiles) {
|
|
|
|
if (result.status !== 'success') {
|
|
|
|
OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
self.hideMask();
|
2014-02-12 13:50:23 +00:00
|
|
|
// simply remove all files
|
2014-05-08 20:06:30 +00:00
|
|
|
self.setFiles([]);
|
|
|
|
self.enableActions();
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-05-08 20:06:30 +00:00
|
|
|
self._removeCallback(result);
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
);
|
|
|
|
},
|
2014-02-12 13:50:23 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
_onClickDeleteSelected: function(event) {
|
2014-02-12 13:50:23 +00:00
|
|
|
event.preventDefault();
|
2014-05-08 20:06:30 +00:00
|
|
|
var self = this;
|
2014-05-12 17:54:20 +00:00
|
|
|
var allFiles = this.$el.find('.select-all').is(':checked');
|
2014-05-08 20:06:30 +00:00
|
|
|
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()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.disableActions();
|
|
|
|
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");
|
2014-09-22 16:24:32 +00:00
|
|
|
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
|
2014-05-08 20:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$.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'));
|
|
|
|
}
|
|
|
|
self.hideMask();
|
|
|
|
// simply remove all files
|
|
|
|
self.setFiles([]);
|
|
|
|
self.enableActions();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self._removeCallback(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClickFile: function(event) {
|
|
|
|
var mime = $(this).parent().parent().data('mime');
|
|
|
|
if (mime !== 'httpd/unix-directory') {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
return OCA.Files.FileList.prototype._onClickFile.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
generatePreviewUrl: function(urlSpec) {
|
|
|
|
return OC.generateUrl('/apps/files_trashbin/ajax/preview.php?') + $.param(urlSpec);
|
|
|
|
},
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
getDownloadUrl: function() {
|
2014-05-08 20:06:30 +00:00
|
|
|
// no downloads
|
|
|
|
return '#';
|
|
|
|
},
|
|
|
|
|
|
|
|
enableActions: function() {
|
|
|
|
this.$el.find('.action').css('display', 'inline');
|
2015-10-01 20:54:36 +00:00
|
|
|
this.$el.find('input:checkbox').removeClass('u-hidden');
|
2014-05-08 20:06:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
disableActions: function() {
|
|
|
|
this.$el.find('.action').css('display', 'none');
|
2015-10-01 20:54:36 +00:00
|
|
|
this.$el.find('input:checkbox').addClass('u-hidden');
|
2014-05-12 17:54:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateStorageStatistics: function() {
|
|
|
|
// no op because the trashbin doesn't have
|
|
|
|
// storage info like free space / used space
|
2014-12-08 14:16:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isSelectedDeletable: function() {
|
|
|
|
return true;
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Trashbin.FileList = FileList;
|
2013-10-28 19:22:06 +00:00
|
|
|
})();
|
2014-05-08 20:06:30 +00:00
|
|
|
|