diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-09-27 01:50:24 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-10-19 01:46:13 +0200 |
commit | a8f1902b02d02cc2b7d624b3d7b288f8aea84fdc (patch) | |
tree | 5f5ff64d4b9e989c4573f0e4049c19782282d150 /apps | |
parent | bea04d12d5a9ae8653277fc6379468d990f397ea (diff) | |
download | nextcloud-server-a8f1902b02d02cc2b7d624b3d7b288f8aea84fdc.tar.gz nextcloud-server-a8f1902b02d02cc2b7d624b3d7b288f8aea84fdc.zip |
Add support to FileActionsMenu for icon class functions
Icon class function properties make possible to render a different icon
class depending on the context of the file action.
Inline file actions had support for them already and called them passing
the file name and context of the file action as parameters. Due to this
the FileActionsMenu passes those parameters too to icon class functions
instead of just the context like done for display name functions.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/js/fileactions.js | 13 | ||||
-rw-r--r-- | apps/files/js/fileactionsmenu.js | 5 | ||||
-rw-r--r-- | apps/files/tests/js/fileactionsmenuSpec.js | 28 |
3 files changed, 45 insertions, 1 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 3da9b06b0d3..0f320c8b3c7 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -706,7 +706,7 @@ * @property {String} mime mime type * @property {int} permissions permissions * @property {(Function|String)} icon icon path to the icon or function that returns it (deprecated, use iconClass instead) - * @property {(Function|String)} iconClass class name of the icon (recommended for theming) + * @property {(String|OCA.Files.FileActions~iconClassFunction)} iconClass class name of the icon (recommended for theming) * @property {OCA.Files.FileActions~renderActionFunction} [render] optional rendering function * @property {OCA.Files.FileActions~actionHandler} actionHandler action handler function */ @@ -746,6 +746,17 @@ */ /** + * Icon class function for actions. + * The function returns the icon class of the action using + * the given context information. + * + * @callback OCA.Files.FileActions~iconClassFunction + * @param {String} fileName name of the file on which the action must be performed + * @param {OCA.Files.FileActionContext} context action context + * @return {String} icon class + */ + + /** * Action handler function for file actions * * @callback OCA.Files.FileActions~actionHandler diff --git a/apps/files/js/fileactionsmenu.js b/apps/files/js/fileactionsmenu.js index 45d2bd83049..b8022f13734 100644 --- a/apps/files/js/fileactionsmenu.js +++ b/apps/files/js/fileactionsmenu.js @@ -115,6 +115,11 @@ item = _.extend({}, item); item.displayName = item.displayName(self._context); } + if (_.isFunction(item.iconClass)) { + var fileName = self._context.$file.attr('data-file'); + item = _.extend({}, item); + item.iconClass = item.iconClass(fileName, self._context); + } return item; }); items = items.sort(function(actionA, actionB) { diff --git a/apps/files/tests/js/fileactionsmenuSpec.js b/apps/files/tests/js/fileactionsmenuSpec.js index 3028db2b3ac..926516b3043 100644 --- a/apps/files/tests/js/fileactionsmenuSpec.js +++ b/apps/files/tests/js/fileactionsmenuSpec.js @@ -205,6 +205,34 @@ describe('OCA.Files.FileActionsMenu tests', function() { expect(displayNameStub.calledWith(menuContext)).toEqual(true); expect(menu.$el.find('a[data-action=Something]').text()).toEqual('Test'); }); + it('uses plain iconClass', function() { + fileActions.registerAction({ + name: 'Something', + mime: 'text/plain', + permissions: OC.PERMISSION_ALL, + iconClass: 'test' + }); + + menu.render(); + + expect(menu.$el.find('a[data-action=Something]').children('span.icon').hasClass('test')).toEqual(true); + }); + it('calls iconClass function', function() { + var iconClassStub = sinon.stub().returns('test'); + + fileActions.registerAction({ + name: 'Something', + mime: 'text/plain', + permissions: OC.PERMISSION_ALL, + iconClass: iconClassStub + }); + + menu.render(); + + expect(iconClassStub.calledOnce).toEqual(true); + expect(iconClassStub.calledWith(menuContext.$file.attr('data-file'), menuContext)).toEqual(true); + expect(menu.$el.find('a[data-action=Something]').children('span.icon').hasClass('test')).toEqual(true); + }); }); describe('action handler', function() { |