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_link_dialog_fix.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'; } // All the code related to this __extraAssetsForIframe variable is an // ugly hack to restore mass mailing options in stable versions. The // whole logic has to be refactored as soon as possible... this.__extraAssetsForIframe = [{ jsLibs: ['/mass_mailing/static/src/js/mass_mailing_snippets.js'], }]; }, //-------------------------------------------------------------------------- // 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 (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(); } 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.saveModifiedImages(this.$content).then(function () { return self.wysiwyg.save().then(function (result) { self._isDirty = result.isDirty; convertInline.attachmentThumbnailToLinkImg($editable); convertInline.fontToImg($editable); convertInline.classToStyle($editable); // fix outlook image rendering bug _.each(['width', 'height'], function(attribute) { $editable.find('img[style*="width"], img[style*="height"]').attr(attribute, function(){ return $(this)[attribute](); }).css(attribute, function(){ return $(this).get(0).style[attribute] || 'auto'; }); }); self.trigger_up('field_changed', { dataPointID: self.dataPointID, changes: _.object([fieldName], [self._unWrap($editable.html())]) }); self.wysiwyg.setValue(result.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 //-------------------------------------------------------------------------- /** * 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 */ _renderReadonly: function () { 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 $('