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>
This commit is contained in:
parent
bea04d12d5
commit
a8f1902b02
|
@ -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
|
||||
*/
|
||||
|
@ -745,6 +745,17 @@
|
|||
* @return {String} display name
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue