diff --git a/mail_preview_base/static/src/js/preview.js b/mail_preview_base/static/src/js/preview.js index c488fde..873408e 100644 --- a/mail_preview_base/static/src/js/preview.js +++ b/mail_preview_base/static/src/js/preview.js @@ -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( $("").addClass("fa fa-search preview_file") ); @@ -143,5 +157,4 @@ odoo.define("mail_preview_base.preview", function (require) { FieldPreviewBinary: FieldPreviewBinary, DocumentViewer: DocumentViewer, }; - }); diff --git a/mail_preview_base/static/src/xml/preview.xml b/mail_preview_base/static/src/xml/preview.xml index c5ce02f..9600a84 100644 --- a/mail_preview_base/static/src/xml/preview.xml +++ b/mail_preview_base/static/src/xml/preview.xml @@ -1,17 +1,25 @@ - + - #{widget.activeAttachment.source_url}?unique=1&signature=#{widget.activeAttachment.checksum} + #{widget.activeAttachment.source_url}?unique=1&signature=#{widget.activeAttachment.checksum} - /web/static/lib/pdfjs/web/viewer.html?file=#{widget.activeAttachment.source_url} + /web/static/lib/pdfjs/web/viewer.html?file=#{widget.activeAttachment.source_url} - #{widget.activeAttachment.source_url} + #{widget.activeAttachment.source_url} - #{widget.activeAttachment.source_url} + #{widget.activeAttachment.source_url} @@ -22,7 +30,7 @@ defined on the preview. TODO: Set the has_preview on a function... --> - + diff --git a/mail_preview_base/template/assets.xml b/mail_preview_base/template/assets.xml index a12c52a..afe0cf3 100644 --- a/mail_preview_base/template/assets.xml +++ b/mail_preview_base/template/assets.xml @@ -6,12 +6,22 @@ --> -