From 642fe9b9c1c0267dfb05b12932be9d3dfe53df40 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Thu, 20 Apr 2017 14:26:19 +0200 Subject: [PATCH] [FIX] web: support anchor tags with action type in views --- .../src/js/views/abstract_controller.js | 14 +++++++++++ addons/web/static/tests/views/form_tests.js | 24 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js index 1dacce59fa6..b84f6ec1951 100644 --- a/addons/web/static/src/js/views/abstract_controller.js +++ b/addons/web/static/src/js/views/abstract_controller.js @@ -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 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); + }, }); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 2eb5f6e127b..69d1d8c1993 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -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: '
' + + ' Click me !' + + '', + 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(); + }); + }); });