Skip to content
Snippets Groups Projects
Commit e29c0896 authored by Nicolas Lempereur's avatar Nicolas Lempereur
Browse files

[FIX] web_editor: reintroduce source mode in debug


In 12.3 there was a number of changes in source mode. This was reverted
before 13.0 and somehow it seems the source mode was lost between the
12.3 editor changes and its revert.

With this changeset, we introduce back source mode as it was in 12.

opw-2091649
opw-2116960
closes #40026

Signed-off-by: default avatarNicolas Lempereur (nle) <nle@odoo.com>
parent 578dacc3
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ odoo.define('web_editor.field.html', function (require) {
var ajax = require('web.ajax');
var basic_fields = require('web.basic_fields');
var config = require('web.config');
var core = require('web.core');
var Wysiwyg = require('web_editor.wysiwyg.root');
var field_registry = require('web.field_registry');
......@@ -14,6 +15,8 @@ var TranslatableFieldMixin = basic_fields.TranslatableFieldMixin;
var QWeb = core.qweb;
var assetsLoaded;
var jinjaRegex = /(^|\n)\s*%\s(end|set\s)/;
/**
* FieldHtml Widget
* Intended to display HTML content. This widget uses the wysiwyg editor
......@@ -96,6 +99,10 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
*/
commitChanges: function () {
var self = this;
if (config.isDebug() && this.mode === 'edit') {
var layoutInfo = $.summernote.core.dom.makeLayoutInfo(this.wysiwyg.$editor);
$.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false);
}
if (this.mode == "readonly" || !this.isRendered) {
return this._super();
}
......@@ -199,6 +206,20 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
if (para && para[1] && para[1].indexOf('checklist') === -1) {
para[1].splice(2, 0, 'checklist');
}
if (config.isDebug()) {
options.codeview = true;
var view = _.find(options.toolbar, function (item) {
return item[0] === 'view';
});
if (view) {
if (!view[1].includes('codeview')) {
view[1].splice(-1, 0, 'codeview');
}
} else {
options.toolbar.splice(-1, 0, ['view', ['codeview']]);
}
}
options.prettifyHtml = false;
return options;
},
});
......@@ -341,7 +362,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
*/
_textToHtml: function (text) {
var value = text || "";
if (/%\send/.test(value)) { // is jinja
if (jinjaRegex.test(value)) { // is jinja
return value;
}
try {
......@@ -464,6 +485,12 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
top: '+5px',
});
this.$el.append($button);
// force source editor if it contains multiline Jinja directives
if (jinjaRegex.test(this._getValue())) {
var layoutInfo = $.summernote.core.dom.makeLayoutInfo(this.wysiwyg.$editor);
layoutInfo.toolbar().hide();
$.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, true);
}
},
/**
* @private
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment