From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/mass_mailing/static/src/js/mass_mailing.js | 15 + .../static/src/js/mass_mailing_link_dialog_fix.js | 75 +++ .../src/js/mass_mailing_list_kanban_record.js | 18 + .../src/js/mass_mailing_list_kanban_renderer.js | 16 + .../static/src/js/mass_mailing_list_kanban_view.js | 19 + .../static/src/js/mass_mailing_snippets.js | 153 ++++++ .../static/src/js/mass_mailing_widget.js | 520 +++++++++++++++++++++ .../static/src/js/tours/mass_mailing_tour.js | 88 ++++ addons/mass_mailing/static/src/js/unsubscribe.js | 198 ++++++++ 9 files changed, 1102 insertions(+) create mode 100644 addons/mass_mailing/static/src/js/mass_mailing.js create mode 100644 addons/mass_mailing/static/src/js/mass_mailing_link_dialog_fix.js create mode 100644 addons/mass_mailing/static/src/js/mass_mailing_list_kanban_record.js create mode 100644 addons/mass_mailing/static/src/js/mass_mailing_list_kanban_renderer.js create mode 100644 addons/mass_mailing/static/src/js/mass_mailing_list_kanban_view.js create mode 100644 addons/mass_mailing/static/src/js/mass_mailing_snippets.js create mode 100644 addons/mass_mailing/static/src/js/mass_mailing_widget.js create mode 100644 addons/mass_mailing/static/src/js/tours/mass_mailing_tour.js create mode 100644 addons/mass_mailing/static/src/js/unsubscribe.js (limited to 'addons/mass_mailing/static/src/js') diff --git a/addons/mass_mailing/static/src/js/mass_mailing.js b/addons/mass_mailing/static/src/js/mass_mailing.js new file mode 100644 index 00000000..e74d97f5 --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing.js @@ -0,0 +1,15 @@ +odoo.define('mass_mailing.mass_mailing', function (require) { +"use strict"; + +var KanbanColumn = require('web.KanbanColumn'); + +KanbanColumn.include({ + init: function () { + this._super.apply(this, arguments); + if (this.modelName === 'mailing.mailing') { + this.draggable = false; + } + }, +}); + +}); diff --git a/addons/mass_mailing/static/src/js/mass_mailing_link_dialog_fix.js b/addons/mass_mailing/static/src/js/mass_mailing_link_dialog_fix.js new file mode 100644 index 00000000..6b46340b --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing_link_dialog_fix.js @@ -0,0 +1,75 @@ + +odoo.define('mass_mailing.fix.LinkDialog', function (require) { +'use strict'; + +const LinkDialog = require('wysiwyg.widgets.LinkDialog'); + +/** + * Primary and link buttons are "hacked" by mailing themes scss. We thus + * have to fix their preview if possible. + */ +LinkDialog.include({ + /** + * @override + */ + start() { + const ret = this._super(...arguments); + if (!$(this.editable).find('.o_mail_wrapper').length) { + return ret; + } + + this.opened().then(() => { + // Ugly hack to show the real color for link and primary which + // depend on the mailing themes. Note: the hack is not enough as + // the mailing theme changes those colors in some environment, + // sometimes (for example 'btn-primary in this snippet looks like + // that')... we'll consider this a limitation until a master + // refactoring of those mailing themes. + this.__realMMColors = {}; + const $previewArea = $('
').addClass('o_mail_snippet_general'); + $(this.editable).find('.o_layout').append($previewArea); + _.each(['link', 'primary', 'secondary'], type => { + const $el = $(''); + $el.appendTo($previewArea); + this.__realMMColors[type] = { + 'border-color': $el.css('border-top-color'), + 'background-color': $el.css('background-color'), + 'color': $el.css('color'), + }; + $el.remove(); + + this.$('.form-group .o_btn_preview.btn-' + type) + .css(_.pick(this.__realMMColors[type], 'background-color', 'color')); + }); + $previewArea.remove(); + + this._adaptPreview(); + }); + + return ret; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + _adaptPreview() { + this._super(...arguments); + if (this.__realMMColors) { + var $preview = this.$("#link-preview"); + $preview.css('border-color', ''); + $preview.css('background-color', ''); + $preview.css('color', ''); + _.each(['link', 'primary', 'secondary'], type => { + if ($preview.hasClass('btn-' + type) || type === 'link' && !$preview.hasClass('btn')) { + $preview.css(this.__realMMColors[type]); + } + }); + } + }, +}); + +}); diff --git a/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_record.js b/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_record.js new file mode 100644 index 00000000..52d7076b --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_record.js @@ -0,0 +1,18 @@ +odoo.define('mass_mailing.ListKanbanRecord', function (require) { +"use strict"; + +var KanbanRecord = require('web.KanbanRecord'); + +var MassMailingListKanbanRecord = KanbanRecord.extend({ + /** + * @override + * @private + */ + _openRecord: function () { + this.$('.o_mailing_list_kanban_boxes a').first().click(); + } +}); + +return MassMailingListKanbanRecord; + +}); diff --git a/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_renderer.js b/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_renderer.js new file mode 100644 index 00000000..b9804e72 --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_renderer.js @@ -0,0 +1,16 @@ +odoo.define('mass_mailing.ListKanbanRenderer', function (require) { +"use strict"; + +var MassMailingListKanbanRecord = require('mass_mailing.ListKanbanRecord'); + +var KanbanRenderer = require('web.KanbanRenderer'); + +var MassMailingListKanbanRenderer = KanbanRenderer.extend({ + config: _.extend({}, KanbanRenderer.prototype.config, { + KanbanRecord: MassMailingListKanbanRecord, + }) +}); + +return MassMailingListKanbanRenderer; + +}); diff --git a/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_view.js b/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_view.js new file mode 100644 index 00000000..86bac695 --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing_list_kanban_view.js @@ -0,0 +1,19 @@ +odoo.define('mass_mailing.ListKanbanView', function (require) { +"use strict"; + +var MassMailingListKanbanRenderer = require('mass_mailing.ListKanbanRenderer'); + +var KanbanView = require('web.KanbanView'); +var view_registry = require('web.view_registry'); + +var MassMailingListKanbanView = KanbanView.extend({ + config: _.extend({}, KanbanView.prototype.config, { + Renderer: MassMailingListKanbanRenderer, + }), +}); + +view_registry.add('mass_mailing_list_kanban', MassMailingListKanbanView); + +return MassMailingListKanbanView; + +}); diff --git a/addons/mass_mailing/static/src/js/mass_mailing_snippets.js b/addons/mass_mailing/static/src/js/mass_mailing_snippets.js new file mode 100644 index 00000000..ef4bd007 --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing_snippets.js @@ -0,0 +1,153 @@ +odoo.define('mass_mailing.snippets.options', function (require) { +"use strict"; + +var options = require('web_editor.snippets.options'); + +// Snippet option for resizing image and column width inline like excel +options.registry.mass_mailing_sizing_x = options.Class.extend({ + /** + * @override + */ + start: function () { + var def = this._super.apply(this, arguments); + + this.containerWidth = this.$target.parent().closest("td, table, div").width(); + + var self = this; + var offset, sib_offset, target_width, sib_width; + + this.$overlay.find(".o_handle.e, .o_handle.w").removeClass("readonly"); + this.isIMG = this.$target.is("img"); + if (this.isIMG) { + this.$overlay.find(".o_handle.w").addClass("readonly"); + } + + var $body = $(this.ownerDocument.body); + this.$overlay.find(".o_handle").on('mousedown', function (event) { + event.preventDefault(); + var $handle = $(this); + var compass = false; + + _.each(['n', 's', 'e', 'w'], function (handler) { + if ($handle.hasClass(handler)) { compass = handler; } + }); + if (self.isIMG) { compass = "image"; } + + $body.on("mousemove.mass_mailing_width_x", function (event) { + event.preventDefault(); + offset = self.$target.offset().left; + target_width = self.get_max_width(self.$target); + if (compass === 'e' && self.$target.next().offset()) { + sib_width = self.get_max_width(self.$target.next()); + sib_offset = self.$target.next().offset().left; + self.change_width(event, self.$target, target_width, offset, true); + self.change_width(event, self.$target.next(), sib_width, sib_offset, false); + } + if (compass === 'w' && self.$target.prev().offset()) { + sib_width = self.get_max_width(self.$target.prev()); + sib_offset = self.$target.prev().offset().left; + self.change_width(event, self.$target, target_width, offset, false); + self.change_width(event, self.$target.prev(), sib_width, sib_offset, true); + } + if (compass === 'image') { + self.change_width(event, self.$target, target_width, offset, true); + } + }); + $body.one("mouseup", function () { + $body.off('.mass_mailing_width_x'); + }); + }); + + return def; + }, + change_width: function (event, target, target_width, offset, grow) { + target.css("width", grow ? (event.pageX - offset) : (offset + target_width - event.pageX)); + this.trigger_up('cover_update'); + }, + get_int_width: function (el) { + return parseInt($(el).css("width"), 10); + }, + get_max_width: function ($el) { + return this.containerWidth - _.reduce(_.map($el.siblings(), this.get_int_width), function (memo, w) { return memo + w; }); + }, + onFocus: function () { + this._super.apply(this, arguments); + + if (this.$target.is("td, th")) { + this.$overlay.find(".o_handle.e, .o_handle.w").toggleClass("readonly", this.$target.siblings().length === 0); + } + }, +}); + +options.registry.mass_mailing_table_item = options.Class.extend({ + onClone: function (options) { + this._super.apply(this, arguments); + + // If we cloned a td or th element... + if (options.isCurrent && this.$target.is("td, th")) { + // ... and that the td or th element was alone on its row ... + if (this.$target.siblings().length === 1) { + var $tr = this.$target.parent(); + $tr.clone().empty().insertAfter($tr).append(this.$target); // ... move the clone in a new row instead + return; + } + + // ... if not, if the clone neighbor is an empty cell, remove this empty cell (like if the clone content had been put in that cell) + var $next = this.$target.next(); + if ($next.length && $next.text().trim() === "") { + $next.remove(); + return; + } + + // ... if not, insert an empty col in each other row, at the index of the clone + var width = this.$target.width(); + var $trs = this.$target.closest("table").children("thead, tbody, tfoot").addBack().children("tr").not(this.$target.parent()); + _.each($trs.children(":nth-child(" + this.$target.index() + ")"), function (col) { + $(col).after($("", {style: "width: " + width + "px;"})); + }); + } + }, + onRemove: function () { + this._super.apply(this, arguments); + + // If we are removing a td or th element which was not alone on its row ... + if (this.$target.is("td, th") && this.$target.siblings().length > 0) { + var $trs = this.$target.closest("table").children("thead, tbody, tfoot").addBack().children("tr").not(this.$target.parent()); + if ($trs.length) { // ... if there are other rows in the table ... + var $last_tds = $trs.children(":last-child"); + if (_.reduce($last_tds, function (memo, td) { return memo + (td.innerHTML || ""); }, "").trim() === "") { + $last_tds.remove(); // ... remove the potential full empty column in the table + } else { + this.$target.parent().append(""); // ... else, if there is no full empty column, append an empty col in the current row + } + } + } + }, +}); + +// Adding compatibility for the outlook compliance of mailings. +// Commit of such compatibility : a14f89c8663c9cafecb1cc26918055e023ecbe42 +options.registry.BackgroundImage = options.registry.BackgroundImage.extend({ + start: function () { + this._super(); + if (this.snippets && this.snippets.split('.')[0] === "mass_mailing") { + var $table_target = this.$target.find('table:first'); + if ($table_target.length) { + this.$target = $table_target; + } + } + } +}); + +// TODO remove in master when removing the XML div. The option has been disabled +// in 14.0 because of tricky problems to resolve that require refactoring: +// the ability to clean snippet without saving and reloading the page. +options.registry.SnippetSave.include({ + + async saveSnippet(previewMode, widgetValue, params) {}, + + async _computeVisibility() { + return false; + }, +}); +}); diff --git a/addons/mass_mailing/static/src/js/mass_mailing_widget.js b/addons/mass_mailing/static/src/js/mass_mailing_widget.js new file mode 100644 index 00000000..b39cb917 --- /dev/null +++ b/addons/mass_mailing/static/src/js/mass_mailing_widget.js @@ -0,0 +1,520 @@ +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 $('