diff --git a/mail_preview_base/__manifest__.py b/mail_preview_base/__manifest__.py index a583528..9f05bd9 100644 --- a/mail_preview_base/__manifest__.py +++ b/mail_preview_base/__manifest__.py @@ -5,11 +5,14 @@ "name": "Mail Preview", "summary": """ Base to add more previewing options""", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "license": "LGPL-3", "author": "Creu Blanca,Odoo Community Association (OCA)", "website": "https://github.com/OCA/social", "depends": ["mail"], - "data": ["template/assets.xml"], + "data": [ + "template/assets.xml", + "views/ir_attachment_view.xml", + ], "qweb": ["static/src/xml/preview.xml"], } diff --git a/mail_preview_base/readme/CONTRIBUTORS.rst b/mail_preview_base/readme/CONTRIBUTORS.rst index 93ec993..bc379ab 100644 --- a/mail_preview_base/readme/CONTRIBUTORS.rst +++ b/mail_preview_base/readme/CONTRIBUTORS.rst @@ -1 +1,5 @@ * Enric Tobella + +* `Tecnativa `_: + + * Víctor Martínez diff --git a/mail_preview_base/readme/USAGE.rst b/mail_preview_base/readme/USAGE.rst index 5b05fa1..ea4857e 100644 --- a/mail_preview_base/readme/USAGE.rst +++ b/mail_preview_base/readme/USAGE.rst @@ -7,4 +7,10 @@ You need to add the configuration in three places: Javascript * Qweb template `DocumentViewer.Content` +To use this module, you need to: + +#. Go to Settings > Technical > Attachments +#. Create attachment with image or pdf format +#. Show preview icon in "File content" + As an example, you can check `mail_preview_audio`. diff --git a/mail_preview_base/static/src/js/preview.js b/mail_preview_base/static/src/js/preview.js index d67ea82..0ff87d5 100644 --- a/mail_preview_base/static/src/js/preview.js +++ b/mail_preview_base/static/src/js/preview.js @@ -9,7 +9,6 @@ odoo.define("mail_preview_base.preview", function (require) { var DocumentViewer = require("mail.DocumentViewer"); var basic_fields = require("web.basic_fields"); var registry = require("web.field_registry"); - var AttachmentBox = require("mail.AttachmentBox"); DocumentViewer.include({ init: function (parent, attachments) { @@ -59,29 +58,18 @@ odoo.define("mail_preview_base.preview", function (require) { }, }); - AttachmentBox.include({ - init: function (parent, record, attachments) { - _.each(attachments, function (attachment) { - attachment.has_preview = DocumentViewer.prototype._hasPreview( - attachment.mimetype && attachment.mimetype.split("/").shift(), - attachment - ); - }); - this._super.apply(this, arguments); - }, - }); - var FieldPreviewViewer = DocumentViewer.extend({ init: function (parent, attachments, activeAttachmentID, model, field) { - this.modelName = model; + this.fieldModelName = model; this.fieldName = field; this._super.apply(this, arguments); + this.modelName = model; }, _onDownload: function (e) { e.preventDefault(); window.location = "/web/content/" + - this.modelName + + this.fieldModelName + "/" + this.activeAttachment.id + "/" + @@ -93,7 +81,7 @@ odoo.define("mail_preview_base.preview", function (require) { _getContentUrl: function (attachment) { return ( "/web/content/" + - this.modelName + + this.fieldModelName + "/" + attachment.id + "/" + @@ -105,7 +93,7 @@ odoo.define("mail_preview_base.preview", function (require) { _getImageUrl: function (attachment) { return ( "/web/image/" + - this.modelName + + this.fieldModelName + "/" + attachment.id + "/" + @@ -118,6 +106,10 @@ odoo.define("mail_preview_base.preview", function (require) { events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, { "click .preview_file": "_previewFile", }), + init: function () { + this._super.apply(this, arguments); + this.mimetype_value = this.recordData.mimetype; + }, _previewFile: function (event) { event.stopPropagation(); event.preventDefault(); @@ -134,12 +126,12 @@ odoo.define("mail_preview_base.preview", function (require) { this._super.apply(this, arguments); if (this.value) { this.attachment = { - mimetype: this.recordData.res_mimetype, + mimetype: this.mimetype_value, id: this.res_id, - fileType: this.recordData.res_mimetype, - name: this.filename, + fileType: this.mimetype_value, + name: this.recordData.name, }; - var mimetype = this.recordData.res_mimetype; + var mimetype = this.mimetype_value; var type = mimetype.split("/").shift(); if (DocumentViewer.prototype._hasPreview(type, this.attachment)) { this.$el.prepend( diff --git a/mail_preview_base/views/ir_attachment_view.xml b/mail_preview_base/views/ir_attachment_view.xml new file mode 100644 index 0000000..69bb003 --- /dev/null +++ b/mail_preview_base/views/ir_attachment_view.xml @@ -0,0 +1,13 @@ + + + + ir.attachment + + 99 + + + preview_binary + + + +