[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",
"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"],
}

View File

@ -1 +1,5 @@
* 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
* 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`.

View File

@ -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(

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>