[IMP] mail_preview_base: black, isort, prettier

This commit is contained in:
Jaime Arroyo 2020-09-28 11:55:04 +02:00 committed by Jasmin Solanki
parent 139c59c31c
commit e6acf6eaac
2 changed files with 33 additions and 29 deletions

View File

@ -2,14 +2,14 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{ {
'name': 'Mail Preview', "name": "Mail Preview",
'summary': """ "summary": """
Base to add more previewing options""", Base to add more previewing options""",
'version': '12.0.1.0.0', "version": "13.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"],
'qweb': ['static/src/xml/preview.xml'], "qweb": ["static/src/xml/preview.xml"],
} }

View File

@ -3,7 +3,7 @@
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
**********************************************************************************/ **********************************************************************************/
odoo.define("mail_preview_base.preview", function(require) { odoo.define("mail_preview_base.preview", function (require) {
"use strict"; "use strict";
var DocumentViewer = require("mail.DocumentViewer"); var DocumentViewer = require("mail.DocumentViewer");
@ -16,19 +16,21 @@ odoo.define("mail_preview_base.preview", function(require) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
var self = this; var self = this;
_.forEach(this.attachment, function (attachment) { _.forEach(this.attachment, function (attachment) {
if (attachment.mimetype === 'application/pdf' || attachment.type === 'text') { if (attachment.mimetype === 'application/pdf' ||
attachment.type === 'text'
) {
attachment.source_url = self._getContentUrl(attachment); attachment.source_url = self._getContentUrl(attachment);
} else {
attachment.source_url = self._getImageUrl(attachment);
} }
else { });
attachment.source_url = self._getImageUrl(attachment)
}
})
this.attachment = this.attachment.concat( this.attachment = this.attachment.concat(
_.filter(attachments, function (attachment) { _.filter(attachments, function (attachment) {
return self._checkAttachment(attachment) return self._checkAttachment(attachment);
}) })
); );
}, },
/* /*
This function is a hook, it will allow to define new kind of This function is a hook, it will allow to define new kind of
records records
@ -44,7 +46,9 @@ odoo.define("mail_preview_base.preview", function(require) {
return "/web/image/" + attachment.id; return "/web/image/" + attachment.id;
}, },
_hasPreview: function (type, attachment) { _hasPreview: function (type, attachment) {
return type === 'image' || type === 'video' || attachment.mimetype === 'application/pdf'; return type === 'image' ||
type === 'video' ||
attachment.mimetype === 'application/pdf';
}, },
}); });
@ -53,19 +57,19 @@ odoo.define("mail_preview_base.preview", function(require) {
_.each(attachments, function (attachment) { _.each(attachments, function (attachment) {
attachment.has_preview = DocumentViewer.prototype._hasPreview( attachment.has_preview = DocumentViewer.prototype._hasPreview(
attachment.mimetype && attachment.mimetype.split('/').shift(), attachment.mimetype && attachment.mimetype.split('/').shift(),
attachment) attachment);
}) });
this._super.apply(this, arguments); 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.modelName = model;
this.fieldName = field; this.fieldName = field;
this._super.apply(this, arguments); this._super.apply(this, arguments);
}, },
_onDownload: function(e) { _onDownload: function (e) {
e.preventDefault(); e.preventDefault();
window.location = window.location =
"/web/content/" + "/web/content/" +
@ -81,16 +85,16 @@ odoo.define("mail_preview_base.preview", function(require) {
_getContentUrl: function (attachment) { _getContentUrl: function (attachment) {
return "/web/content/" + return "/web/content/" +
this.modelName + '/' + this.modelName + '/' +
attachment.id + '/' attachment.id + '/' +
+ this.fieldName this.fieldName +
+"?filename=" + "?filename=" +
window.encodeURIComponent(attachment.name); window.encodeURIComponent(attachment.name);
}, },
_getImageUrl: function (attachment) { _getImageUrl: function (attachment) {
return "/web/image/" + return "/web/image/" +
this.modelName + '/' + this.modelName + '/' +
attachment.id + '/' attachment.id + '/' +
+ this.fieldName this.fieldName;
}, },
}); });
@ -98,7 +102,7 @@ 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",
}), }),
_previewFile: function(event) { _previewFile: function (event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
var attachmentViewer = new FieldPreviewViewer( var attachmentViewer = new FieldPreviewViewer(
@ -110,7 +114,7 @@ odoo.define("mail_preview_base.preview", function(require) {
); );
attachmentViewer.appendTo($("body")); attachmentViewer.appendTo($("body"));
}, },
_renderReadonly: function() { _renderReadonly: function () {
this._super.apply(this, arguments); this._super.apply(this, arguments);
if (this.value) { if (this.value) {
this.attachment = { this.attachment = {