diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-05-19 08:30:03 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-05-19 15:51:57 +0200 |
| commit | a845ecffa13657922ba75dbc7f37c7bad8c0e4c0 (patch) | |
| tree | 8ef24e19054b143341a9537830917207ef299a6d /addons/web_editor/static/src/js/backend.js | |
| parent | 7524b8ef923692ac8498a4ac25365424b17b607a (diff) | |
[FIX] web_editor: field html: save changes done in code mode
Summernote doesn't call the onChange callback when changes are
done in the code mode, so the html field isn't aware of those
changes. It means that if the user does some changes in code mode
and then save directly (without coming back to normal mode), those
changes are lost.
This rev. ensures to save every changes by manually come back to
the normal mode before saving, as this will correctly trigger the
changes. Actually, it simply restores some code of the previous
implementation (before new views) of this widget.
Diffstat (limited to 'addons/web_editor/static/src/js/backend.js')
| -rw-r--r-- | addons/web_editor/static/src/js/backend.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 00faf80c70f..30649f73221 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -3,6 +3,7 @@ odoo.define('web_editor.backend', function (require) { var AbstractField = require('web.AbstractField'); var basic_fields = require('web.basic_fields'); +var config = require('web.config'); var core = require('web.core'); var session = require('web.session'); var field_registry = require('web.field_registry'); @@ -29,6 +30,21 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ //-------------------------------------------------------------------------- /** + * Summernote doesn't notify for changes done in code mode. We override + * commitChanges to manually switch back to normal mode before committing + * changes, so that the widget is aware of the changes done in code mode. + * + * @override + */ + commitChanges: function () { + // switch to WYSIWYG mode if currently in code mode to get all changes + if (config.debug) { + var layoutInfo = this.$textarea.data('layoutInfo'); + $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); + } + this._super.apply(this, arguments); + }, + /** * @override */ isSet: function () { @@ -60,7 +76,7 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ * @returns {Object} the summernote configuration */ _getSummernoteConfig: function () { - var config = { + var summernoteConfig = { focus: false, height: 180, toolbar: [ @@ -79,10 +95,10 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ lang: "odoo", onChange: this._doDebouncedAction.bind(this), }; - if (this.getSession().debug) { - config.toolbar.splice(7, 0, ['view', ['codeview']]); + if (config.debug) { + summernoteConfig.toolbar.splice(7, 0, ['view', ['codeview']]); } - return config; + return summernoteConfig; }, /** * @override |
