diff --git a/mail_preview_base/README.rst b/mail_preview_base/README.rst new file mode 100644 index 0000000..26985a5 --- /dev/null +++ b/mail_preview_base/README.rst @@ -0,0 +1,91 @@ +============ +Mail Preview +============ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/12.0/mail_preview_base + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_preview_base + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module has two goals: + +* Define a unique system for inheritance that will allow to introduce more + types for the preview. +* Define a new widget that will allow to show the preview. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Creating a new preview file +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You need to add the configuration in three places: + +* Function `_checkAttachment` and `_hasPreview` from `mail.DocumentViewer` on + Javascript +* Qweb template `DocumentViewer.Content` + +As an example, you can check `mail_preview_audio`. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Creu Blanca + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_preview_base/__init__.py b/mail_preview_base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mail_preview_base/__manifest__.py b/mail_preview_base/__manifest__.py new file mode 100644 index 0000000..9276779 --- /dev/null +++ b/mail_preview_base/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + 'name': 'Mail Preview', + 'summary': """ + Base to add more previewing options""", + 'version': '12.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'], + 'qweb': ['static/src/xml/preview.xml'], +} diff --git a/mail_preview_base/i18n/mail_preview_base.pot b/mail_preview_base/i18n/mail_preview_base.pot new file mode 100644 index 0000000..2ffc0b7 --- /dev/null +++ b/mail_preview_base/i18n/mail_preview_base.pot @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_preview_base +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_preview_base +#. openerp-web +#: code:addons/mail_preview_base/static/src/xml/preview.xml:11 +#: code:addons/mail_preview_base/static/src/xml/preview.xml:14 +#, python-format +msgid "#{widget.activeAttachment.source_url}" +msgstr "" + +#. module: mail_preview_base +#. openerp-web +#: code:addons/mail_preview_base/static/src/xml/preview.xml:5 +#, python-format +msgid "#{widget.activeAttachment.source_url}?unique=1&signature=#{widget.activeAttachment.checksum}" +msgstr "" + +#. module: mail_preview_base +#. openerp-web +#: code:addons/mail_preview_base/static/src/xml/preview.xml:8 +#, python-format +msgid "/web/static/lib/pdfjs/web/viewer.html?file=#{widget.activeAttachment.source_url}" +msgstr "" + diff --git a/mail_preview_base/readme/CONTRIBUTORS.rst b/mail_preview_base/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..93ec993 --- /dev/null +++ b/mail_preview_base/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Enric Tobella diff --git a/mail_preview_base/readme/DESCRIPTION.rst b/mail_preview_base/readme/DESCRIPTION.rst new file mode 100644 index 0000000..c353c3f --- /dev/null +++ b/mail_preview_base/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module has two goals: + +* Define a unique system for inheritance that will allow to introduce more + types for the preview. +* Define a new widget that will allow to show the preview. diff --git a/mail_preview_base/readme/USAGE.rst b/mail_preview_base/readme/USAGE.rst new file mode 100644 index 0000000..5b05fa1 --- /dev/null +++ b/mail_preview_base/readme/USAGE.rst @@ -0,0 +1,10 @@ +Creating a new preview file +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You need to add the configuration in three places: + +* Function `_checkAttachment` and `_hasPreview` from `mail.DocumentViewer` on + Javascript +* Qweb template `DocumentViewer.Content` + +As an example, you can check `mail_preview_audio`. diff --git a/mail_preview_base/static/description/icon.png b/mail_preview_base/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/mail_preview_base/static/description/icon.png differ diff --git a/mail_preview_base/static/description/index.html b/mail_preview_base/static/description/index.html new file mode 100644 index 0000000..c903922 --- /dev/null +++ b/mail_preview_base/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Mail Preview + + + +
+

Mail Preview

+ + +

Beta License: LGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

This module has two goals:

+
    +
  • Define a unique system for inheritance that will allow to introduce more +types for the preview.
  • +
  • Define a new widget that will allow to show the preview.
  • +
+

Table of contents

+ +
+

Usage

+
+

Creating a new preview file

+

You need to add the configuration in three places:

+
    +
  • Function _checkAttachment and _hasPreview from mail.DocumentViewer on +Javascript
  • +
  • Qweb template DocumentViewer.Content
  • +
+

As an example, you can check mail_preview_audio.

