From e42dc39e37ac577c44a68409ef597be5a172eae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Thu, 28 Apr 2022 13:49:43 +0000 Subject: [PATCH] [FIX] web_editor: fix isDirty() in wysiwyg.js The isDirty method of the wysiwyg was not very accurate and was most of the time returning true even if no changes were done in the editor. task-2692125 closes odoo/odoo#90200 X-original-commit: bab673488e185ddd7792aedecc3870663290fed3 Signed-off-by: David Monjoie (dmo) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 11 +++++++---- addons/website/static/src/js/menu/edit.js | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 4022348ceb0..b906c16261f 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -98,11 +98,12 @@ const Wysiwyg = Widget.extend({ const self = this; var options = this._editorOptions(); - this._value = options.value; this.options.isInternalUser = await session.user_has_group('base.group_user'); this.$editable = this.$editable || this.$el; - this.$editable.html(this._value); + if (options.value) { + this.$editable.html(options.value); + } this.$editable.data('wysiwyg', this); this.$editable.data('oe-model', options.recordInfo.res_model); this.$editable.data('oe-id', options.recordInfo.res_id); @@ -178,6 +179,7 @@ const Wysiwyg = Widget.extend({ this.odooEditor.document.addEventListener("keyup", this._signalOnline, true); } + this._initialValue = this.getValue(); const $wrapwrap = $('#wrapwrap'); if ($wrapwrap.length) { $wrapwrap[0].addEventListener('scroll', this.odooEditor.multiselectionRefresh, { passive: true }); @@ -742,7 +744,7 @@ const Wysiwyg = Widget.extend({ * @returns {Boolean} */ isDirty: function () { - return this._value !== (this.$editable.html() || this.$editable.val()); + return this._initialValue !== (this.getValue() || this.$editable.val()); }, /** * Get the value of the editable element. @@ -759,6 +761,7 @@ const Wysiwyg = Widget.extend({ $editable.find('[title=""]').removeAttr('title'); $editable.find('[alt=""]').removeAttr('alt'); $editable.find('[data-original-title=""]').removeAttr('data-original-title'); + $editable.find('[data-editor-message]').removeAttr('data-editor-message'); $editable.find('a.o_image, span.fa, i.fa').html(''); $editable.find('[aria-describedby]').removeAttr('aria-describedby').removeAttr('data-original-title'); this.odooEditor.cleanForSave($editable[0]); @@ -780,7 +783,7 @@ const Wysiwyg = Widget.extend({ } else { this.$editable.html(html); } - return Promise.resolve({isDirty:isDirty, html:html}); + return Promise.resolve({isDirty: isDirty, html: html}); }, /** * Save the content for the normal mode or the translation mode. diff --git a/addons/website/static/src/js/menu/edit.js b/addons/website/static/src/js/menu/edit.js index 7c9ca6949f8..253cd51910b 100644 --- a/addons/website/static/src/js/menu/edit.js +++ b/addons/website/static/src/js/menu/edit.js @@ -116,7 +116,9 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ self.destroy(); }; if (!this.wysiwyg.isDirty()) { - return destroy(); + destroy(); + window.location.reload(); + return; } return this.wysiwyg.saveContent(false).then((result) => { var $wrapwrap = $('#wrapwrap');