From cad943d035c200cce4a7e5a428d2883bf2452b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 29 May 2017 10:12:43 +0200 Subject: [PATCH] [FIX] web_editor: prevent crash with FieldTextHtmlSimple If the method commitChange from the widget FieldTextHtmlSimple was called in mode=readonly, a traceback was displayed. This is not very common, because most save operations are done in mode=edit, but it can happen in readonly mode: when the user clicks on an action button, then the form view is saved, if necessary. To reproduce this bug, just open a form view for res.users, and click on the Change Password button. --- addons/web_editor/static/src/js/backend.js | 2 +- .../static/tests/web_editor_tests.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 8895ee0b99a..c12ab41b4bb 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -39,7 +39,7 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ */ commitChanges: function () { // switch to WYSIWYG mode if currently in code mode to get all changes - if (config.debug) { + if (config.debug && this.mode === 'edit') { var layoutInfo = this.$textarea.data('layoutInfo'); $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); } diff --git a/addons/web_editor/static/tests/web_editor_tests.js b/addons/web_editor/static/tests/web_editor_tests.js index 6a18566af2b..a053ad99043 100644 --- a/addons/web_editor/static/tests/web_editor_tests.js +++ b/addons/web_editor/static/tests/web_editor_tests.js @@ -121,4 +121,31 @@ QUnit.test('field html_frame widget', function (assert) { form.destroy(); }); +QUnit.test('field htmlsimple does not crash when commitChanges is called in mode=readonly', function (assert) { + assert.expect(1); + + var form = testUtils.createView({ + View: FormView, + model: 'mass.mailing', + data: this.data, + arch: '
' + + '
' + + '
' + + '' + + '' + + '' + + '
', + res_id: 1, + intercepts: { + execute_action: function () { + assert.step('execute_action'); + } + }, + }); + + form.$('button:contains(Do it)').click(); + form.destroy(); +}); + });