From 2ee329f6ca8417fea1b3cb9fe632ef2befcc3817 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Tue, 12 Sep 2023 09:58:56 +0200 Subject: [PATCH] [FIX] web: close button in form view dialog discard The goal of this commit is to ensure that the form view dialog close button performs the same behaviour as the discard button. To enable this, we had to add the dialogData.dismiss, which lets you add a callBack that will only be executed when a dialog is closed because of the "x" or the "escape" shortcut. closes odoo/odoo#135116 Related: odoo/enterprise#47283 Signed-off-by: Aaron Bohy (aab) --- .../confirmation_dialog.js | 6 ++-- addons/web/static/src/core/dialog/dialog.js | 9 +++++- addons/web/static/src/core/dialog/dialog.xml | 5 ++- .../src/views/fields/relational_utils.js | 6 ++-- .../views/view_dialogs/form_view_dialog.js | 15 +++++---- .../view_dialogs/select_create_dialog.xml | 2 +- .../src/webclient/actions/action_dialog.xml | 1 - addons/web/static/tests/core/dialog_tests.js | 18 +++++++---- .../view_dialogs/form_view_dialog_tests.js | 32 +++++++++++++++++++ 9 files changed, 70 insertions(+), 24 deletions(-) diff --git a/addons/web/static/src/core/confirmation_dialog/confirmation_dialog.js b/addons/web/static/src/core/confirmation_dialog/confirmation_dialog.js index cb9991e4909..1c5e93ee7f1 100644 --- a/addons/web/static/src/core/confirmation_dialog/confirmation_dialog.js +++ b/addons/web/static/src/core/confirmation_dialog/confirmation_dialog.js @@ -8,17 +8,17 @@ import { Component } from "@odoo/owl"; export class ConfirmationDialog extends Component { setup() { - this.env.dialogData.close = () => this._cancel(); + this.env.dialogData.dismiss = () => this._cancel(); this.modalRef = useChildRef(); this.isProcess = false; } async _cancel() { - this.execButton(this.props.cancel); + return this.execButton(this.props.cancel); } async _confirm() { - this.execButton(this.props.confirm); + return this.execButton(this.props.confirm); } setButtonsDisabled(disabled) { diff --git a/addons/web/static/src/core/dialog/dialog.js b/addons/web/static/src/core/dialog/dialog.js index 310f72ca9f6..00cb2cc8f79 100644 --- a/addons/web/static/src/core/dialog/dialog.js +++ b/addons/web/static/src/core/dialog/dialog.js @@ -90,7 +90,14 @@ export class Dialog extends Component { } onEscape() { - this.data.close(); + return this.dismiss(); + } + + async dismiss() { + if (this.data.dismiss) { + await this.data.dismiss(); + } + return this.data.close(); } } Dialog.template = "web.Dialog"; diff --git a/addons/web/static/src/core/dialog/dialog.xml b/addons/web/static/src/core/dialog/dialog.xml index 75e0e16734e..78a1f34836b 100644 --- a/addons/web/static/src/core/dialog/dialog.xml +++ b/addons/web/static/src/core/dialog/dialog.xml @@ -13,7 +13,6 @@