-
-
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 90564bb
Showing
6 changed files
with
40 additions
and
86 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
37 changes: 14 additions & 23 deletions
37
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 @@ | ||
/* 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("/", ".") | ||
); | ||
}, | ||
}); | ||
|
||
$widget.attr("href", this.imgSrc); | ||
odoo.define("web_widget_image_download.image_field", function (require) { | ||
"use strict"; | ||
const {patch} = require("@web/core/utils/patch"); | ||
const {ImageField} = require("@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(); | ||
}, | ||
}); | ||
}); |
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,22 @@ | |
<!-- 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" | ||
aria-label="Download" | ||
> | ||
<button class="fa fa-download fa-lg" /> | ||
</a> | ||
</t> | ||
</t> | ||
<t | ||
t-name="web_widget_image_download.ImageField" | ||
t-inherit="web.ImageField" | ||
t-inherit-mode="extension" | ||
owl="1" | ||
> | ||
<xpath expr="//button[hasclass('o_clear_file_button')]" position="before"> | ||
<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" | ||
> | ||
<i class="fa fa-download fa-fw" /> | ||
</button> | ||
</xpath> | ||
</t> | ||
</template> |