diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-08-10 13:19:05 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-08-10 13:56:22 +0200 |
| commit | deba788b4cdc22bb50e0c19adb5ed35ed33c0a01 (patch) | |
| tree | d0c7eb0fae9d6257bca76e4b7f1d2652c9b3d975 /addons | |
| parent | 87133a8235aa71db49566e9a1179ab66b68e87ec (diff) | |
[FIX] web_editor: html_frame: saving in readonly
A form view record may be saved even if the record is displayed in
readonly (e.g. when a button in the form view is clicked). When
this happened, if there were an html field with html_frame widget
in the form, it crashed (e.g. in Email Marketing > Mass Mailings >
open one > click on Test Mailing).
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/web_editor/static/src/js/backend.js | 2 | ||||
| -rw-r--r-- | addons/web_editor/static/tests/web_editor_tests.js | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 06053dd1cea..6b167c59edd 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -383,7 +383,7 @@ var FieldTextHtml = AbstractField.extend({ * @override */ commitChanges: function () { - if (!this.loaded) { + if (!this.loaded || this.mode === 'readonly') { return; } // switch to WYSIWYG mode if currently in code mode to get all changes diff --git a/addons/web_editor/static/tests/web_editor_tests.js b/addons/web_editor/static/tests/web_editor_tests.js index 283931e9b0d..41ada113cba 100644 --- a/addons/web_editor/static/tests/web_editor_tests.js +++ b/addons/web_editor/static/tests/web_editor_tests.js @@ -188,4 +188,34 @@ QUnit.test('field htmlsimple does not crash when commitChanges is called in mode form.destroy(); }); +QUnit.test('html_frame does not crash when saving in readonly', function (assert) { + // The 'Save' action may be triggered even in readonly (e.g. when clicking + // on a button in the form view) + assert.expect(0); + + var form = testUtils.createView({ + View: FormView, + model: 'mass.mailing', + data: this.data, + arch: '<form string="Partners">' + + '<sheet>' + + '<field name="body" widget="html_frame" options="{\'editor_url\': \'/test\'}"/>' + + '</sheet>' + + '</form>', + res_id: 1, + mockRPC: function (route) { + if (_.str.startsWith(route, '/test')) { + // manually call the callback to simulate that the iframe has + // been correctly loaded + window.odoo[$.deparam(route).callback + '_content'].call(); + return $.when(); + } + return this._super.apply(this, arguments); + }, + }); + + form.saveRecord(); // before the fix done in this commit, it crashed here + form.destroy(); +}); + }); |
