[FIX] web: support anchor tags with action type in views

This commit is contained in:
David Monjoie
2017-05-02 15:24:55 +02:00
parent e02cee4ea6
commit 642fe9b9c1
2 changed files with 38 additions and 0 deletions
@@ -19,6 +19,9 @@ var AbstractController = Widget.extend({
custom_events: {
open_record: '_onOpenRecord',
},
events: {
'click a[type="action"]': '_onActionClicked',
},
/**
* @constructor
@@ -291,6 +294,17 @@ var AbstractController = Widget.extend({
model: this.modelName,
});
},
/**
* When a user clicks on an <a> link with type="action", we need to actually
* do the action. This kind of links is used a lot in no-content helpers.
*
* @private
* @param {OdooEvent} event
*/
_onActionClicked: function (event) {
event.preventDefault();
this.do_action(event.target.name);
},
});
@@ -3795,5 +3795,29 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('support anchor tags with action type', function (assert) {
assert.expect(1);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<a type="action" name="42"><i class="fa fa-arrow-right"/> Click me !</a>' +
'</form>',
res_id: 1,
intercepts: {
do_action: function (event) {
assert.strictEqual(event.data.action, "42",
"should trigger do_action with correct action parameter");
}
}
});
form.$('a[type="action"]').click();
form.destroy();
});
});
});