forked from Techsystech/web
[MIG] web_widget_image_download: Update for v9.
parent
f89da05f05
commit
2a9e480da5
|
@ -26,7 +26,6 @@ Known Issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
||||||
* In order to work correctly, this widget has to detect image type, the server should include this information in the `Content-Type` header. Right now, odoo is not doing so, but a fix has been `proposed <https://github.com/odoo/odoo/pull/12918>`_.
|
* In order to work correctly, this widget has to detect image type, the server should include this information in the `Content-Type` header. Right now, odoo is not doing so, but a fix has been `proposed <https://github.com/odoo/odoo/pull/12918>`_.
|
||||||
* For some unknown reason, the widget does not work in the `Preferences` view, because odoo is not rendering the **QWeb** template.
|
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
@ -43,6 +42,7 @@ Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* Flavio Corpa <flavio.corpa@tecnativa.com>
|
* Flavio Corpa <flavio.corpa@tecnativa.com>
|
||||||
|
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
----------
|
----------
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
|
||||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
|
|
@ -1,6 +1,8 @@
|
||||||
/* Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
/* 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). */
|
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
||||||
|
|
||||||
.openerp .oe_application a.oe_form_binary_file_download {
|
.openerp .oe_form .oe_form_field_image .oe_form_field_image_controls
|
||||||
color: #eee;
|
.oe_form_binary_file_download {
|
||||||
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,42 @@
|
||||||
/*
|
/* Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
||||||
* 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).
|
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
||||||
*/
|
odoo.define('web_widget_image_download.widget', function (require) {
|
||||||
odoo.define('web_widget_image_download', function (require) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var common = require('web.form_common');
|
var core = require('web.core');
|
||||||
|
var $ = require('$');
|
||||||
|
|
||||||
common.FieldBinaryImage.include({
|
core.form_widget_registry.get("image").include({
|
||||||
render_value: function () {
|
render_value: function () {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
var $widget = this.$el.find('.oe_form_binary_file_download');
|
var $widget = this.$el.find('.oe_form_binary_file_download');
|
||||||
|
this.imgSrc = this.$el.find('img[name="' + this.name + '"]')
|
||||||
this.imgSrc = this.$el.find('img[name="image"]').attr('src');
|
.attr('src');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'HEAD',
|
type: 'HEAD', // Avoid downloading full image, just headers
|
||||||
url: this.imgSrc,
|
url: this.imgSrc,
|
||||||
complete: function (xhr) {
|
complete: function (xhr) {
|
||||||
// retrieve image type from server ("Content-Type" header)
|
$widget.attr(
|
||||||
$widget.attr('download', xhr.getResponseHeader("Content-Type").replace('/', '.'));
|
'download',
|
||||||
|
xhr.getResponseHeader("Content-Type")
|
||||||
|
.replace('/', '.')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// use jquery instead of `replace` with qweb (to avoid breaking inheritance)
|
// Replace with jQuery to keep inheritance intact
|
||||||
if (this.has_custom_image()) {
|
if (this.has_custom_image()) {
|
||||||
this.$el.find('.oe_form_binary_file_clear').removeClass('col-md-offset-5');
|
this.$el.find('.oe_form_binary_file_clear')
|
||||||
|
.removeClass('col-md-offset-5');
|
||||||
}
|
}
|
||||||
|
|
||||||
$widget.attr('href', this.imgSrc);
|
$widget.attr('href', this.imgSrc);
|
||||||
},
|
},
|
||||||
|
|
||||||
has_custom_image: function () {
|
has_custom_image: function () {
|
||||||
// check if the image of the widget is different from the default placeholder
|
return this.imgSrc != this.placeholder;
|
||||||
return this.imgSrc && !this.imgSrc.includes('/placeholder.png');
|
},
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue