[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).
**********************************************************************************/
odoo.define("mail_preview_base.preview", function (require) {
odoo.define("mail_preview_base.preview", function(require) {
"use strict";
var DocumentViewer = require("mail.DocumentViewer");
@ -12,12 +12,13 @@ odoo.define("mail_preview_base.preview", function (require) {
var AttachmentBox = require("mail.AttachmentBox");
DocumentViewer.include({
init: function (parent, attachments) {
init: function(parent, attachments) {
this._super.apply(this, arguments);
var self = this;
_.forEach(this.attachment, function (attachment) {
if (attachment.mimetype === 'application/pdf' ||
attachment.type === 'text'
_.forEach(this.attachment, function(attachment) {
if (
attachment.mimetype === "application/pdf" ||
attachment.type === "text"
) {
attachment.source_url = self._getContentUrl(attachment);
} else {
@ -25,7 +26,7 @@ odoo.define("mail_preview_base.preview", function (require) {
}
});
this.attachment = this.attachment.concat(
_.filter(attachments, function (attachment) {
_.filter(attachments, function(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
records
*/
_checkAttachment: function () {
_checkAttachment: function() {
return false;
},
_getContentUrl: function (attachment) {
return "/web/content/" + attachment.id +"?filename=" +
window.encodeURIComponent(attachment.name);
_getContentUrl: function(attachment) {
return (
"/web/content/" +
attachment.id +
"?filename=" +
window.encodeURIComponent(attachment.name)
);
},
_getImageUrl: function (attachment) {
_getImageUrl: function(attachment) {
return "/web/image/" + attachment.id;
},
_hasPreview: function (type, attachment) {
return type === 'image' ||
type === 'video' ||
attachment.mimetype === 'application/pdf';
_hasPreview: function(type, attachment) {
return (
type === "image" ||
type === "video" ||
attachment.mimetype === "application/pdf"
);
},
});
AttachmentBox.include({
init: function (parent, record, attachments) {
_.each(attachments, function (attachment) {
init: function(parent, record, attachments) {
_.each(attachments, function(attachment) {
attachment.has_preview = DocumentViewer.prototype._hasPreview(
attachment.mimetype && attachment.mimetype.split('/').shift(),
attachment);
attachment.mimetype && attachment.mimetype.split("/").shift(),
attachment
);
});
this._super.apply(this, arguments);
},
});
var FieldPreviewViewer = DocumentViewer.extend({
init: function (parent, attachments, activeAttachmentID, model, field) {
init: function(parent, attachments, activeAttachmentID, model, field) {
this.modelName = model;
this.fieldName = field;
this._super.apply(this, arguments);
},
_onDownload: function (e) {
_onDownload: function(e) {
e.preventDefault();
window.location =
"/web/content/" +
@ -82,19 +90,27 @@ odoo.define("mail_preview_base.preview", function (require) {
"datas" +
"?download=true";
},
_getContentUrl: function (attachment) {
return "/web/content/" +
this.modelName + '/' +
attachment.id + '/' +
_getContentUrl: function(attachment) {
return (
"/web/content/" +
this.modelName +
"/" +
attachment.id +
"/" +
this.fieldName +
"?filename=" +
window.encodeURIComponent(attachment.name);
window.encodeURIComponent(attachment.name)
);
},
_getImageUrl: function (attachment) {
return "/web/image/" +
this.modelName + '/' +
attachment.id + '/' +
this.fieldName;
_getImageUrl: function(attachment) {
return (
"/web/image/" +
this.modelName +
"/" +
attachment.id +
"/" +
this.fieldName
);
},
});
@ -102,7 +118,7 @@ odoo.define("mail_preview_base.preview", function (require) {
events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, {
"click .preview_file": "_previewFile",
}),
_previewFile: function (event) {
_previewFile: function(event) {
event.stopPropagation();
event.preventDefault();
var attachmentViewer = new FieldPreviewViewer(
@ -114,7 +130,7 @@ odoo.define("mail_preview_base.preview", function (require) {
);
attachmentViewer.appendTo($("body"));
},
_renderReadonly: function () {
_renderReadonly: function() {
this._super.apply(this, arguments);
if (this.value) {
this.attachment = {
@ -125,9 +141,7 @@ odoo.define("mail_preview_base.preview", function (require) {
};
var mimetype = this.recordData.res_mimetype;
var type = mimetype.split("/").shift();
if (
DocumentViewer.prototype._hasPreview(type, this.attachment)
) {
if (DocumentViewer.prototype._hasPreview(type, this.attachment)) {
this.$el.prepend(
$("<span/>").addClass("fa fa-search preview_file")
);
@ -143,5 +157,4 @@ odoo.define("mail_preview_base.preview", function (require) {
FieldPreviewBinary: FieldPreviewBinary,
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">
<t t-extend="DocumentViewer.Content">
<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-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-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-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>
@ -22,7 +30,7 @@
defined on the preview.
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>
</templates>

View File

@ -6,12 +6,22 @@
-->
<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">
<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 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>
</template>
</odoo>