From 4f925af06fd3cebfcfb56eb947ab68c8a2ca4490 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 7 Jun 2017 17:45:15 +0200 Subject: [MOV] web_editor, website: reorganize files --- addons/web_editor/static/src/js/backend/fields.js | 409 ++++++++++++++++++++++ 1 file changed, 409 insertions(+) create mode 100644 addons/web_editor/static/src/js/backend/fields.js (limited to 'addons/web_editor/static/src/js/backend/fields.js') diff --git a/addons/web_editor/static/src/js/backend/fields.js b/addons/web_editor/static/src/js/backend/fields.js new file mode 100644 index 00000000000..6b167c59edd --- /dev/null +++ b/addons/web_editor/static/src/js/backend/fields.js @@ -0,0 +1,409 @@ +odoo.define('web_editor.backend', function (require) { +'use strict'; + +var AbstractField = require('web.AbstractField'); +var basic_fields = require('web.basic_fields'); +var config = require('web.config'); +var core = require('web.core'); +var session = require('web.session'); +var field_registry = require('web.field_registry'); + +var transcoder = require('web_editor.transcoder'); + +var TranslatableFieldMixin = basic_fields.TranslatableFieldMixin; + +var QWeb = core.qweb; +var _t = core._t; + + +/** + * FieldTextHtmlSimple Widget + * Intended to display HTML content. This widget uses the summernote editor + * improved by odoo. + * + */ +var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { + className: 'oe_form_field oe_form_field_html_text', + supportedFieldTypes: ['html'], + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Summernote doesn't notify for changes done in code mode. We override + * commitChanges to manually switch back to normal mode before committing + * changes, so that the widget is aware of the changes done in code mode. + * + * @override + */ + commitChanges: function () { + // switch to WYSIWYG mode if currently in code mode to get all changes + if (config.debug && this.mode === 'edit') { + var layoutInfo = this.$textarea.data('layoutInfo'); + $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); + } + this._super.apply(this, arguments); + }, + /** + * @override + */ + isSet: function () { + return this.value && this.value !== "


" && this.value.match(/\S/); + }, + /** + * Do not re-render this field if it was the origin of the onchange call. + * + * @override + */ + reset: function (record, event) { + this._reset(record, event); + if (!event || event.target !== this) { + if (this.mode === 'edit') { + this.$content.html(this._textToHtml(this.value)); + } else { + this._renderReadonly(); + } + } + return $.when(); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @returns {Object} the summernote configuration + */ + _getSummernoteConfig: function () { + var summernoteConfig = { + focus: false, + height: 180, + toolbar: [ + ['style', ['style']], + ['font', ['bold', 'italic', 'underline', 'clear']], + ['fontsize', ['fontsize']], + ['color', ['color']], + ['para', ['ul', 'ol', 'paragraph']], + ['table', ['table']], + ['insert', ['link', 'picture']], + ['history', ['undo', 'redo']] + ], + prettifyHtml: false, + styleWithSpan: false, + inlinemedia: ['p'], + lang: "odoo", + onChange: this._doDebouncedAction.bind(this), + }; + if (config.debug) { + summernoteConfig.toolbar.splice(7, 0, ['view', ['codeview']]); + } + return summernoteConfig; + }, + /** + * @override + * @private + */ + _getValue: function () { + if (this.nodeOptions['style-inline']) { + transcoder.class_to_style(this.$content); + transcoder.font_to_img(this.$content); + } + return this.$content.html(); + }, + /** + * @override + * @private + */ + _renderEdit: function () { + this.$textarea = $('