aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/files/js/fileactions.js13
-rw-r--r--apps/files/js/fileactionsmenu.js5
-rw-r--r--apps/files/tests/js/fileactionsmenuSpec.js28
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() {