From 35b4b6b745a5c3d9df63a4a3e6ff2659126aa0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Thu, 30 Jul 2020 10:20:29 +0000 Subject: [FIX] web: Close dialog when clicking button with close attribute In a dialog, a button with `close="1"` should close the dialog when clicked. It currently only works if the dialog is a subview. closes odoo/odoo#55200 Signed-off-by: Aaron Bohy (aab) Co-authored-by: fleodoo Co-authored-by: aab-odoo --- addons/web/static/src/js/chrome/action_manager.js | 2 +- .../static/tests/chrome/action_manager_tests.js | 59 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) (limited to 'addons/web/static') diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index aee954342fa..bdcc93e022a 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -393,7 +393,7 @@ var ActionManager = Widget.extend({ return dialog.open().opened(function () { self.currentDialogController = controller; - + widget.setParent(dialog); dom.append(dialog.$el, widget.$el, { in_DOM: true, callbacks: [{widget: dialog}, {widget: controller.widget}], diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 02ba1d2472d..971c5effb98 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -3852,6 +3852,65 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test("Button with `close` attribute closes dialog", async function (assert) { + assert.expect(2); + const actions = [ + { + id: 4, + name: "Partners Action 4", + res_model: "partner", + type: "ir.actions.act_window", + views: [[false, "form"]], + }, + { + id: 5, + name: "Create a Partner", + res_model: "partner", + target: "new", + type: "ir.actions.act_window", + views: [["view_ref", "form"]], + }, + ]; + + const actionManager = await createActionManager({ + actions, + archs: { + "partner,false,form": ` +
+
+
+
+ `, + "partner,view_ref,form": ` +
+
+
+
+ `, + "partner,false,search": "", + }, + data: this.data, + mockRPC: async function (route, args) { + if ( + route === "/web/dataset/call_button" && + args.method === "some_method" + ) { + return { tag: "display_notification", type: "ir.actions.client" }; + } + return this._super(...arguments); + }, + }); + + await actionManager.doAction(4); + await testUtils.dom.click(`button[name="5"]`); + assert.strictEqual($(".modal").length, 1, "It should display a modal"); + await testUtils.dom.click(`button[name="some_method"]`); + assert.strictEqual($(".modal").length, 0, "It should have closed the modal"); + actionManager.destroy(); + }); + QUnit.test('on_attach_callback is called for actions in target="new"', async function (assert) { assert.expect(4); -- cgit v1.2.3