diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-01-10 13:46:17 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-01-10 13:46:17 +0100 |
| commit | 482fd04167410885264d5903ea621682f5f917db (patch) | |
| tree | 602a2e02e59fb195243f79dd808e68a8775a0a8e /addons/web_editor/static/src | |
| parent | 23d07478e3c8a7beff4bb9cec6c4ba0c4b75043e (diff) | |
| parent | f1583504cebe0d0fb87ccfe24773f9280770864d (diff) | |
[MERGE] forward port branch saas-11 up to f1583504ceb
Diffstat (limited to 'addons/web_editor/static/src')
| -rw-r--r-- | addons/web_editor/static/src/js/backend.js | 10 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/rte.summernote.js | 22 |
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 9c6f1df5e8c..ce8643f04de 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -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 () { + /* Switch to WYSIWYG mode if currently in code view */ + if (session.debug) { + var layoutInfo = this.$textarea.data('layoutInfo'); + $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); + } if (this.options['style-inline']) { transcoder.class_to_style(this.$content); transcoder.font_to_img(this.$content); @@ -377,6 +382,11 @@ var FieldTextHtml = widget.extend({ this._dirty_flag = false; return this.editor.save(); } else if (this._dirty_flag && this.editor && this.editor.buildingBlock) { + /* Switch to WYSIWYG mode if currently in code view */ + if (session.debug) { + var layoutInfo = this.editor.rte.editable().data('layoutInfo'); + $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); + } this.editor.buildingBlock.clean_for_save(); this.internal_set_value( this.$content.html() ); } diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js index 1789ed69e7e..9f908a245bc 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -511,12 +511,32 @@ function prettify_html(html) { } return result; } -$.summernote.pluginEvents.codeview = function (event, editor, layoutInfo) { + +/* + * This override when clicking on the 'Code View' button has two aims: + * + * - have our own code view implementation for FieldTextHtml + * - add an 'enable' paramater to call the function directly and allow us to + * disable (false) or enable (true) the code view mode. + */ +$.summernote.pluginEvents.codeview = function (event, editor, layoutInfo, enable) { + if (layoutInfo === undefined) { + return; + } if (layoutInfo.toolbar) { + // if editor inline (FieldTextHtmlSimple) + var is_activated = $.summernote.eventHandler.modules.codeview.isActivated(layoutInfo); + if (is_activated === enable) { + return; + } return eventHandler.modules.codeview.toggle(layoutInfo); } else { + // if editor iframe (FieldTextHtml) var $editor = layoutInfo.editor(); var $textarea = $editor.prev('textarea'); + if ($textarea.is('textarea') === enable) { + return; + } if (!$textarea.length) { // init and create texarea |
