[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.
This commit is contained in:
Lucas Perais (lpe)
2021-08-02 07:55:52 +00:00
parent b0de4f7cef
commit 83eb9f9ebd
2 changed files with 27 additions and 1 deletions
@@ -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();
@@ -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) {