[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) <dmo@odoo.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user