[IMP] web_editor: don't lose modified code view content

The scenario when using the code view is the following :

- click on code view button to use code view
- make changes
- click on code view button to get back to wysiwyg view
- save from the wysiwyg view

If the 3rd step is not done:

- for the inline editor, we lose the changes that have been done in code
  view,
- for the iframe editor, we lose the entirety of the content.

At one time the user was forced to go back to wysiwyg before being able
to save, but this have been removed hence the present usability issue.

With this fix, when the editor content is saved, if the user is in code
view he is automatically set back to wysiwyg view.

closes #14339
opw-693052
This commit is contained in:
Nicolas Lempereur
2016-11-16 14:06:01 +01:00
parent 9f172a61e0
commit 897290dd3f
2 changed files with 12 additions and 0 deletions
@@ -161,6 +161,11 @@ var FieldTextHtmlSimple = widget.extend({
return !this.get('value') || this.get('value') === "<p><br/></p>" || !this.get('value').match(/\S/);
},
commit_value: function() {
// leave code view before saving
if (this.$content.prev('textarea').length === 1) {
var layoutInfo = { 'editor': function() { return this.$content; }.bind(this) };
$.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo);
}
if (this.options['style-inline']) {
transcoder.class_to_style(this.$content);
transcoder.font_to_img(this.$content);
@@ -374,6 +379,11 @@ var FieldTextHtml = widget.extend({
this._dirty_flag = false;
return this.editor.save();
} else if (this._dirty_flag && this.editor && this.editor.buildingBlock) {
// leave code view before saving
if (this.$content.prev('textarea').length === 1) {
var layoutInfo = { 'editor': function() { return this.$content; }.bind(this) };
$.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo);
}
this.editor.buildingBlock.clean_for_save();
this.internal_set_value( this.$content.html() );
}
@@ -485,6 +485,8 @@ function prettify_html(html) {
}
return result;
}
// Change Warning: called with dummy arguments to quit code view before saving
$.summernote.pluginEvents.codeview = function (event, editor, layoutInfo) {
if (layoutInfo.toolbar) {
return eventHandler.modules.codeview.toggle(layoutInfo);