2014-02-17 21:26:29 +04: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 23:22:06 +04:00
|
|
|
/* global OC, t, BreadCrumb, FileActions, FileList, Files */
|
2013-01-18 16:11:29 +04:00
|
|
|
$(document).ready(function() {
|
2013-10-28 23:22:06 +04:00
|
|
|
var deletedRegExp = new RegExp(/^(.+)\.d[0-9]+$/);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param name file name
|
|
|
|
* @return converted file name
|
|
|
|
*/
|
|
|
|
function getDeletedFileName(name) {
|
|
|
|
name = OC.basename(name);
|
|
|
|
var match = deletedRegExp.exec(name);
|
|
|
|
if (match && match.length > 1) {
|
|
|
|
name = match[1];
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2014-03-25 14:00:01 +04:00
|
|
|
Files.updateStorageStatistics = function() {
|
|
|
|
// no op because the trashbin doesn't have
|
|
|
|
// storage info like free space / used space
|
|
|
|
};
|
|
|
|
|
2013-01-18 16:11:29 +04:00
|
|
|
if (typeof FileActions !== 'undefined') {
|
2013-06-17 15:30:57 +04:00
|
|
|
FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) {
|
2014-01-10 18:02:26 +04:00
|
|
|
var tr = FileList.findFileEl(filename);
|
|
|
|
var deleteAction = tr.children("td.date").children(".action.delete");
|
2013-10-09 14:01:25 +04:00
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
2013-07-26 16:54:27 +04:00
|
|
|
disableActions();
|
2014-02-17 21:26:29 +04:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
|
|
|
|
files: JSON.stringify([filename]),
|
|
|
|
dir: FileList.getCurrentDirectory()
|
|
|
|
},
|
2014-02-12 17:50:23 +04:00
|
|
|
FileList._removeCallback
|
2013-10-09 14:43:56 +04:00
|
|
|
);
|
2014-04-17 04:35:43 +04:00
|
|
|
}, t('files_trashbin', 'Restore'));
|
2013-10-09 14:43:56 +04:00
|
|
|
};
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-10-09 14:43:56 +04:00
|
|
|
FileActions.register('all', 'Delete', OC.PERMISSION_READ, function() {
|
|
|
|
return OC.imagePath('core', 'actions/delete');
|
|
|
|
}, function(filename) {
|
|
|
|
$('.tipsy').remove();
|
2014-01-10 18:02:26 +04:00
|
|
|
var tr = FileList.findFileEl(filename);
|
|
|
|
var deleteAction = tr.children("td.date").children(".action.delete");
|
2013-10-09 14:43:56 +04:00
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
|
|
|
disableActions();
|
2014-02-17 21:26:29 +04:00
|
|
|
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
|
|
|
|
files: JSON.stringify([filename]),
|
|
|
|
dir: FileList.getCurrentDirectory()
|
|
|
|
},
|
2014-02-12 17:50:23 +04:00
|
|
|
FileList._removeCallback
|
2013-10-09 14:43:56 +04:00
|
|
|
);
|
|
|
|
});
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
/**
|
|
|
|
* Override crumb URL maker (hacky!)
|
|
|
|
*/
|
|
|
|
FileList.breadcrumb.getCrumbUrl = function(part, index) {
|
|
|
|
if (index === 0) {
|
|
|
|
return OC.linkTo('files', 'index.php');
|
|
|
|
}
|
|
|
|
return OC.linkTo('files_trashbin', 'index.php')+"?dir=" + encodeURIComponent(part.dir);
|
2013-08-17 15:07:18 +04:00
|
|
|
};
|
2013-01-18 16:11:29 +04:00
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
Files.generatePreviewUrl = function(urlSpec) {
|
|
|
|
return OC.generateUrl('/apps/files_trashbin/ajax/preview.php?') + $.param(urlSpec);
|
|
|
|
};
|
|
|
|
|
|
|
|
Files.getDownloadUrl = function(action, params) {
|
|
|
|
// no downloads
|
|
|
|
return '#';
|
|
|
|
};
|
|
|
|
|
|
|
|
Files.getAjaxUrl = function(action, params) {
|
|
|
|
var q = '';
|
|
|
|
if (params) {
|
|
|
|
q = '?' + OC.buildQueryString(params);
|
|
|
|
}
|
|
|
|
return OC.filePath('files_trashbin', 'ajax', action + '.php') + q;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override crumb making to add "Deleted Files" entry
|
|
|
|
* and convert files with ".d" extensions to a more
|
|
|
|
* user friendly name.
|
|
|
|
*/
|
|
|
|
var oldMakeCrumbs = BreadCrumb.prototype._makeCrumbs;
|
|
|
|
BreadCrumb.prototype._makeCrumbs = function() {
|
|
|
|
var parts = oldMakeCrumbs.apply(this, arguments);
|
|
|
|
// duplicate first part
|
|
|
|
parts.unshift(parts[0]);
|
|
|
|
parts[1] = {
|
|
|
|
dir: '/',
|
|
|
|
name: t('files_trashbin', 'Deleted Files')
|
2013-01-18 20:50:44 +04:00
|
|
|
};
|
2013-10-28 23:22:06 +04:00
|
|
|
for (var i = 2; i < parts.length; i++) {
|
|
|
|
parts[i].name = getDeletedFileName(parts[i].name);
|
2013-01-18 20:50:44 +04:00
|
|
|
}
|
2013-10-28 23:22:06 +04:00
|
|
|
return parts;
|
|
|
|
};
|
2013-01-31 21:14:22 +04:00
|
|
|
|
2013-10-28 23:22:06 +04:00
|
|
|
FileActions.actions.dir = {
|
|
|
|
// only keep 'Open' action for navigation
|
|
|
|
'Open': FileActions.actions.dir.Open
|
|
|
|
};
|
|
|
|
});
|
2013-07-26 16:54:27 +04:00
|
|
|
|
|
|
|
function enableActions() {
|
|
|
|
$(".action").css("display", "inline");
|
|
|
|
$(":input:checkbox").css("display", "inline");
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableActions() {
|
|
|
|
$(".action").css("display", "none");
|
|
|
|
$(":input:checkbox").css("display", "none");
|
|
|
|
}
|
2013-08-17 15:07:18 +04:00
|
|
|
|