From 83eb9f9ebd928eec40e0cc75b7e0225233e7b803 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 29 Jul 2021 14:34:20 +0000 Subject: [PATCH] [FIX] web: action_service: onClose callback can execute history-back Have an action in the breadcrumb (A) Do an action (B) that has a button which spawns a dialog with a onClose callback executing an`history-back` event. This may be useful when the action (B) acts as a selection buffer between (A) and the dialog. (e.g. stock_barcode: execute `stock_barcode_client_action` from a picking) Before this commit, the history-back event just closed the dialog without going back to the action (A) This was because the wrong condition was used to determine if the dialog was still alive or not. After this commit, the action (A) is displayed when closing the dialog from any point. --- .../src/webclient/actions/action_service.js | 2 +- .../webclient/actions/close_action_tests.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index b2048498b49..a4e4a4205e9 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -538,7 +538,7 @@ function makeActionManager(env) { } onHistoryBack() { const previousController = controllerStack[controllerStack.length - 2]; - if (previousController && !dialogCloseProm) { + if (previousController && !dialog.remove) { restore(previousController.jsId); } else { _executeCloseAction(); diff --git a/addons/web/static/tests/webclient/actions/close_action_tests.js b/addons/web/static/tests/webclient/actions/close_action_tests.js index 036bb6a3061..6e4b0540117 100644 --- a/addons/web/static/tests/webclient/actions/close_action_tests.js +++ b/addons/web/static/tests/webclient/actions/close_action_tests.js @@ -108,6 +108,32 @@ QUnit.module("ActionManager", (hooks) => { assert.containsNone(webClient.el, ".modal"); }); + QUnit.test("history back called within on_close", async function (assert) { + assert.expect(7); + const webClient = await createWebClient({ serverData }); + + await doAction(webClient, 1); + assert.containsOnce(webClient, ".o_kanban_view"); + await doAction(webClient, 3); + assert.containsOnce(webClient, ".o_list_view"); + + function onClose() { + const ev = new Event("history-back", { bubbles: true, cancelable: true }); + webClient.el.querySelector(".o_view_controller").dispatchEvent(ev); + assert.step("on_close"); + } + // open a new dialog form + await doAction(webClient, 5, { onClose }); + + await click(webClient.el, ".modal-header button.close"); + await nextTick(); + await legacyExtraNextTick(); + assert.containsNone(webClient, ".modal"); + assert.containsNone(webClient, ".o_list_view"); + assert.containsOnce(webClient, ".o_kanban_view"); + assert.verifySteps(["on_close"]); + }); + QUnit.test( "history back calls on_close handler of dialog action with 2 breadcrumbs", async function (assert) {