[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.
This commit is contained in:
@@ -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');
|
||||
@@ -28,6 +29,21 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user