diff options
| author | Christophe Matthieu <chm@odoo.com> | 2016-06-23 11:45:17 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2016-06-23 11:45:17 +0200 |
| commit | 025263d3bfe568ae862fdb227b1a39b079a456fc (patch) | |
| tree | 4464702cbe21fcca42b9ef20ad633a6d44c1190f /addons/web_editor/static/src/js/backend.js | |
| parent | 2e785a886905333758497150b17b0df1d0ef66d6 (diff) | |
Revert "[FIX] web_editor: test jinja content to load editor in codeview"
This reverts commit f38f8930f0436a40f675fa1d054a9d46f550d440.
Revert for internal choice. Odoo want to use qweb in template and remove jinja support on next version.
If users want to use jinja they can change the view to use text widget instead of html widget.
Diffstat (limited to 'addons/web_editor/static/src/js/backend.js')
| -rw-r--r-- | addons/web_editor/static/src/js/backend.js | 90 |
1 files changed, 10 insertions, 80 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 9491c283ef3..fa962cfd75f 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -8,11 +8,8 @@ var common = require('web.form_common'); var base = require('web_editor.base'); var editor = require('web_editor.editor'); var summernote = require('web_editor.summernote'); -require('web_editor.rte.summernote'); var transcoder = require('web_editor.transcoder'); -var form_widgets = require('web.form_widgets'); - var QWeb = core.qweb; var _t = core._t; @@ -23,43 +20,6 @@ var _t = core._t; */ var widget = common.AbstractField.extend(common.ReinitializeFieldMixin); -var dom = $.summernote.core.dom; - -var _html = dom.html; -dom.html = function ($dom, prettifyHtml) { - if (prettifyHtml) { - transcoder.font_to_img($dom); - transcoder.class_to_style($dom); - - // fix outlook image rendering bug - _.each(['width', 'height'], function(attribute) { - $dom.find('img[style*="width"], img[style*="height"]').attr(attribute, function(){ - return $(this)[attribute](); - }).css(attribute, function(){ - return $(this).get(0).style[attribute] || 'auto'; - }); - }); - } - return _html($dom, prettifyHtml); -}; - -var _value = dom.value; -dom.value = function ($dom, stripLinebreaks, $editable) { - var value = _value($dom, stripLinebreaks); - if (stripLinebreaks) { - $editable = $editable || $('<div/>'); - $editable.html(value); - transcoder.img_to_font($editable); - transcoder.style_to_class($editable); - - // fix outlook image rendering bug - $editable.find('img[style*="width"], img[style*="height"]').removeAttr('height width'); - - value = $editable.html(); - } - return value; -}; - var FieldTextHtmlSimple = widget.extend({ template: 'web_editor.FieldTextHtmlSimple', @@ -78,12 +38,13 @@ var FieldTextHtmlSimple = widget.extend({ ['insert', ['link', 'picture']], ['history', ['undo', 'redo']] ], - 'prettifyHtml': !!this.options['style-inline'], + 'prettifyHtml': false, 'styleWithSpan': false, 'inlinemedia': ['p'], 'lang': "odoo", 'onChange': function (value) { self.internal_set_value(value); + self.trigger('changed_value'); } }; if (session.debug) { @@ -92,7 +53,6 @@ var FieldTextHtmlSimple = widget.extend({ return config; }, start: function() { - var self = this; var def = this._super.apply(this, arguments); this.$translate.remove(); this.$translate = $(); @@ -134,22 +94,9 @@ var FieldTextHtmlSimple = widget.extend({ setTimeout(reset, 0); this.$content = this.$('.note-editable:first'); - this.$content.html(dom.value(this.$textarea, this.options['style-inline'], this.$content)); - - var layoutInfo = this.$textarea.data('layoutInfo'); - var $codable = layoutInfo.codable(); - var $toolbar = layoutInfo.toolbar(); - $toolbar.find('button[data-event="codeview"]').on('click', function (event) { - if ($codable.is(':visible')) { - if (dom.check_unvalid_preview($codable.val())) { - event.preventDefault(); - self.do_notify(_t("You can't use html preview when you use non html code (like jinja)")); - } - } - }); - $codable.on('input', function () { - self.internal_set_value($codable.val()); - }); + if (this.options['style-inline']) { + transcoder.style_to_class(this.$content); + } } $(".oe-view-manager-content").on("scroll", function () { @@ -168,11 +115,11 @@ var FieldTextHtmlSimple = widget.extend({ var value = text || ""; if (value.match(/^\s*$/)) { value = '<p><br/></p>'; - } else if (!value.match(/<(a|span|font|strong|u|i|strong|b|td|p)[^>]*>/i)) { + } else { value = "<p>"+value.split(/<br\/?>/).join("<br/></p><p>")+"</p>"; - value = value.replace(/<p[^>]*><p([^>]*)>/g, '<p\$1>').replace('</p></p>', '</p>'); + value = value.replace(/<p><\/p>/g, '').replace('<p><p>', '<p>').replace('<p><p ', '<p ').replace('</p></p>', '</p>'); } - return value.replace(/<p[^>]*><\/p>/g, ''); + return value; }, focus: function() { if (this.get("effective_readonly")) { @@ -192,22 +139,10 @@ var FieldTextHtmlSimple = widget.extend({ var value = this.get('value'); this.$textarea.val(value || ''); this.$content.html(this.text_to_html(value)); - - var layoutInfo = this.$textarea.data('layoutInfo'); - if (layoutInfo) { - var $codable = layoutInfo.codable(); - $codable.val(value); - var $toolbar = layoutInfo.toolbar(); - if ($codable.is(':visible') != !!dom.check_unvalid_preview(value)) { - $toolbar.find('button[data-event="codeview"]').trigger('click'); - } - } - if (this.get("effective_readonly")) { this.resize(); } else { transcoder.style_to_class(this.$content); - transcoder.img_to_font(this.$content); } if (this.$content.is(document.activeElement)) { this.focus(); @@ -221,11 +156,6 @@ var FieldTextHtmlSimple = widget.extend({ return !this.get('value') || this.get('value') === "<p><br/></p>" || !this.get('value').match(/\S/); }, commit_value: function() { - var layoutInfo = this.$textarea.data('layoutInfo'); - if (layoutInfo && layoutInfo.codable().is(':visible')) { - return this.internal_set_value(layoutInfo.codable().val()); - } - if (this.options['style-inline']) { transcoder.class_to_style(this.$content); transcoder.font_to_img(this.$content); @@ -239,7 +169,6 @@ var FieldTextHtmlSimple = widget.extend({ } }); - var FieldTextHtml = widget.extend({ template: 'web_editor.FieldTextHtml', willStart: function () { @@ -438,7 +367,8 @@ var FieldTextHtml = widget.extend({ this._dirty_flag = false; return this.editor.save(); } else if (this._dirty_flag && this.editor && this.editor.buildingBlock) { - this.internal_set_value( this.editor.buildingBlock.get_codesource() ); + this.editor.buildingBlock.clean_for_save(); + this.internal_set_value( this.$content.html() ); } }, destroy: function () { |
