You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.1 KiB
31 lines
1.1 KiB
/* Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
|
* Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
|
|
* 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({
|
|
type: 'HEAD', // Avoid downloading full image, just headers
|
|
url: this.imgSrc,
|
|
complete: function (xhr) {
|
|
$widget.attr(
|
|
'download',
|
|
xhr.getResponseHeader("Content-Type")
|
|
.replace('/', '.')
|
|
);
|
|
}
|
|
});
|
|
|
|
$widget.attr('href', this.imgSrc);
|
|
}
|
|
});
|
|
});
|