[IMP] pre-commit run -a

This commit is contained in:
Jairo Llopis 2021-01-26 14:06:17 +00:00 committed by Jasmin Solanki
parent 975e0b8cdb
commit 6bfa014aec
3 changed files with 77 additions and 46 deletions

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");
@ -12,12 +12,13 @@ odoo.define("mail_preview_base.preview", function (require) {
var AttachmentBox = require("mail.AttachmentBox"); var AttachmentBox = require("mail.AttachmentBox");
DocumentViewer.include({ DocumentViewer.include({
init: function (parent, attachments) { init: function(parent, attachments) {
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' || if (
attachment.type === 'text' attachment.mimetype === "application/pdf" ||
attachment.type === "text"
) { ) {
attachment.source_url = self._getContentUrl(attachment); attachment.source_url = self._getContentUrl(attachment);
} else { } else {
@ -25,7 +26,7 @@ odoo.define("mail_preview_base.preview", function (require) {
} }
}); });
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);
}) })
); );
@ -35,41 +36,48 @@ odoo.define("mail_preview_base.preview", function (require) {
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
*/ */
_checkAttachment: function () { _checkAttachment: function() {
return false; return false;
}, },
_getContentUrl: function (attachment) { _getContentUrl: function(attachment) {
return "/web/content/" + attachment.id +"?filename=" + return (
window.encodeURIComponent(attachment.name); "/web/content/" +
attachment.id +
"?filename=" +
window.encodeURIComponent(attachment.name)
);
}, },
_getImageUrl: function (attachment) { _getImageUrl: function(attachment) {
return "/web/image/" + attachment.id; return "/web/image/" + attachment.id;
}, },
_hasPreview: function (type, attachment) { _hasPreview: function(type, attachment) {
return type === 'image' || return (
type === 'video' || type === "image" ||
attachment.mimetype === 'application/pdf'; type === "video" ||
attachment.mimetype === "application/pdf"
);
}, },
}); });
AttachmentBox.include({ AttachmentBox.include({
init: function (parent, record, attachments) { init: function(parent, record, attachments) {
_.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/" +
@ -82,19 +90,27 @@ odoo.define("mail_preview_base.preview", function (require) {
"datas" + "datas" +
"?download=true"; "?download=true";
}, },
_getContentUrl: function (attachment) { _getContentUrl: function(attachment) {
return "/web/content/" + return (
this.modelName + '/' + "/web/content/" +
attachment.id + '/' + this.modelName +
"/" +
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 (
this.modelName + '/' + "/web/image/" +
attachment.id + '/' + this.modelName +
this.fieldName; "/" +
attachment.id +
"/" +
this.fieldName
);
}, },
}); });
@ -102,7 +118,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(
@ -114,7 +130,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 = {
@ -125,9 +141,7 @@ odoo.define("mail_preview_base.preview", function (require) {
}; };
var mimetype = this.recordData.res_mimetype; var mimetype = this.recordData.res_mimetype;
var type = mimetype.split("/").shift(); var type = mimetype.split("/").shift();
if ( if (DocumentViewer.prototype._hasPreview(type, this.attachment)) {
DocumentViewer.prototype._hasPreview(type, this.attachment)
) {
this.$el.prepend( this.$el.prepend(
$("<span/>").addClass("fa fa-search preview_file") $("<span/>").addClass("fa fa-search preview_file")
); );
@ -143,5 +157,4 @@ odoo.define("mail_preview_base.preview", function (require) {
FieldPreviewBinary: FieldPreviewBinary, FieldPreviewBinary: FieldPreviewBinary,
DocumentViewer: DocumentViewer, DocumentViewer: DocumentViewer,
}; };
}); });

View File

@ -1,17 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve"> <templates xml:space="preserve">
<t t-extend="DocumentViewer.Content"> <t t-extend="DocumentViewer.Content">
<t t-jquery=".o_viewer_img" t-operation="attributes"> <t t-jquery=".o_viewer_img" t-operation="attributes">
<attribute name="t-attf-src">#{widget.activeAttachment.source_url}?unique=1&amp;signature=#{widget.activeAttachment.checksum}</attribute> <attribute
name="t-attf-src"
>#{widget.activeAttachment.source_url}?unique=1&amp;signature=#{widget.activeAttachment.checksum}</attribute>
</t> </t>
<t t-jquery=".o_viewer_pdf" t-operation="attributes"> <t t-jquery=".o_viewer_pdf" t-operation="attributes">
<attribute name="t-attf-src">/web/static/lib/pdfjs/web/viewer.html?file=#{widget.activeAttachment.source_url}</attribute> <attribute
name="t-attf-src"
>/web/static/lib/pdfjs/web/viewer.html?file=#{widget.activeAttachment.source_url}</attribute>
</t> </t>
<t t-jquery=".o_viewer_video > source" t-operation="attributes"> <t t-jquery=".o_viewer_video > source" t-operation="attributes">
<attribute name="t-attf-src">#{widget.activeAttachment.source_url}</attribute> <attribute
name="t-attf-src"
>#{widget.activeAttachment.source_url}</attribute>
</t> </t>
<t t-jquery=".o_viewer_text:first" t-operation="attributes"> <t t-jquery=".o_viewer_text:first" t-operation="attributes">
<attribute name="t-attf-src">#{widget.activeAttachment.source_url}</attribute> <attribute
name="t-attf-src"
>#{widget.activeAttachment.source_url}</attribute>
</t> </t>
</t> </t>
@ -22,7 +30,7 @@
defined on the preview. defined on the preview.
TODO: Set the has_preview on a function... TODO: Set the has_preview on a function...
--> -->
<t t-set="has_preview" t-value="has_preview || attachment.has_preview"/> <t t-set="has_preview" t-value="has_preview || attachment.has_preview" />
</t> </t>
</t> </t>
</templates> </templates>

View File

@ -6,12 +6,22 @@
--> -->
<odoo> <odoo>
<template id="assets_backend" name="mail_preview_base_assets" inherit_id="web.assets_backend"> <template
id="assets_backend"
name="mail_preview_base_assets"
inherit_id="web.assets_backend"
>
<xpath expr="//script[last()]" position="after"> <xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/mail_preview_base/static/src/js/preview.js" /> <script
type="text/javascript"
src="/mail_preview_base/static/src/js/preview.js"
/>
</xpath> </xpath>
<xpath expr="//link[last()]" position="after"> <xpath expr="//link[last()]" position="after">
<link rel="stylesheet" href="/mail_preview_base/static/src/scss/preview.scss" /> <link
rel="stylesheet"
href="/mail_preview_base/static/src/scss/preview.scss"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>