From e689bc745fc94d9760976e40522ddf96eb5c645c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 24 Nov 2014 16:26:50 +0100 Subject: Improve FileActions JS to allow for custom rendering This improves the OCA.Files.FileActions class to support passing a "render" function in the action object. The default function "_defaultRenderFunction" is used by default and renders actions in the usual actions container. Moved "Rename" and "Delete" to custom render functions. --- apps/files_trashbin/js/app.js | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'apps/files_trashbin/js') diff --git a/apps/files_trashbin/js/app.js b/apps/files_trashbin/js/app.js index a9727542bad..72d9f4a6771 100644 --- a/apps/files_trashbin/js/app.js +++ b/apps/files_trashbin/js/app.js @@ -57,21 +57,34 @@ OCA.Trashbin.App = { ); }, t('files_trashbin', 'Restore')); - fileActions.register('all', 'Delete', OC.PERMISSION_READ, function() { - return OC.imagePath('core', 'actions/delete'); - }, 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'); - fileList.disableActions(); - $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), { - files: JSON.stringify([filename]), - dir: fileList.getCurrentDirectory() - }, - _.bind(fileList._removeCallback, fileList) - ); + fileActions.registerAction({ + name: 'Delete', + displayName: '', + mime: 'all', + permissions: OC.PERMISSION_READ, + icon: function() { + return OC.imagePath('core', 'actions/delete'); + }, + render: function(actionSpec, isDefault, context) { + var $actionLink = fileActions._makeActionLink(actionSpec, context); + $actionLink.attr('original-title', t('files', 'Delete permanently')); + context.$file.find('td:last').append($actionLink); + return $actionLink; + }, + 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'); + fileList.disableActions(); + $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), { + files: JSON.stringify([filename]), + dir: fileList.getCurrentDirectory() + }, + _.bind(fileList._removeCallback, fileList) + ); + } }); return fileActions; } -- cgit v1.2.3