From 85dfd22b4987ce76f49e88f14940d2d0127bd7c0 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Tue, 20 Sep 2022 14:10:52 +0000 Subject: [PATCH] [IMP] mrp_subcontracting: convert portal to OWL The subcontracting portal was already mainly written in OWL, but a couple of small tweaks are needed to match the latest implementation. Used for reference: https://github.com/odoo/odoo/blob/b8ef0cc4f22827f684cf3361ee9fd526d27cb72a/addons/project/static/src/project_sharing/project_sharing.js i.e. the OWL changes to the code that this portal was originally "inspired" by closes odoo/odoo#104024 Signed-off-by: Arnold Moyaux (arm) --- .../subcontracting_portal.js | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/addons/mrp_subcontracting/static/src/subcontracting_portal/subcontracting_portal.js b/addons/mrp_subcontracting/static/src/subcontracting_portal/subcontracting_portal.js index 14af8be979e..34fc80e34fe 100644 --- a/addons/mrp_subcontracting/static/src/subcontracting_portal/subcontracting_portal.js +++ b/addons/mrp_subcontracting/static/src/subcontracting_portal/subcontracting_portal.js @@ -4,13 +4,11 @@ import { useService } from '@web/core/utils/hooks'; import { ActionContainer } from '@web/webclient/actions/action_container'; import { MainComponentsContainer } from "@web/core/main_components_container"; import { useOwnDebugContext } from "@web/core/debug/debug_context"; -import { ErrorHandler } from "@web/core/utils/components"; import { session } from '@web/session'; -import { LegacyComponent } from "@web/legacy/legacy_component"; -const { useEffect} = owl; +const { Component, useEffect, useExternalListener } = owl; -export class SubcontractingPortalWebClient extends LegacyComponent { +export class SubcontractingPortalWebClient extends Component { setup() { window.parent.document.body.style.margin = "0"; // remove the margin in the parent body this.actionService = useService('action'); @@ -23,19 +21,7 @@ export class SubcontractingPortalWebClient extends LegacyComponent { }, () => [] ); - } - - handleComponentError(error, C) { - // remove the faulty component - this.Components.splice(this.Components.indexOf(C), 1); - /** - * we rethrow the error to notify the user something bad happened. - * We do it after a tick to make sure owl can properly finish its - * rendering - */ - Promise.resolve().then(() => { - throw error; - }); + useExternalListener(window, "click", this.onGlobalClick, { capture: true }); } async _showView() { @@ -54,7 +40,24 @@ export class SubcontractingPortalWebClient extends LegacyComponent { } ); } + + /** + * @param {MouseEvent} ev + */ + onGlobalClick(ev) { + // When a ctrl-click occurs inside an element + // we let the browser do the default behavior and + // we do not want any other listener to execute. + if ( + ev.ctrlKey && + ((ev.target instanceof HTMLAnchorElement && ev.target.href) || + (ev.target instanceof HTMLElement && ev.target.closest("a[href]:not([href=''])"))) + ) { + ev.stopImmediatePropagation(); + return; + } + } } -SubcontractingPortalWebClient.components = { ActionContainer, ErrorHandler, MainComponentsContainer }; +SubcontractingPortalWebClient.components = { ActionContainer, MainComponentsContainer }; SubcontractingPortalWebClient.template = 'mrp_subcontracting.SubcontractingPortalWebClient';