+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_preview_base/static/src/js/preview.js b/mail_preview_base/static/src/js/preview.js new file mode 100644 index 0000000..fc4514f --- /dev/null +++ b/mail_preview_base/static/src/js/preview.js @@ -0,0 +1,142 @@ +/** ******************************************************************************** + Copyright 2020 Creu Blanca + License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + **********************************************************************************/ + +odoo.define("mail_preview_base.preview", function(require) { + "use strict"; + + 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) { + this._super.apply(this, arguments); + var self = this; + _.forEach(this.attachment, function (attachment) { + if (attachment.mimetype === 'application/pdf' || attachment.type === 'text') { + attachment.source_url = self._getContentUrl(attachment); + } + else { + attachment.source_url = self._getImageUrl(attachment) + } + }) + this.attachment = this.attachment.concat( + _.filter(attachments, function (attachment) { + return self._checkAttachment(attachment) + }) + ); + }, + /* + This function is a hook, it will allow to define new kind of + records + */ + _checkAttachment: function () { + return false; + }, + _getContentUrl: function (attachment) { + return "/web/content/" + attachment.id +"?filename=" + + window.encodeURIComponent(attachment.name); + }, + _getImageUrl: function (attachment) { + return "/web/image/" + attachment.id; + }, + _hasPreview: function (type, attachment) { + return type === 'image' || type === 'video' || attachment.mimetype === 'application/pdf'; + }, + }); + + 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.fieldName = field; + this._super.apply(this, arguments); + }, + _onDownload: function(e) { + e.preventDefault(); + window.location = + "/web/content/" + + this.modelName + + "/" + + this.activeAttachment.id + + "/" + + this.fieldName + + "/" + + "datas" + + "?download=true"; + }, + _getContentUrl: function (attachment) { + return "/web/content/" + + this.modelName + '/' + + attachment.id + '/' + + this.fieldName + +"?filename=" + + window.encodeURIComponent(attachment.name); + }, + _getImageUrl: function (attachment) { + return "/web/image/" + + this.modelName + '/' + + attachment.id + '/' + + this.fieldName + }, + }); + + var FieldPreviewBinary = basic_fields.FieldBinaryFile.extend({ + events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, { + "click .preview_file": "_previewFile", + }), + _previewFile: function(event) { + event.stopPropagation(); + event.preventDefault(); + var attachmentViewer = new FieldPreviewViewer( + this, + [this.attachment], + this.res_id, + this.model, + this.name + ); + attachmentViewer.appendTo($("body")); + }, + _renderReadonly: function() { + this._super.apply(this, arguments); + if (this.value) { + this.attachment = { + mimetype: this.recordData.res_mimetype, + id: this.res_id, + fileType: this.recordData.res_mimetype, + name: this.filename, + }; + var mimetype = this.recordData.res_mimetype; + var type = mimetype.split("/").shift(); + if ( + DocumentViewer.prototype._hasPreview(type, this.attachment) + ) { + this.$el.prepend( + $("").addClass("fa fa-search preview_file") + ); + } + } + }, + }); + + registry.add("preview_binary", FieldPreviewBinary); + + return { + FieldPreviewViewer: FieldPreviewViewer, + FieldPreviewBinary: FieldPreviewBinary, + }; + +}); diff --git a/mail_preview_base/static/src/scss/preview.scss b/mail_preview_base/static/src/scss/preview.scss new file mode 100644 index 0000000..377cd24 --- /dev/null +++ b/mail_preview_base/static/src/scss/preview.scss @@ -0,0 +1,3 @@ +.o_form_view .o_form_uri > span:nth-child(2) { + color: $o-brand-primary; +} diff --git a/mail_preview_base/static/src/xml/preview.xml b/mail_preview_base/static/src/xml/preview.xml new file mode 100644 index 0000000..c5ce02f --- /dev/null +++ b/mail_preview_base/static/src/xml/preview.xml @@ -0,0 +1,28 @@ + + + + + #{widget.activeAttachment.source_url}?unique=1&signature=#{widget.activeAttachment.checksum} + + + /web/static/lib/pdfjs/web/viewer.html?file=#{widget.activeAttachment.source_url} + + + #{widget.activeAttachment.source_url} + + + #{widget.activeAttachment.source_url} + + + + + + + + + + diff --git a/mail_preview_base/template/assets.xml b/mail_preview_base/template/assets.xml new file mode 100644 index 0000000..a12c52a --- /dev/null +++ b/mail_preview_base/template/assets.xml @@ -0,0 +1,17 @@ + + + +