diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-01-10 12:07:44 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-01-10 12:07:44 +0100 |
| commit | f1583504cebe0d0fb87ccfe24773f9280770864d (patch) | |
| tree | 7bf3d9cfe56a0a9207c00c8dc48bd6805763ace0 /addons/web_editor/static/src | |
| parent | 9073ecb6f59e1834bdd5e1aed96d6be4b03b00d5 (diff) | |
| parent | 3f7b1f608344fed2f79d08ec602a700ec34c70cb (diff) | |
[MERGE] forward port branch 9.0 up to 3f7b1f60834
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 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/tour.rte.js | 45 |
3 files changed, 76 insertions, 1 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 36cd33c60fd..3585ddfdb9a 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); @@ -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) { + /* 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 73565e19743..97574c0cb86 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -539,12 +539,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 diff --git a/addons/web_editor/static/src/js/tour.rte.js b/addons/web_editor/static/src/js/tour.rte.js index 2d85600e578..5ca69cd0e13 100644 --- a/addons/web_editor/static/src/js/tour.rte.js +++ b/addons/web_editor/static/src/js/tour.rte.js @@ -403,6 +403,51 @@ Tour.register({ }); +Tour.register({ + id: 'rte_backend_inline', + name: "Test RTE in backend view", + mode: 'test', + steps: [ + { + title: "Beginning test", + }, + { + title: "Click on edit button", + element: '.o_form_button_edit, .oe_form_button_edit', + }, + { + title: "Add text to inline html field and save", + element: '.o_form_button_save, .oe_form_button_save', + onload: function(){ + $('.oe_form_field_html_text .note-editable > p').append('<i>world</i>'); + }, + }, + { + title: "Verify saved data after edition then click on edit button", + waitFor: '.oe_form_field_html_text p > i:last-child:contains(world)', + element: '.o_form_button_edit, .oe_form_button_edit', + }, + { + title: "Switch to code view mode", + element: 'button[data-event="codeview"]', + }, + { + title: "Modify code view content and save", + element: '.o_form_button_save, .oe_form_button_save', + onload: function(){ + $('.oe_form_field_html_text textarea.note-codable').val(function(_, val){ + return val.replace('</p>', '<u>!</u></p>'); + }); + }, + }, + { + title: "Verify saved data after code view edition", + waitFor: '.oe_form_field_html_text p > u:last-child:contains(!)', + }, + ] +}); + + }); }); |
