diff options
| author | jpr-odoo <jpr@openerp.com> | 2017-09-04 18:18:12 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2017-09-05 15:52:15 +0200 |
| commit | 46699c5214229ea8aebcc04e08d0786fd2b67f35 (patch) | |
| tree | 60f74e793b442ba8d2379f68743fb5a4724472e0 /addons/mail/static/src/js/thread.js | |
| parent | fa432175e991be13035757e5174625f954bae171 (diff) | |
[IMP] mail: Add a preview popup for attachments
Purpose
=======
The goal is that when you click on an attachment, you should get a preview of it and then you get the possibility to download it.
Diffstat (limited to 'addons/mail/static/src/js/thread.js')
| -rw-r--r-- | addons/mail/static/src/js/thread.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/thread.js b/addons/mail/static/src/js/thread.js index 038bbf93de9..80d4c4c8a4c 100644 --- a/addons/mail/static/src/js/thread.js +++ b/addons/mail/static/src/js/thread.js @@ -2,6 +2,7 @@ odoo.define('mail.ChatThread', function (require) { "use strict"; var core = require('web.core'); +var DocumentViewer = require('mail.DocumentViewer'); var Widget = require('web.Widget'); var QWeb = core.qweb; @@ -30,6 +31,8 @@ var Thread = Widget.extend({ "click img": "on_click_redirect", "click strong": "on_click_redirect", "click .o_thread_show_more": "on_click_show_more", + "click .o_attachment_download": "_onAttachmentDownload", + "click .o_attachment_view": "_onAttachmentView", "click .o_thread_message_needaction": function (event) { var message_id = $(event.currentTarget).data('message-id'); this.trigger("mark_as_read", message_id); @@ -110,6 +113,8 @@ var Thread = Widget.extend({ ORDER: ORDER, })); + this.attachments = _.uniq(_.flatten(_.map(messages, 'attachment_ids'))); + _.each(msgs, function(msg) { var $msg = self.$('.o_thread_message[data-message-id="'+ msg.id +'"]'); $msg.find('.o_mail_timestamp').data('date', msg.date); @@ -300,6 +305,29 @@ var Thread = Widget.extend({ destroy: function () { clearInterval(this.update_timestamps_interval); }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {MouseEvent} event + */ + _onAttachmentDownload: function (event) { + event.stopPropagation(); + }, + /** + * @private + * @param {MouseEvent} event + */ + _onAttachmentView: function (event) { + var activeAttachmentID = $(event.currentTarget).data('id'); + if (activeAttachmentID) { + var attachmentViewer = new DocumentViewer(this, this.attachments, activeAttachmentID); + attachmentViewer.appendTo($('body')); + } + }, }); Thread.ORDER = ORDER; |
