-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG]web_widget_image_download: Migration to 16.0
- Loading branch information
1 parent
9e0a86f
commit 9d55e4a
Showing
7 changed files
with
48 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 15 additions & 24 deletions
39
web_widget_image_download/static/src/js/web_widget_image_download.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,21 @@ | ||
/** @odoo-module **/ | ||
|
||
/* Copyright 2016 Flavio Corpa <[email protected]> | ||
* Copyright 2016 Jairo Llopis <[email protected]> | ||
* Copyright 2024 Manuel Regidor <[email protected]> | ||
* 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("/", ".") | ||
); | ||
}, | ||
}); | ||
import {patch} from "@web/core/utils/patch"; | ||
import {ImageField} from "@web/views/fields/image/image_field"; | ||
|
||
$widget.attr("href", this.imgSrc); | ||
}, | ||
}); | ||
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(); | ||
}, | ||
}); |
38 changes: 0 additions & 38 deletions
38
web_widget_image_download/static/src/scss/web_widget_image_download.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,28 @@ | |
<!-- Copyright 2016 Flavio Corpa <[email protected]> | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). --> | ||
<template> | ||
<t t-extend="FieldBinaryImage"> | ||
<t t-jquery=".o_select_file_button" t-operation="after"> | ||
<t t-if="widget.value"> | ||
<a | ||
class="o_form_binary_file_download float-left" | ||
title="Download" | ||
<t | ||
t-name="web_widget_image_download.ImageField" | ||
t-inherit="web.ImageField" | ||
t-inherit-mode="extension" | ||
owl="1" | ||
> | ||
<xpath expr="//FileUploader/../.." position="after"> | ||
<div | ||
t-attf-class="position-absolute top-0 opacity-0 opacity-100-hover {{isMobile ? 'o_mobile_controls' : ''}}" | ||
aria-atomic="true" | ||
t-att-style="sizeStyle" | ||
> | ||
<button | ||
t-if="props.value and state.isValid" | ||
class="o_form_binary_file_download btn btn-light border-0 rounded-circle m-1 p-1" | ||
data-tooltip="Download" | ||
aria-label="Download" | ||
t-on-click="onFileDownload" | ||
> | ||
<button class="fa fa-download fa-lg" /> | ||
</a> | ||
</t> | ||
</t> | ||
<i class="fa fa-download fa-fw" /> | ||
</button> | ||
</div> | ||
</xpath> | ||
</t> | ||
</template> |