[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) <dmo@odoo.com>
Co-authored-by: Dhaval Baraiya <dhba@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Nicolas Bayet <nby@odoo.com>
This commit is contained in:
dhba-odoo
2023-01-20 16:54:18 +01:00
committed by David Monjoie
co-authored by David Monjoie Nicolas Bayet
parent 19210a44a8
commit 59101edb9b
4 changed files with 27 additions and 3 deletions
@@ -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.
@@ -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();
};
@@ -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: "<b>Click Discard</b> to Discard all Changes.",
position: "bottom",
}, {
trigger: "iframe body:not(.editor_enable)",
auto: true,
run: () => null,
}]);
+3
View File
@@ -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')