[MIG] mail_preview_base: Migration to 14.0

Co-authored-by: Enric Tobella <etobella@creublanca.es>
This commit is contained in:
Víctor Martínez 2021-03-30 17:13:35 +02:00 committed by Jasmin Solanki
parent 7329af8c70
commit a5709e6635
5 changed files with 41 additions and 23 deletions

View File

@ -5,11 +5,14 @@
"name": "Mail Preview", "name": "Mail Preview",
"summary": """ "summary": """
Base to add more previewing options""", Base to add more previewing options""",
"version": "13.0.1.0.0", "version": "14.0.1.0.0",
"license": "LGPL-3", "license": "LGPL-3",
"author": "Creu Blanca,Odoo Community Association (OCA)", "author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social", "website": "https://github.com/OCA/social",
"depends": ["mail"], "depends": ["mail"],
"data": ["template/assets.xml"], "data": [
"template/assets.xml",
"views/ir_attachment_view.xml",
],
"qweb": ["static/src/xml/preview.xml"], "qweb": ["static/src/xml/preview.xml"],
} }

View File

@ -1 +1,5 @@
* Enric Tobella <etobella@creublanca.es> * Enric Tobella <etobella@creublanca.es>
* `Tecnativa <https://www.tecnativa.com>`_:
* Víctor Martínez

View File

@ -7,4 +7,10 @@ You need to add the configuration in three places:
Javascript Javascript
* Qweb template `DocumentViewer.Content` * 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`. As an example, you can check `mail_preview_audio`.

View File

@ -9,7 +9,6 @@ odoo.define("mail_preview_base.preview", function (require) {
var DocumentViewer = require("mail.DocumentViewer"); var DocumentViewer = require("mail.DocumentViewer");
var basic_fields = require("web.basic_fields"); var basic_fields = require("web.basic_fields");
var registry = require("web.field_registry"); var registry = require("web.field_registry");
var AttachmentBox = require("mail.AttachmentBox");
DocumentViewer.include({ DocumentViewer.include({
init: function (parent, attachments) { 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({ var FieldPreviewViewer = DocumentViewer.extend({
init: function (parent, attachments, activeAttachmentID, model, field) { init: function (parent, attachments, activeAttachmentID, model, field) {
this.modelName = model; this.fieldModelName = model;
this.fieldName = field; this.fieldName = field;
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.modelName = model;
}, },
_onDownload: function (e) { _onDownload: function (e) {
e.preventDefault(); e.preventDefault();
window.location = window.location =
"/web/content/" + "/web/content/" +
this.modelName + this.fieldModelName +
"/" + "/" +
this.activeAttachment.id + this.activeAttachment.id +
"/" + "/" +
@ -93,7 +81,7 @@ odoo.define("mail_preview_base.preview", function (require) {
_getContentUrl: function (attachment) { _getContentUrl: function (attachment) {
return ( return (
"/web/content/" + "/web/content/" +
this.modelName + this.fieldModelName +
"/" + "/" +
attachment.id + attachment.id +
"/" + "/" +
@ -105,7 +93,7 @@ odoo.define("mail_preview_base.preview", function (require) {
_getImageUrl: function (attachment) { _getImageUrl: function (attachment) {
return ( return (
"/web/image/" + "/web/image/" +
this.modelName + this.fieldModelName +
"/" + "/" +
attachment.id + attachment.id +
"/" + "/" +
@ -118,6 +106,10 @@ odoo.define("mail_preview_base.preview", function (require) {
events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, { events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, {
"click .preview_file": "_previewFile", "click .preview_file": "_previewFile",
}), }),
init: function () {
this._super.apply(this, arguments);
this.mimetype_value = this.recordData.mimetype;
},
_previewFile: function (event) { _previewFile: function (event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -134,12 +126,12 @@ odoo.define("mail_preview_base.preview", function (require) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
if (this.value) { if (this.value) {
this.attachment = { this.attachment = {
mimetype: this.recordData.res_mimetype, mimetype: this.mimetype_value,
id: this.res_id, id: this.res_id,
fileType: this.recordData.res_mimetype, fileType: this.mimetype_value,
name: this.filename, name: this.recordData.name,
}; };
var mimetype = this.recordData.res_mimetype; var mimetype = this.mimetype_value;
var type = mimetype.split("/").shift(); var type = mimetype.split("/").shift();
if (DocumentViewer.prototype._hasPreview(type, this.attachment)) { if (DocumentViewer.prototype._hasPreview(type, this.attachment)) {
this.$el.prepend( this.$el.prepend(

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_attachment_form_mail_preview_base" model="ir.ui.view">
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="base.view_attachment_form" />
<field name="priority">99</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='datas']" position="attributes">
<attribute name="widget">preview_binary</attribute>
</xpath>
</field>
</record>
</odoo>