From 59101edb9b18355db1904c7cf152d315c869c8cf Mon Sep 17 00:00:00 2001 From: dhba-odoo Date: Tue, 8 Nov 2022 07:02:38 +0000 Subject: [PATCH] [FIX] website: prevent confirmation modal when discarding without changes Before this commit: When entering edit mode on the website and discarding directly, the editor considers that there are changes in the DOM and displays a confirmation modal. After this commit: When entering edit mode on the website and clicking directly on discard, the confirmation modal is not displayed. Task-3056463 closes odoo/odoo#110515 X-original-commit: 650a97d1bd59254cc2115d54d58940b6112a8d70 Signed-off-by: David Monjoie (dmo) Co-authored-by: Dhaval Baraiya Co-authored-by: David Monjoie Co-authored-by: Nicolas Bayet --- .../static/src/js/wysiwyg/wysiwyg.js | 3 ++- .../wysiwyg_adapter/wysiwyg_adapter.js | 6 ++++-- .../tests/tours/homepage_edit_discard.js | 18 ++++++++++++++++++ addons/website/tests/test_ui.py | 3 +++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 addons/website/static/tests/tours/homepage_edit_discard.js diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 7a40069b13e..36d9e15bc1a 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -845,7 +845,8 @@ const Wysiwyg = Widget.extend({ * @returns {Boolean} */ isDirty: function () { - return this._initialValue !== (this.getValue() || this.$editable.val()); + const isDocumentDirty = this.$editable[0].ownerDocument.defaultView.$(".o_dirty").length; + return this._initialValue !== (this.getValue() || this.$editable.val()) && isDocumentDirty; }, /** * Get the value of the editable element. diff --git a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js index 59d066ebb41..370009b1a93 100644 --- a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js +++ b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js @@ -75,8 +75,6 @@ export class WysiwygAdapterComponent extends ComponentAdapter { if (this.props.beforeEditorActive) { await this.props.beforeEditorActive(this.$editable); } - this._setObserver(); - // The jquery instance inside the iframe needs to be aware of the wysiwyg. this.websiteService.contentWindow.$('#wrapwrap').data('wysiwyg', this.widget); await new Promise((resolve, reject) => this._websiteRootEvent('widgets_start_request', { @@ -92,6 +90,10 @@ export class WysiwygAdapterComponent extends ComponentAdapter { } } this.props.wysiwygReady(); + // Wait for widgets to be destroyed and restarted before setting + // the dirty observer (not to be confused with odooEditor + // observer) as the widgets might trigger DOM mutations. + this._setObserver(); this.widget.odooEditor.observerActive(); }; diff --git a/addons/website/static/tests/tours/homepage_edit_discard.js b/addons/website/static/tests/tours/homepage_edit_discard.js new file mode 100644 index 00000000000..995efb5ea50 --- /dev/null +++ b/addons/website/static/tests/tours/homepage_edit_discard.js @@ -0,0 +1,18 @@ +/** @odoo-module **/ + +import wTourUtils from "website.tour_utils"; + +wTourUtils.registerWebsitePreviewTour('homepage_edit_discard', { + test: true, + url: '/', + edition: true, +}, [{ + trigger: "#oe_snippets button[data-action=\"cancel\"]:not([disabled])", + extra_trigger: "body:not(:has(.o_dialog))", + content: "Click Discard to Discard all Changes.", + position: "bottom", +}, { + trigger: "iframe body:not(.editor_enable)", + auto: true, + run: () => null, +}]); diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index d8552c32b55..6c901fb685a 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -398,3 +398,6 @@ class TestUi(odoo.tests.HttpCase): snippet_key='s_text_block', template_key='website.snippets') self.start_tour('/@/', 'snippet_cache_across_websites', login='admin') + + def test_25_website_edit_discard(self): + self.start_tour('/web', 'homepage_edit_discard', login='admin')