From 7c4f200b8edf0bc695c623c7afc62288f838db36 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Wed, 20 Apr 2022 09:36:09 +0000 Subject: [PATCH] [IMP] web: improve core Dialog API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *: base_automation, iap, web_tour Previously, when trying to create a custom dialog, one would need to extend the base Dialog class and configure it directly on the class, using separate templates for the body and footer as necessary. This is very unidiomatic owl code, and it is much more natural to simply extend Component, and use Dialog at the root of the template, giving it slots and props to configure its properties and contents. This commit changes the dialog API to work as described and adapts code that uses it. closes odoo/odoo#89113 Enterprise: https://github.com/odoo/enterprise/pull/26462 Related: odoo/enterprise#26462 Signed-off-by: Géry Debongnie --- .../src/js/base_automation_error_dialog.js | 6 +- .../src/xml/base_automation_error_dialog.xml | 2 +- .../js/insufficient_credit_error_handler.js | 13 +- addons/iap/static/src/xml/iap_templates.xml | 39 ++-- .../src/core/commands/command_palette.js | 17 +- .../src/core/commands/command_palette.xml | 75 +++---- .../core/commands/command_palette_dialog.js | 34 --- .../core/commands/command_palette_dialog.xml | 8 - .../src/core/commands/command_service.js | 4 +- .../confirmation_dialog.js | 37 ++-- .../confirmation_dialog.xml | 33 ++- .../src/core/debug/debug_menu_items.xml | 193 +++++++++--------- addons/web/static/src/core/dialog/dialog.js | 63 +++--- addons/web/static/src/core/dialog/dialog.xml | 30 ++- .../src/core/dialog/dialog_container.js | 24 +-- .../static/src/core/dialog/dialog_service.js | 19 +- .../static/src/core/errors/error_dialogs.js | 48 ++--- .../static/src/core/errors/error_dialogs.xml | 92 +++++---- .../web/static/src/core/utils/components.js | 9 +- .../web/static/src/legacy/action_adapters.js | 13 +- addons/web/static/src/legacy/debug_manager.js | 15 +- addons/web/static/src/views/debug_items.js | 10 +- .../src/webclient/actions/action_dialog.js | 18 +- .../src/webclient/actions/action_dialog.xml | 21 +- .../webclient/user_menu/user_menu_items.js | 11 +- .../webclient/user_menu/user_menu_items.xml | 6 +- .../core/commands/command_palette_tests.js | 66 +++--- .../tests/core/debug/debug_manager_tests.js | 8 + .../static/tests/core/dialog_service_tests.js | 44 ++-- addons/web/static/tests/core/dialog_tests.js | 167 ++++++--------- .../tests/core/errors/error_dialogs_tests.js | 25 ++- .../tests/legacy/core/owl_dialog_tests.js | 29 +-- .../static/src/debug/tour_dialog_component.js | 12 +- .../src/debug/tour_dialog_component.xml | 4 +- 34 files changed, 578 insertions(+), 617 deletions(-) delete mode 100644 addons/web/static/src/core/commands/command_palette_dialog.js delete mode 100644 addons/web/static/src/core/commands/command_palette_dialog.xml diff --git a/addons/base_automation/static/src/js/base_automation_error_dialog.js b/addons/base_automation/static/src/js/base_automation_error_dialog.js index a0cc2c3b106..b3f19dd2528 100644 --- a/addons/base_automation/static/src/js/base_automation_error_dialog.js +++ b/addons/base_automation/static/src/js/base_automation_error_dialog.js @@ -31,7 +31,7 @@ export class BaseAutomationErrorDialog extends ErrorDialog { await this.orm.write("base.automation", [this.actionId], { active: false, }); - this.close(); + this.props.close(); } /** * This method is called when the user clicks on the 'Edit action' button @@ -50,10 +50,10 @@ export class BaseAutomationErrorDialog extends ErrorDialog { type: "ir.actions.act_window", view_mode: "form", }); - this.close(); + this.props.close(); } } -BaseAutomationErrorDialog.bodyTemplate = "base_automation.ErrorDialogBody"; +BaseAutomationErrorDialog.template = "base_automation.ErrorDialog"; registry.category("error_dialogs").add("base_automation", BaseAutomationErrorDialog); diff --git a/addons/base_automation/static/src/xml/base_automation_error_dialog.xml b/addons/base_automation/static/src/xml/base_automation_error_dialog.xml index e694dd3311c..5cb78ef1424 100644 --- a/addons/base_automation/static/src/xml/base_automation_error_dialog.xml +++ b/addons/base_automation/static/src/xml/base_automation_error_dialog.xml @@ -1,7 +1,7 @@ - +

The error occurred during the execution of the automated action diff --git a/addons/iap/static/src/js/insufficient_credit_error_handler.js b/addons/iap/static/src/js/insufficient_credit_error_handler.js index 3271daa7b54..eb3d0e41b71 100644 --- a/addons/iap/static/src/js/insufficient_credit_error_handler.js +++ b/addons/iap/static/src/js/insufficient_credit_error_handler.js @@ -3,11 +3,12 @@ import { Dialog } from "@web/core/dialog/dialog"; import { registry } from "@web/core/registry"; import { useService } from "@web/core/utils/hooks"; -class InsufficientCreditDialog extends Dialog { +const { Component, onWillStart } = owl; + +class InsufficientCreditDialog extends Component { setup() { - super.setup(...arguments); this.orm = useService("orm"); - owl.onWillStart(this.onWillStart); + onWillStart(this.onWillStart); } async onWillStart() { @@ -30,11 +31,11 @@ class InsufficientCreditDialog extends Dialog { buyCredits() { window.open(this.url, "_blank"); - this.close(); + this.props.close(); } } -InsufficientCreditDialog.bodyTemplate = "iap.redirect_to_odoo_credit"; -InsufficientCreditDialog.footerTemplate = "iap.InsufficientCreditFooter"; +InsufficientCreditDialog.components = { Dialog }; +InsufficientCreditDialog.template = "iap.InsufficientCreditDialog"; function insufficientCreditHandler(env, error, originalError) { if (!originalError) { diff --git a/addons/iap/static/src/xml/iap_templates.xml b/addons/iap/static/src/xml/iap_templates.xml index 6f9b6b1995f..2dbb2876cbd 100644 --- a/addons/iap/static/src/xml/iap_templates.xml +++ b/addons/iap/static/src/xml/iap_templates.xml @@ -2,24 +2,27 @@