From 0ff51e592eebc28be9aae947e587357a7c28e4f0 Mon Sep 17 00:00:00 2001 From: manu Date: Mon, 29 Jul 2024 11:10:06 +0200 Subject: [PATCH] [MIG]web_widget_image_download: Migration to 16.0 --- web_widget_image_download/README.rst | 12 +++--- web_widget_image_download/__manifest__.py | 9 ++--- web_widget_image_download/readme/USAGE.rst | 2 +- .../static/description/index.html | 9 ++--- .../static/src/components/image_field.esm.js | 21 ++++++++++ .../src/js/web_widget_image_download.js | 30 --------------- .../src/scss/web_widget_image_download.scss | 38 ------------------- .../src/xml/web_widget_image_download.xml | 31 ++++++++++----- 8 files changed, 56 insertions(+), 96 deletions(-) create mode 100644 web_widget_image_download/static/src/components/image_field.esm.js delete mode 100644 web_widget_image_download/static/src/js/web_widget_image_download.js delete mode 100644 web_widget_image_download/static/src/scss/web_widget_image_download.scss diff --git a/web_widget_image_download/README.rst b/web_widget_image_download/README.rst index 34038352d..1edb0737c 100644 --- a/web_widget_image_download/README.rst +++ b/web_widget_image_download/README.rst @@ -17,13 +17,13 @@ Web Widget - Image Download :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/15.0/web_widget_image_download + :target: https://github.com/OCA/web/tree/16.0/web_widget_image_download :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_image_download + :target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_widget_image_download :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=15.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -44,7 +44,7 @@ To use this module, an example path is: #. Go to the section `Contacts`. #. Click on a contact. #. Edit the contact. -#. Click the `Download` button (between `Edit` and `Clear`). +#. Click the `Download` button (on the top left corner). Bug Tracker =========== @@ -52,7 +52,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -93,6 +93,6 @@ 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. +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_widget_image_download/__manifest__.py b/web_widget_image_download/__manifest__.py index 9ed52dbc1..dfecfebb3 100644 --- a/web_widget_image_download/__manifest__.py +++ b/web_widget_image_download/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Web Widget - Image Download", "summary": "Allows to download any image from its widget", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "web", "website": "https://github.com/OCA/web", "author": "Tecnativa, Odoo Community Association (OCA), Kaushal Prajapati", @@ -13,11 +13,8 @@ "depends": ["web"], "assets": { "web.assets_backend": [ - "web_widget_image_download/static/src/js/**/*", - "web_widget_image_download/static/src/scss/**/*", - ], - "web.assets_qweb": [ - "web_widget_image_download/static/src/xml/**/*", + "web_widget_image_download/static/src/components/*", + "web_widget_image_download/static/src/xml/*", ], }, } diff --git a/web_widget_image_download/readme/USAGE.rst b/web_widget_image_download/readme/USAGE.rst index f1685b6a0..e4cccdbd2 100644 --- a/web_widget_image_download/readme/USAGE.rst +++ b/web_widget_image_download/readme/USAGE.rst @@ -3,4 +3,4 @@ To use this module, an example path is: #. Go to the section `Contacts`. #. Click on a contact. #. Edit the contact. -#. Click the `Download` button (between `Edit` and `Clear`). +#. Click the `Download` button (on the top left corner). diff --git a/web_widget_image_download/static/description/index.html b/web_widget_image_download/static/description/index.html index 4bddbe6ec..70ce7300b 100644 --- a/web_widget_image_download/static/description/index.html +++ b/web_widget_image_download/static/description/index.html @@ -1,4 +1,3 @@ - @@ -369,7 +368,7 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:01e27e70406c021c12f0ccba353c64aea71f52d5f06cd7eee48668ad281a029d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module was written to extend the functionality of the image widget and allows to download it.

Table of contents

@@ -392,7 +391,7 @@ allows to download it.

  • Go to the section Contacts.
  • Click on a contact.
  • Edit the contact.
  • -
  • Click the Download button (between Edit and Clear).
  • +
  • Click the Download button (on the top left corner).
  • @@ -400,7 +399,7 @@ allows to download it.

    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.

    +feedback.

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

    @@ -435,7 +434,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

    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.

    +

    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_widget_image_download/static/src/components/image_field.esm.js b/web_widget_image_download/static/src/components/image_field.esm.js new file mode 100644 index 000000000..c1d0816a7 --- /dev/null +++ b/web_widget_image_download/static/src/components/image_field.esm.js @@ -0,0 +1,21 @@ +/** @odoo-module **/ + +/* Copyright 2016 Flavio Corpa + * Copyright 2016 Jairo Llopis + * Copyright 2024 Manuel Regidor + * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ + +import {patch} from "@web/core/utils/patch"; +import {ImageField} from "@web/views/fields/image/image_field"; + +patch(ImageField.prototype, "web_widget_image_download", { + download() { + const downloadLink = document.createElement("a"); + downloadLink.setAttribute("href", this.getUrl(this.props.name)); + downloadLink.setAttribute("download", ""); + downloadLink.click(); + }, + onFileDownload() { + this.download(); + }, +}); diff --git a/web_widget_image_download/static/src/js/web_widget_image_download.js b/web_widget_image_download/static/src/js/web_widget_image_download.js deleted file mode 100644 index d78a3d4ff..000000000 --- a/web_widget_image_download/static/src/js/web_widget_image_download.js +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2016 Flavio Corpa - * Copyright 2016 Jairo Llopis - * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ -odoo.define("web_widget_image_download.widget", function (require) { - "use strict"; - - var FieldBinaryImage = require("web.basic_fields").FieldBinaryImage; - - FieldBinaryImage.include({ - _render: function () { - this._super(); - var $widget = this.$el.find(".o_form_binary_file_download"); - this.imgSrc = this.$el.find('img[name="' + this.name + '"]').attr("src"); - - $.ajax({ - // Avoid downloading full image, just headers - type: "HEAD", - url: this.imgSrc, - complete: function (xhr) { - $widget.attr( - "download", - xhr.getResponseHeader("Content-Type").replace("/", ".") - ); - }, - }); - - $widget.attr("href", this.imgSrc); - }, - }); -}); diff --git a/web_widget_image_download/static/src/scss/web_widget_image_download.scss b/web_widget_image_download/static/src/scss/web_widget_image_download.scss deleted file mode 100644 index 134419bfe..000000000 --- a/web_widget_image_download/static/src/scss/web_widget_image_download.scss +++ /dev/null @@ -1,38 +0,0 @@ -.o_field_widget { - &.o_field_image { - .o_form_image_controls { - > .fa, - .o_form_binary_file_download { - margin: 5px 0; - padding: 1px 0; - width: 33.333333%; - } - .o_form_binary_file_download { - border: none; - background-color: transparent; - line-height: 0px; - - > button.fa { - width: 100%; - height: 100%; - margin: 0px; - border: none; - background-color: transparent; - cursor: pointer; - } - } - } - @include media-breakpoint-down(xs, $o-extra-grid-breakpoints) { - .o_form_image_controls { - .o_form_binary_file_download { - display: none; - } - > .fa { - width: 50%; - padding: 6px; - margin: 0px; - } - } - } - } -} diff --git a/web_widget_image_download/static/src/xml/web_widget_image_download.xml b/web_widget_image_download/static/src/xml/web_widget_image_download.xml index f27db538b..1f030b1b1 100644 --- a/web_widget_image_download/static/src/xml/web_widget_image_download.xml +++ b/web_widget_image_download/static/src/xml/web_widget_image_download.xml @@ -2,17 +2,28 @@