odoo.define('mass_mailing.FieldHtml', function (require) { 'use strict'; var config = require('web.config'); var core = require('web.core'); var FieldHtml = require('web_editor.field.html'); var fieldRegistry = require('web.field_registry'); var convertInline = require('web_editor.convertInline'); var _t = core._t; var MassMailingFieldHtml = FieldHtml.extend({ xmlDependencies: (FieldHtml.prototype.xmlDependencies || []).concat(["/mass_mailing/static/src/xml/mass_mailing.xml"]), jsLibs: [ '/mass_mailing/static/src/js/mass_mailing_snippets.js', ], custom_events: _.extend({}, FieldHtml.prototype.custom_events, { snippets_loaded: '_onSnippetsLoaded', }), /** * @override */ init: function () { this._super.apply(this, arguments); if (!this.nodeOptions.snippets) { this.nodeOptions.snippets = 'mass_mailing.email_designer_snippets'; } }, //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- /** * Commit the change in 'style-inline' on an other field nodeOptions: * * - inline-field: fieldName to save the html value converted into inline code * * @override */ commitChanges: function () { var self = this; if (this.mode === 'readonly' || !this.isRendered) { return this._super(); } var fieldName = this.nodeOptions['inline-field']; if (this.$content.find('.o_basic_theme').length) { this.$content.find('*').css('font-family', ''); } var $editable = this.wysiwyg.getEditable(); return this.wysiwyg.save().then(function (result) { self._isDirty = result.isDirty; convertInline.attachmentThumbnailToLinkImg($editable); convertInline.fontToImg($editable); convertInline.classToStyle($editable); self.trigger_up('field_changed', { dataPointID: self.dataPointID, changes: _.object([fieldName], [self._unWrap($editable.html())]) }); if (self._isDirty && self.mode === 'edit') { return self._doAction(); } }); }, /** * The html_frame widget is opened in an iFrame that has its URL encoded * with all the key/values returned by this method. * * Some fields can get very long values and we want to omit them for the URL building. * * @override */ getDatarecord: function () { return _.omit(this._super(), [ 'mailing_domain', 'contact_list_ids', 'body_html', 'attachment_ids' ]); }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** * Add generateOptions options to change wysiwyg configuration: * - Remove table menu in toolbar * - Remove table popover * - Add rules for isEditableNode, the TD must content a not TABLE node as * children to be editable. * * @override */ _getWysiwygOptions: function () { var options = this._super(); options.generateOptions = function (options) { options.toolbar = _.filter(options.toolbar, function (item) { return item[0] !== 'table'; }); delete options.popover.table; var isEditableNode = options.isEditableNode; options.isEditableNode = function (node) { if (node.tagName === "TD" && !$(node).children('*:not(table):first').length) { return false; } return isEditableNode.call(this, node); }; return options; }; return options; }, /** * Returns true if must force the user to choose a theme. * * @private * @returns {Boolean} */ _checkIfMustForceThemeChoice: function () { var firstChoice = this._editableAreaIsEmpty(); this.$content.closest('body').toggleClass("o_force_mail_theme_choice", firstChoice); return firstChoice; }, /** * Returns true if the editable area is empty. * * @private * @param {JQuery} [$layout] * @returns {Boolean} */ _editableAreaIsEmpty: function ($layout) { $layout = $layout || this.$content.find(".o_layout"); var $mailWrapper = $layout.children(".o_mail_wrapper"); var $mailWrapperContent = $mailWrapper.find('.o_mail_wrapper_td'); if (!$mailWrapperContent.length) { // compatibility $mailWrapperContent = $mailWrapper; } var value; if ($mailWrapperContent.length > 0) { value = $mailWrapperContent.html(); } else if ($layout.length) { value = $layout.html(); } else { value = this.wysiwyg.getValue(); } var blankEditable = "


"; return value === "" || value === blankEditable; }, /** * @override */ _renderEdit: function () { this._isFromInline = !this.value; if (!this.value) { this.value = this.recordData[this.nodeOptions['inline-field']]; } return this._super.apply(this, arguments); }, /** * @override * @returns {JQuery} */ _renderTranslateButton: function () { var fieldName = this.nodeOptions['inline-field']; if (_t.database.multi_lang && this.record.fields[fieldName].translate && this.res_id) { return $('