From 196a837c57b5d0112d55287a7308614aa256cf90 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Tue, 13 Dec 2022 15:48:57 +0000 Subject: [PATCH] [FIX] web_editor: commit changes when using the sidebar Before this commit, some operation (eg. move node, duplicate or remove a snippet from the snippetMenu) in the snippetMenu sidebar did not trigger the mass mailing commit changes and therefore if no selection was made in the document followed by a blur was made, no changes could be recorded and saved by the owl form component. task-3052658 X-original-commit: 8bd8db97ee0d7774e5aa0495b9a5cc7d695fca67 Part-of: odoo/odoo#112908 --- .../static/src/js/mass_mailing_html_field.js | 19 ------------------- .../static/src/js/wysiwyg/wysiwyg.js | 5 ++++- .../static/src/js/wysiwyg/wysiwyg_iframe.js | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/addons/mass_mailing/static/src/js/mass_mailing_html_field.js b/addons/mass_mailing/static/src/js/mass_mailing_html_field.js index 433a192ecca..2e64057fdcd 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_html_field.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_html_field.js @@ -17,7 +17,6 @@ import { getRangePosition } from '@web_editor/js/editor/odoo-editor/src/utils/ut const { onWillStart, - useEffect, useSubEnv, onWillUpdateProps, } = owl; @@ -41,15 +40,6 @@ export class MassMailingHtmlField extends HtmlField { this._hideIrrelevantTemplates(); } }); - - useEffect(() => { - const listener = () => { - this._lastClickInIframe = false; - }; - document.addEventListener('mousedown', listener, true); - - return () => document.removeEventListener('mousedown', listener, true); - }, () => []); } get wysiwygOptions() { @@ -173,10 +163,6 @@ export class MassMailingHtmlField extends HtmlField { this.wysiwyg.odooEditor.historyReset(); this.wysiwyg.$iframeBody.addClass('o_mass_mailing_iframe'); - this.wysiwyg.odooEditor.document.addEventListener('mousedown', () => { - this._lastClickInIframe = true; - }, true); - this.onIframeUpdated(); } @@ -589,11 +575,6 @@ export class MassMailingHtmlField extends HtmlField { async _getWysiwygClass() { return getWysiwygClass({moduleName: 'mass_mailing.wysiwyg'}); } - _onWysiwygBlur() { - if (!this._lastClickInIframe) { - super._onWysiwygBlur(); - } - } } MassMailingHtmlField.props = { diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 1731d815096..9df99e6df25 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -130,7 +130,7 @@ const Wysiwyg = Widget.extend({ this.$editable.data('oe-model', options.recordInfo.res_model); this.$editable.data('oe-id', options.recordInfo.res_id); document.addEventListener('mousedown', this._onDocumentMousedown, true); - this.$editable.on('blur', this._onBlur); + this._bindOnBlur(); this.toolbar = new Toolbar(this, this.options.toolbarTemplate); await this.toolbar.appendTo(document.createElement('void')); @@ -2632,6 +2632,9 @@ const Wysiwyg = Widget.extend({ } } }, + _bindOnBlur() { + this.$editable.on('blur', this._onBlur); + }, }); Wysiwyg.activeCollaborationChannelNames = new Set(); diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js index 3707d987b7e..1fe97d8dc05 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg_iframe.js @@ -174,6 +174,20 @@ Wysiwyg.include({ return this._super.apply(this, arguments); } }, + + /** + * Bind the blur event on the iframe so that it would not blur when using + * the sidebar. + * + * @override + */ + _bindOnBlur: function () { + if (!this.options.inIframe) { + this._super.apply(this, arguments); + } else { + this.$iframe[0].contentWindow.addEventListener('blur', this._onBlur); + } + }, }); });