From 78c6c70ee4fe8d795a5f42ae662e8deaf82ca322 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 3 Oct 2022 08:42:50 +0000 Subject: [PATCH] [FIX] web: FormViewDialog: handle `close` attr on buttons Before this commit, clicking on view buttons with attribute `close="1"` in FormViewDialog didn't close the dialog once the button action was performed. This commit fixes that issue, and ensures we do not reload the record if we're about to close the dialog. X-original-commit: 32d211a6fd5c121fa5f556f1d78b79421edc6f68 Part-of: odoo/odoo#102149 --- addons/web/static/src/core/dialog/dialog.js | 2 +- addons/web/static/src/views/utils.js | 1 + .../src/views/view_button/view_button_hook.js | 16 ++++--- .../view_dialogs/form_view_dialog_tests.js | 45 ++++++++++++++++++- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/core/dialog/dialog.js b/addons/web/static/src/core/dialog/dialog.js index f8790f5707f..50195e8fa23 100644 --- a/addons/web/static/src/core/dialog/dialog.js +++ b/addons/web/static/src/core/dialog/dialog.js @@ -14,7 +14,7 @@ export class Dialog extends Component { this.data.close(); }); this.id = `dialog_${this.data.id}`; - useChildSubEnv({ inDialog: true, dialogId: this.id }); + useChildSubEnv({ inDialog: true, dialogId: this.id, closeDialog: this.data.close }); owl.onWillDestroy(() => { if (this.env.isSmall) { diff --git a/addons/web/static/src/views/utils.js b/addons/web/static/src/views/utils.js index 34bebefcd01..d9f2927d2f5 100644 --- a/addons/web/static/src/views/utils.js +++ b/addons/web/static/src/views/utils.js @@ -196,6 +196,7 @@ export function processButton(node) { options: JSON.parse(node.getAttribute("options") || "{}"), modifiers: JSON.parse(node.getAttribute("modifiers") || "{}"), clickParams: { + close: archParseBoolean(node.getAttribute("close"), false), context: node.getAttribute("context") || "{}", name: node.getAttribute("name"), type: node.getAttribute("type"), diff --git a/addons/web/static/src/views/view_button/view_button_hook.js b/addons/web/static/src/views/view_button/view_button_hook.js index d47a88b960c..8d690bda19a 100644 --- a/addons/web/static/src/views/view_button/view_button_hook.js +++ b/addons/web/static/src/views/view_button/view_button_hook.js @@ -39,9 +39,7 @@ export function useViewButtons(model, ref, options = {}) { (() => { return true; }); - const afterExecuteAction = - options.afterExecuteAction || - (() => {}); + const afterExecuteAction = options.afterExecuteAction || (() => {}); useSubEnv({ async onClickViewButton({ clickParams, @@ -66,6 +64,7 @@ export function useViewButtons(model, ref, options = {}) { enableButtons(getEl(), manuallyDisabledButtons, enableAction); return; } + const closeDialog = clickParams.close && env.closeDialog; const params = getResParams(); const resId = params.resId; const resIds = params.resIds || model.resIds; @@ -88,9 +87,11 @@ export function useViewButtons(model, ref, options = {}) { context: params.context || {}, //LPE FIXME new Context(payload.env.context).eval(); buttonContext, onClose: async () => { - const reload = options.reload || (() => model.root.load()); - await reload(); - comp.render(true); // FIXME WOWL reactivity + if (!closeDialog) { + const reload = options.reload || (() => model.root.load()); + await reload(); + comp.render(true); // FIXME WOWL reactivity + } }, }); let error; @@ -101,6 +102,9 @@ export function useViewButtons(model, ref, options = {}) { await doActionParams.onClose(); } await afterExecuteAction(clickParams); + if (closeDialog) { + closeDialog(); + } enableButtons(getEl(), manuallyDisabledButtons, enableAction); if (error) { return Promise.reject(error); diff --git a/addons/web/static/tests/views/view_dialogs/form_view_dialog_tests.js b/addons/web/static/tests/views/view_dialogs/form_view_dialog_tests.js index e6cb2a48ec6..a840256c716 100644 --- a/addons/web/static/tests/views/view_dialogs/form_view_dialog_tests.js +++ b/addons/web/static/tests/views/view_dialogs/form_view_dialog_tests.js @@ -1,6 +1,12 @@ /** @odoo-module */ -import { click, getFixture, nextTick, triggerHotkey } from "@web/../tests/helpers/utils"; +import { + click, + getFixture, + nextTick, + patchWithCleanup, + triggerHotkey, +} from "@web/../tests/helpers/utils"; import { makeView } from "@web/../tests/views/helpers"; import { createWebClient } from "@web/../tests/webclient/helpers"; import { dialogService } from "@web/core/dialog/dialog_service"; @@ -245,6 +251,43 @@ QUnit.module("ViewDialogs", (hooks) => { await click(target, '.o_field_widget[name="instrument"] button.o_external_button'); }); + QUnit.test("click on view buttons in a FormViewDialog", async function (assert) { + serverData.views = { + "partner,false,form": ` +
+ +