diff --git a/mail_forward/README.rst b/mail_forward/README.rst index 83f998b7..fcf96175 100644 --- a/mail_forward/README.rst +++ b/mail_forward/README.rst @@ -1,6 +1,6 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 =============== Message forward @@ -70,11 +70,10 @@ For further information, please visit: Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. In -case of trouble, please check there if your issue has already been reported. If -you spotted it first, help us smashing it by providing a detailed and welcomed -feedback `here -`_. +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. Credits @@ -83,7 +82,8 @@ Credits Contributors ------------ -* Jairo Llopis +* Jairo Llopis +* Emanuel Cino Maintainer ---------- diff --git a/mail_forward/__openerp__.py b/mail_forward/__manifest__.py similarity index 77% rename from mail_forward/__openerp__.py rename to mail_forward/__manifest__.py index 302a8e1f..2d771e8e 100644 --- a/mail_forward/__openerp__.py +++ b/mail_forward/__manifest__.py @@ -5,11 +5,10 @@ { "name": "Message Forward", "summary": "Add option to forward messages", - "version": "8.0.7.0.0", + "version": "10.0.1.0.0", "category": "Social Network", - "website": "https://grupoesoc.es", - "author": "Grupo ESOC Ingeniería de Servicios, " - "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "author": "Tecnativa, Odoo Community Association (OCA)", "license": "AGPL-3", "application": False, "installable": True, diff --git a/mail_forward/models/compose_message.py b/mail_forward/models/compose_message.py index d6511e4d..60352971 100644 --- a/mail_forward/models/compose_message.py +++ b/mail_forward/models/compose_message.py @@ -2,7 +2,7 @@ # © 2014-2015 Grupo ESOC # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models +from odoo import api, fields, models class MailForwardComposeMessage(models.TransientModel): @@ -40,7 +40,6 @@ class MailForwardComposeMessage(models.TransientModel): order="name") return [(m.object, m.name) for m in model_objs] - @api.one @api.onchange("destination_object_id") def change_destination_object(self): """Update some fields for the new message.""" @@ -56,10 +55,13 @@ class MailForwardComposeMessage(models.TransientModel): record_name = "%s %s" % (model_name, record_name) self.record_name = record_name - else: - self.model = self.res_id = self.record_name = False - @api.one + @api.multi + def send_mail_action(self): + # action buttons call with positional arguments only, so we need an + # intermediary function to ensure the context is passed correctly + return self.send_mail() + def send_mail(self): """Send mail and execute the attachment relocation if needed.""" # Let the original wizard do de hard work diff --git a/mail_forward/models/res_request_link.py b/mail_forward/models/res_request_link.py index e5d4dc7a..2219d3da 100644 --- a/mail_forward/models/res_request_link.py +++ b/mail_forward/models/res_request_link.py @@ -2,7 +2,7 @@ # © 2014-2015 Grupo ESOC # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models +from odoo import fields, models class ResRequestLink(models.Model): diff --git a/mail_forward/static/src/css/mail_forward.css b/mail_forward/static/src/css/mail_forward.css deleted file mode 100644 index 6eabe491..00000000 --- a/mail_forward/static/src/css/mail_forward.css +++ /dev/null @@ -1,12 +0,0 @@ -/* © 2014-2015 Grupo ESOC - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - */ - -.openerp .oe_mail .oe_msg .oe_msg_icons .oe_forward:hover a { - color: #1FC0FF; - text-shadow: 0px 1px #184FC5, - 0px -1px #184FC5, - -1px 0px #184FC5, - 1px 0px #184FC5, - 0px 3px 3px rgba(0, 0, 0, 0.1); -} diff --git a/mail_forward/static/src/css/mail_forward.less b/mail_forward/static/src/css/mail_forward.less new file mode 100644 index 00000000..ffebaf36 --- /dev/null +++ b/mail_forward/static/src/css/mail_forward.less @@ -0,0 +1,24 @@ +/* (C) 2018 CompassionCH +/* (C) 2014-2015 Grupo ESOC + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ + +@mail-thread-icon-opacity: 0.6; + +.o_mail_thread { + .o_thread_message { + i.o_forward { + cursor: pointer; + opacity: 0; + } + + &:hover, &.o_thread_selected_message { + i.o_forward { + opacity: @mail-thread-icon-opacity; + &:hover { + opacity: 1; + } + } + } + } +} diff --git a/mail_forward/static/src/js/mail_forward.js b/mail_forward/static/src/js/mail_forward.js index 2629a435..577e6b21 100644 --- a/mail_forward/static/src/js/mail_forward.js +++ b/mail_forward/static/src/js/mail_forward.js @@ -2,76 +2,122 @@ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */ -"use strict"; -openerp.mail_forward = function (instance) { - var _t = instance.web._t; - instance.mail.ThreadMessage.include({ - bind_events: function () { - this._super.apply(this, arguments); - this.$('.oe_forward').on('click', this.on_message_forward); - }, +odoo.define('mail_forward.forward', function (require) { + "use strict"; + var core = require('web.core'); + var ChatThread = require('mail.ChatThread'); + var chat_manager = require('mail.chat_manager'); + var Model = require('web.Model'); + var session = require('web.session'); + var MessageModel = new Model('mail.message', session.user_context); + var _t = core._t; - on_message_forward: function () { + ChatThread.include({ + on_message_forward: function (message_id) { + var self = this; + var read_fields = ['record_name', 'parent_id', 'subject', 'attachment_ids', 'date', + 'email_to', 'email_from', 'email_cc', 'model', 'res_id', 'body']; // Generate email subject as possible from record_name and subject - var subject = [_t("FWD")]; - if (this.record_name && (this.show_record_name || - this.parent_id)) - { - subject.push(this.record_name); - } - if (this.subject) { - subject.push(this.subject); - } else if (subject.length < 2) { - subject.push(_t("(No subject)")); - } + MessageModel.call('read', [message_id, read_fields], {context: session.user_context}).then(function (result) { + var message = result[0]; + var subject = [_t("FWD")]; + if (message.record_name && message.parent_id) { + subject.push(message.record_name); + } + if (message.subject) { + subject.push(message.subject); + } else if (subject.length < 2) { + subject.push(_t("(No subject)")); + } - // Get only ID from the attachments - var attachment_ids = []; - for (var n in this.attachment_ids) { - attachment_ids.push(this.attachment_ids[n].id); - } + // Get only ID from the attachments + var attachment_ids = []; + for (var n in message.attachment_ids) { + attachment_ids.push(message.attachment_ids[n]); + } - // Get necessary fields from the forwarded message - var header = [ - "----------" + _t("Forwarded message") + "----------", - _t("From: ") + this.author_id[1], - _t("Date: ") + this.date, - ]; - if (this.subject) { - header.push(_t("Subject: ") + this.subject); - } - if (this.email_to) { - header.push(_t("To: ") + this.email_to); - } - if (this.email_cc) { - header.push(_t("CC: ") + this.email_cc); - } - header = header.map(_.str.escapeHTML).join("
") + // Get necessary fields from the forwarded message + var header = [ + "----------" + _t("Forwarded message") + "----------", + _t("From: ") + message.email_from, + _t("Date: ") + message.date + ]; + if (message.subject) { + header.push(_t("Subject: ") + message.subject); + } + if (message.email_to) { + header.push(_t("To: ") + message.email_to); + } + if (message.email_cc) { + header.push(_t("CC: ") + message.email_cc); + } + header = header.map(_.str.escapeHTML).join("
"); - var context = { - default_attachment_ids: attachment_ids, - default_body: + var context = { + default_attachment_ids: attachment_ids, + default_body: "

" + header + "


" + - this.body, - default_model: this.model, - default_res_id: this.res_id, - default_subject: subject.join(": "), - }; + message.body, + default_model: message.model, + default_res_id: message.res_id, + default_subject: subject.join(": ") + }; - if (this.model && this.res_id) { - context.default_destination_object_id = - [this.model, this.res_id].join(); - } + if (message.model && message.res_id) { + context.default_destination_object_id = + [message.model, message.res_id].join(); + } - // Get the action data and execute it to open the composer wizard - var do_action = this.do_action; - this.rpc("/web/action/load", { - "action_id": "mail_forward.compose_action", - }) - .done(function(action) { - action.context = context; - do_action(action); + // Get the action data and execute it to open the composer wizard + var do_action = self.do_action; + self.rpc("/web/action/load", { + "action_id": "mail_forward.compose_action" + }) + .done(function (action) { + action.context = context; + do_action(action, { + on_close: $.proxy(self.thread_reload, self) + }); + }); + }); + }, + init: function (parent, options) { + this._super.apply(this, arguments); + // Add click reaction in the events of the thread object + this.events['click .o_forward'] = function (event) { + var message_id = $(event.currentTarget).data('message-id'); + this.trigger("message_forward", message_id); + }; + }, + thread_reload: function(){ + var parent = this.getParent(); + var domain = [['model', '=', parent.model], ['res_id', '=', parent.res_id]]; + var self = this; + MessageModel.call('message_fetch', [domain], {limit: 30}).then(function (msgs) { + var messages = _.map(msgs, chat_manager.make_message); + // Avoid displaying in reverse order + self.options.display_order = 1; + self.render(messages, self.options) }); } }); -}; + + var chatter = require('mail.Chatter'); + chatter.include({ + start: function () { + var result = this._super.apply(this, arguments); + this.thread.on('message_forward', this, this.thread.on_message_forward); + return result; + } + }); + + var ChatAction = core.action_registry.get('mail.chat.instant_messaging'); + ChatAction.include({ + start: function () { + var result = this._super.apply(this, arguments); + // For show wizard in the channels + this.thread.on('message_forward', this, this.thread.on_message_forward); + return result; + } + }); +}); diff --git a/mail_forward/static/src/xml/mail_forward.xml b/mail_forward/static/src/xml/mail_forward.xml index a3c97daa..208abf9b 100644 --- a/mail_forward/static/src/xml/mail_forward.xml +++ b/mail_forward/static/src/xml/mail_forward.xml @@ -4,11 +4,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> diff --git a/mail_forward/tests/test_compose_message.py b/mail_forward/tests/test_compose_message.py index d331cf91..b069cb90 100644 --- a/mail_forward/tests/test_compose_message.py +++ b/mail_forward/tests/test_compose_message.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from os import path -from openerp.tests.common import TransactionCase +from odoo.tests.common import TransactionCase class ForwardMailCase(TransactionCase): @@ -43,14 +43,6 @@ class ForwardMailCase(TransactionCase): self.assertEqual(self.fwd.record_name, "%s %s" % (model.name, self.partner.name)) - # Remove the destination object - self.fwd.destination_object_id = False - self.fwd.change_destination_object() - - self.assertFalse(self.fwd.model) - self.assertFalse(self.fwd.res_id) - self.assertFalse(self.fwd.record_name) - def test_move_attachments(self): """Attachments moved correctly.""" self.fwd.attachment_ids |= self.attachment diff --git a/mail_forward/views/assets.xml b/mail_forward/views/assets.xml index 7c04b70d..9155f3f6 100644 --- a/mail_forward/views/assets.xml +++ b/mail_forward/views/assets.xml @@ -3,19 +3,15 @@ - - + -