From f217aa528f0288151ab48b551c3b9a327fd92edb Mon Sep 17 00:00:00 2001 From: mgh-odoo Date: Tue, 5 Feb 2019 11:03:23 +0000 Subject: [PATCH] [FIX]web_editor: Fixed traceback due to 'field_html' widget while saving record Previously, when user edited record having 'field_html' widget and tried to save the record immediately, a traceback was faced sometimes because content was not loaded yet. This commit fixes the issue by calling super method if the content is not loaded yet properly. Task: #1932687 Closes: #30833 closes odoo/odoo#31581 Signed-off-by: VincentSchippefilt --- .../static/src/js/mass_mailing_widget.js | 3 +++ .../static/src/js/backend/field_html.js | 4 +++- .../static/tests/field_html_tests.js | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/mass_mailing/static/src/js/mass_mailing_widget.js b/addons/mass_mailing/static/src/js/mass_mailing_widget.js index e87c6a11f70..64f8dd60e8b 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_widget.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_widget.js @@ -43,6 +43,9 @@ var MassMailingFieldHtml = FieldHtml.extend({ */ commitChanges: function () { var self = this; + if (!this.wysiwyg || !this.isRendered) { + return this._super(); + } var fieldName = this.nodeOptions['inline-field']; if (this.$content.find('.o_basic_theme').length) { diff --git a/addons/web_editor/static/src/js/backend/field_html.js b/addons/web_editor/static/src/js/backend/field_html.js index b78fcc1d35f..ef443889484 100644 --- a/addons/web_editor/static/src/js/backend/field_html.js +++ b/addons/web_editor/static/src/js/backend/field_html.js @@ -39,6 +39,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { * @override */ willStart: function () { + this.isRendered = false; this._onUpdateIframeId = 'onLoad_' + _.uniqueId('FieldHtml'); var defAsset = null; if (this.nodeOptions.cssReadonly) { @@ -91,7 +92,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { */ commitChanges: function () { var self = this; - if (!this.wysiwyg) { + if (!this.wysiwyg || !this.isRendered) { return this._super(); } var _super = this._super.bind(this); @@ -164,6 +165,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { return this.wysiwyg.attachTo(this.$target).then(function () { self.$content = self.wysiwyg.$editor; self._onLoadWysiwyg(); + self.isRendered = true; }); }, /** diff --git a/addons/web_editor/static/tests/field_html_tests.js b/addons/web_editor/static/tests/field_html_tests.js index 46e66eed81e..eafb273a3b6 100644 --- a/addons/web_editor/static/tests/field_html_tests.js +++ b/addons/web_editor/static/tests/field_html_tests.js @@ -517,6 +517,27 @@ QUnit.test('rendering with iframe for edit mode', function (assert) { }); }); +QUnit.test('save immediately before iframe is rendered in edit mode', function (assert) { + var done = assert.async(); + assert.expect(1); + + testUtils.createAsyncView({ + View: FormView, + model: 'note.note', + data: this.data, + arch: '
' + + '' + + '', + res_id: 1, + }).then(function (form) { + testUtils.form.clickEdit(form); + testUtils.form.clickSave(form); + assert.ok(true, "No traceback encountered. The wysiwyg was cut while not loaded."); + form.destroy(); + done(); + }); +}); + QUnit.test('use colorpicker and save', function (assert) { var done = assert.async(); assert.expect(1);