diff --git a/setup/web_preview_attachment_base/odoo/addons/web_preview_attachment_base b/setup/web_preview_attachment_base/odoo/addons/web_preview_attachment_base new file mode 120000 index 000000000000..1b1ffca47697 --- /dev/null +++ b/setup/web_preview_attachment_base/odoo/addons/web_preview_attachment_base @@ -0,0 +1 @@ +../../../../web_preview_attachment_base \ No newline at end of file diff --git a/setup/web_preview_attachment_base/setup.py b/setup/web_preview_attachment_base/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/web_preview_attachment_base/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_preview_attachment_base/README.rst b/web_preview_attachment_base/README.rst new file mode 100644 index 000000000000..0d72408bf8dd --- /dev/null +++ b/web_preview_attachment_base/README.rst @@ -0,0 +1,104 @@ +================================= +Base Of Preview Documents in Odoo +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6f946b8b59eeeccbcddf7265ccedb0cdc858df3fdab842b9f92dc36c584fa513 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/16.0/web_preview_attachment_base + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_preview_attachment_base + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Base code for Preview Documents in Odoo + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Depend to this module to add your own preview types. +- Example of a custom preview type: + +.. code:: javascript + + /** @odoo-module **/ + + import { patch } from "@web/core/utils/patch"; + import { Many2ManyBinaryField } from "@web/views/fields/many2many_binary/many2many_binary_field"; + + patch( + Many2ManyBinaryField.prototype, + "yourModule.AttachmentPreview", + { + isPreviewable(file) { + if (file.mimetype === "special_mimetype") { + return true; + } + return this._super.apply(this, arguments); + }, + } + ); + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Phan Hong Phuc + +Contributors +------------ + +- `Trobz `__ + + - Phan Hong Phuc phucph@trobz.com + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_preview_attachment_base/__init__.py b/web_preview_attachment_base/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/web_preview_attachment_base/__manifest__.py b/web_preview_attachment_base/__manifest__.py new file mode 100644 index 000000000000..b1eb657143d3 --- /dev/null +++ b/web_preview_attachment_base/__manifest__.py @@ -0,0 +1,21 @@ +{ + "name": "Base Of Preview Documents in Odoo", + "version": "16.0.1.0.0", + "summary": "Base of Preview Documents in Odoo", + "category": "Tools", + "website": "https://github.com/OCA/web", + "maintainer": "Phan Hong Phuc", + "author": "Phan Hong Phuc, Odoo Community Association (OCA)", + "license": "LGPL-3", + "depends": ["web", "mail"], + "assets": { + "web.assets_backend": [ + "web_preview_attachment_base/static/src/many2many_binary/attachment_preview.xml", + "web_preview_attachment_base/static/src/many2many_binary/attachment_preview.js", + ], + }, + "installable": True, + "application": False, + "images": ["static/description/icon.png"], + "auto_install": False, +} diff --git a/web_preview_attachment_base/readme/CONTRIBUTORS.md b/web_preview_attachment_base/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..d3b16f651bfd --- /dev/null +++ b/web_preview_attachment_base/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +* [Trobz](https://trobz.com) + + * Phan Hong Phuc diff --git a/web_preview_attachment_base/readme/DESCRIPTION.md b/web_preview_attachment_base/readme/DESCRIPTION.md new file mode 100644 index 000000000000..1cc83a78ccaa --- /dev/null +++ b/web_preview_attachment_base/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Base code for Preview Documents in Odoo \ No newline at end of file diff --git a/web_preview_attachment_base/readme/USAGE.md b/web_preview_attachment_base/readme/USAGE.md new file mode 100644 index 000000000000..802093d1430a --- /dev/null +++ b/web_preview_attachment_base/readme/USAGE.md @@ -0,0 +1,21 @@ +- Depend to this module to add your own preview types. +- Example of a custom preview type: +```javascript + /** @odoo-module **/ + +import { patch } from "@web/core/utils/patch"; +import { Many2ManyBinaryField } from "@web/views/fields/many2many_binary/many2many_binary_field"; + +patch( + Many2ManyBinaryField.prototype, + "yourModule.AttachmentPreview", + { + isPreviewable(file) { + if (file.mimetype === "special_mimetype") { + return true; + } + return this._super.apply(this, arguments); + }, + } +); +``` \ No newline at end of file diff --git a/web_preview_attachment_base/static/description/icon.png b/web_preview_attachment_base/static/description/icon.png new file mode 100644 index 000000000000..cbf5b14d5166 Binary files /dev/null and b/web_preview_attachment_base/static/description/icon.png differ diff --git a/web_preview_attachment_base/static/description/index.html b/web_preview_attachment_base/static/description/index.html new file mode 100644 index 000000000000..69d521769a6e --- /dev/null +++ b/web_preview_attachment_base/static/description/index.html @@ -0,0 +1,453 @@ + + + + + +Base Of Preview Documents in Odoo + + + +
+

Base Of Preview Documents in Odoo

+ + +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Base code for Preview Documents in Odoo

+

Table of contents

+ +
+

Usage

+
    +
  • Depend to this module to add your own preview types.
  • +
  • Example of a custom preview type:
  • +
+
+   /** @odoo-module **/
+
+import { patch } from "@web/core/utils/patch";
+import { Many2ManyBinaryField } from "@web/views/fields/many2many_binary/many2many_binary_field";
+
+patch(
+    Many2ManyBinaryField.prototype,
+    "yourModule.AttachmentPreview",
+    {
+        isPreviewable(file) {
+            if (file.mimetype === "special_mimetype") {
+                return true;
+            }
+            return this._super.apply(this, arguments);
+        },
+    }
+);
+
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Phan Hong Phuc
  • +
+
+
+

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/web project on GitHub.

+

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

+
+
+
+ + diff --git a/web_preview_attachment_base/static/src/many2many_binary/attachment_preview.js b/web_preview_attachment_base/static/src/many2many_binary/attachment_preview.js new file mode 100644 index 000000000000..367feb08a911 --- /dev/null +++ b/web_preview_attachment_base/static/src/many2many_binary/attachment_preview.js @@ -0,0 +1,47 @@ +/** @odoo-module **/ + +import {useService} from "@web/core/utils/hooks"; +import {patch} from "@web/core/utils/patch"; +import {Many2ManyBinaryField} from "@web/views/fields/many2many_binary/many2many_binary_field"; + +Many2ManyBinaryField.extractProps = ({attrs, field}) => { + return { + acceptedFileExtensions: attrs.options.accepted_file_extensions, + className: attrs.class, + uploadText: attrs.options.upload_text || field.string, + }; +}; + +patch(Many2ManyBinaryField.prototype, "web_preview_attachment_base.AttachmentPreview", { + setup() { + this._super.apply(this, arguments); + this.messaging = useService("messaging"); + this.dialog = useService("dialog"); + }, + + isPreviewable(file) { + return false; + }, + + onFilePreview(file) { + if (this.isPreviewable(file)) { + this._onFilePreview(file); + } + }, + + _onFilePreview(file) { + this.messaging.get().then((messaging) => { + const attachmentList = messaging.models["AttachmentList"].insert({ + selectedAttachment: messaging.models["Attachment"].insert({ + id: file.id, + filename: file.name, + name: file.name, + mimetype: file.mimetype, + }), + }); + this.dialog = messaging.models["Dialog"].insert({ + attachmentListOwnerAsAttachmentView: attachmentList, + }); + }); + }, +}); diff --git a/web_preview_attachment_base/static/src/many2many_binary/attachment_preview.xml b/web_preview_attachment_base/static/src/many2many_binary/attachment_preview.xml new file mode 100644 index 000000000000..28a1033f04bc --- /dev/null +++ b/web_preview_attachment_base/static/src/many2many_binary/attachment_preview.xml @@ -0,0 +1,39 @@ + + + + + +
+ +
+ +
+
+ + + + + +
+
+
+ +