From 85dfc9cf49ca409757a53e5e364ce61deaf120d3 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Thu, 10 Jun 2021 10:37:24 +0000 Subject: [PATCH] [IMP] web: remove the Portal from dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we simplify the dialog template by removing the Portal. The Portal is no longer used, as now we always use the dialog service to open a new dialog. also: - remove the dialog container class from the webclient; - add the dialog container class to the dialog container; - move the management of the inactive modal class to the dialog container; - remove the dialog manager class from the dialog container; closes odoo-dev/odoo#947 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/core/dialog/dialog.js | 37 +-------- addons/web/static/src/core/dialog/dialog.xml | 44 +++++----- .../src/core/dialog/dialog_container.js | 5 +- addons/web/static/src/webclient/webclient.xml | 1 - .../tests/core/debug/debug_manager_tests.js | 14 +--- .../static/tests/core/dialog_service_tests.js | 81 +++++++++++++----- addons/web/static/tests/core/dialog_tests.js | 82 +------------------ .../tests/core/errors/error_dialogs_tests.js | 15 ++-- 8 files changed, 101 insertions(+), 178 deletions(-) diff --git a/addons/web/static/src/core/dialog/dialog.js b/addons/web/static/src/core/dialog/dialog.js index 790c26a3da8..997132e577c 100644 --- a/addons/web/static/src/core/dialog/dialog.js +++ b/addons/web/static/src/core/dialog/dialog.js @@ -4,29 +4,23 @@ import { useHotkey } from "../hotkey_hook"; import { useService } from "../service_hook"; import { useActiveElement } from "../ui/ui_service"; -const { Component, hooks, misc } = owl; +const { Component, hooks } = owl; const { useRef, useSubEnv } = hooks; -const { Portal } = misc; export class Dialog extends Component { - constructor(...args) { - super(...args); + setup() { if (this.constructor === Dialog) { throw new Error( "Dialog should not be used by itself. Please use the dialog service with a Dialog subclass." ); } - } - setup() { this.modalRef = useRef("modal"); this.dialogService = useService("dialog"); useActiveElement("modal"); useHotkey( "escape", () => { - if (!this.modalRef.el.classList.contains("o_inactive_modal")) { - this.close(); - } + this.close(); }, { altIsOptional: true } ); @@ -42,30 +36,6 @@ export class Dialog extends Component { this.__id = null; } - mounted() { - const dialogContainer = document.querySelector(".o_dialog_container"); - const modals = dialogContainer.querySelectorAll(".o_dialog .modal"); - const len = modals.length; - for (let i = 0; i < len - 1; i++) { - const modal = modals[i]; - modal.classList.add("o_inactive_modal"); - } - dialogContainer.classList.add("modal-open"); - } - - willUnmount() { - const dialogContainer = document.querySelector(".o_dialog_container"); - const modals = dialogContainer.querySelectorAll(".o_dialog .modal"); - const len = modals.length; - if (len >= 2) { - const modal = this.modalRef.el === modals[len - 1] ? modals[len - 2] : modals[len - 1]; - modal.focus(); - modal.classList.remove("o_inactive_modal"); - } else { - dialogContainer.classList.remove("modal-open"); - } - } - /** * Send an event signaling that the dialog should be closed. * @private @@ -75,7 +45,6 @@ export class Dialog extends Component { } } -Dialog.components = { Portal }; Dialog.template = "web.Dialog"; Dialog.contentClass = null; Dialog.fullscreen = false; diff --git a/addons/web/static/src/core/dialog/dialog.xml b/addons/web/static/src/core/dialog/dialog.xml index 736d618d958..61a3ce9fd4c 100644 --- a/addons/web/static/src/core/dialog/dialog.xml +++ b/addons/web/static/src/core/dialog/dialog.xml @@ -2,32 +2,30 @@ - -
-