From f936513466dafa4ce0660653b4fe063bc13f2403 Mon Sep 17 00:00:00 2001 From: Romeo Fragomeli Date: Tue, 5 Apr 2022 07:52:51 +0000 Subject: [PATCH] [REF] *: BS5: avoid multiple usage of BS handler In BS5 there is a check to avoid having multiple handler for one element and we can't add two components' instance on an element. So, before disposing a tooltip we check if there is an instance of a tooltip and we avoid instantiation of tooltip if not already done. e.g.: > Bootstrap doesn't allow more than one instance per element. Bound > instance: bs.collapse. e.g.: > Bootstrap doesn't allow more than one instance per element. Bound > instance: bs.carousel. > Bootstrap doesn't allow more than one instance per element. > Bound instance: bs.tooltip. Task ID: 2766483 Part-of: odoo/odoo#95450 --- .../src/legacy/js/views/abstract_controller.js | 15 +++++++++++++++ .../legacy/js/views/pivot/pivot_controller.js | 2 +- .../web/static/src/views/onboarding_banner.js | 18 +++++++++++++++--- .../legacy/views/abstract_view_banner_tests.js | 5 +++-- addons/web/static/tests/views/view_tests.js | 8 ++++---- .../static/src/js/editor/snippets.editor.js | 7 ++++++- .../js/wysiwyg/widgets/link_popover_widget.js | 7 ++++--- odoo/addons/base/views/onboarding_views.xml | 2 +- odoo/addons/test_lint/tests/eslintrc | 2 ++ 9 files changed, 51 insertions(+), 15 deletions(-) diff --git a/addons/web/static/src/legacy/js/views/abstract_controller.js b/addons/web/static/src/legacy/js/views/abstract_controller.js index 631fbdf11c0..75b4d967c16 100644 --- a/addons/web/static/src/legacy/js/views/abstract_controller.js +++ b/addons/web/static/src/legacy/js/views/abstract_controller.js @@ -280,6 +280,18 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { this.renderer.giveFocus(); } }, + /** + * Hide an onboarding banner if present and visible + * @private + */ + _hideBanner: function () { + if (this._$banner.length) { + const $bannerElement = this._$banner.filter('.o_onboarding_container.collapse.show'); + if ($bannerElement.length) { + Collapse.getOrCreateInstance($bannerElement[0]).toggle(); + } + } + }, /** * This method is the way a view can notifies the outside world that * something has changed. The main use for this is to update the url, for @@ -524,6 +536,9 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { additional_context: _.extend({}, data.context) }); } + if (data.oHideBanner) { + self._hideBanner(); + } }, /** * Called either from the control panel to focus the controller diff --git a/addons/web/static/src/legacy/js/views/pivot/pivot_controller.js b/addons/web/static/src/legacy/js/views/pivot/pivot_controller.js index 97cfcf2366d..7d2a4befd9e 100644 --- a/addons/web/static/src/legacy/js/views/pivot/pivot_controller.js +++ b/addons/web/static/src/legacy/js/views/pivot/pivot_controller.js @@ -93,7 +93,7 @@ const context = this._getRenderButtonContext(); this.$buttons = $(QWeb.render('PivotView.buttons', context)); this.$buttons.click(this._onButtonClick.bind(this)); - this.$buttons.find('button').tooltip(); + this.$buttons.find('button[title]').tooltip(); if ($node) { this.$buttons.appendTo($node); } diff --git a/addons/web/static/src/views/onboarding_banner.js b/addons/web/static/src/views/onboarding_banner.js index 31ba74e4691..75e505116ad 100644 --- a/addons/web/static/src/views/onboarding_banner.js +++ b/addons/web/static/src/views/onboarding_banner.js @@ -4,20 +4,32 @@ import { loadCSS, loadJS } from "@web/core/assets"; import { useService } from "@web/core/utils/hooks"; import { useActionLinks } from "@web/views/view_hook"; -const { Component, markup, onWillStart, xml } = owl; +const { Component, markup, onWillStart, useRef, xml } = owl; export class OnboardingBanner extends Component { setup() { this.rpc = useService("rpc"); this.user = useService("user"); + this.onboardingContainerRef = useRef("onboardingContainer"); const resModel = "searchModel" in this.env ? this.env.searchModel.resModel : undefined; - this.handleActionLinks = useActionLinks({ + this._handleActionLinks = useActionLinks({ resModel, reload: async () => { this.bannerHTML = await this.loadBanner(this.env.config.bannerRoute); this.render(); }, }); + this.handleActionLinks = (event) => { + if (event.target.dataset.oHideBanner) { + const collapseElement = this.onboardingContainerRef.el.querySelector( + ".o_onboarding_container.collapse.show" + ); + if (collapseElement) { + Collapse.getOrCreateInstance(collapseElement).toggle(); + } + } + this._handleActionLinks(event); + }; onWillStart(this.onWillStart); } @@ -47,5 +59,5 @@ export class OnboardingBanner extends Component { } } -OnboardingBanner.template = xml`
`; +OnboardingBanner.template = xml`
`; OnboardingBanner.props = {}; diff --git a/addons/web/static/tests/legacy/views/abstract_view_banner_tests.js b/addons/web/static/tests/legacy/views/abstract_view_banner_tests.js index ee3e890cbdf..da8eaacb412 100644 --- a/addons/web/static/tests/legacy/views/abstract_view_banner_tests.js +++ b/addons/web/static/tests/legacy/views/abstract_view_banner_tests.js @@ -43,12 +43,13 @@ QUnit.module('LegacyViews', { assert.expect(6); var banner_html =` -