Browse Source

Merge pull request #395 from Tecnativa/8.0-web_widget_image_download-remove_hardcoded_field

[FIX][web_widget_image_download] Make button look good everywhere (I hope).
pull/354/merge
Sylvain LE GAL 8 years ago
committed by GitHub
parent
commit
b1cf8949b4
  1. 2
      web_widget_image_download/README.rst
  2. 2
      web_widget_image_download/__openerp__.py
  3. 6
      web_widget_image_download/static/src/css/web_widget_image_download.css
  4. 34
      web_widget_image_download/static/src/js/web_widget_image_download.js

2
web_widget_image_download/README.rst

@ -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>`_.
* For some unknown reason, the widget does not work in the `Preferences` view, because odoo is not rendering the **QWeb** template.
Bug Tracker
===========
@ -43,6 +42,7 @@ Contributors
------------
* Flavio Corpa <flavio.corpa@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
Maintainer
----------

2
web_widget_image_download/__openerp__.py

@ -4,7 +4,7 @@
{
"name": "Web Widget - Image Download",
"summary": "Allows to download any image from its widget",
"version": "8.0.1.0.0",
"version": "8.0.1.0.1",
"category": "web",
"website": "https://www.tecnativa.com",
"author": "Tecnativa, Odoo Community Association (OCA)",

6
web_widget_image_download/static/src/css/web_widget_image_download.css

@ -1,6 +1,8 @@
/* 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). */
.openerp .oe_application a.oe_form_binary_file_download {
color: #eee;
.openerp .oe_form .oe_form_field_image .oe_form_field_image_controls
.oe_form_binary_file_download {
color: inherit;
}

34
web_widget_image_download/static/src/js/web_widget_image_download.js

@ -1,37 +1,39 @@
/*
* Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
*/
/* 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). */
openerp.web_widget_image_download = function (instance) {
'use strict';
instance.web.form.web_widget_image_download = instance.web.form.FieldBinaryImage.include({
render_value: function () {
this._super();
var $widget = this.$el.find('.oe_form_binary_file_download');
this.imgSrc = this.$el.find('img[name="image"]').attr('src');
this.imgSrc = this.$el.find('img[name="' + this.name + '"]')
.attr('src');
$.ajax({
type: 'HEAD',
type: 'HEAD', // Avoid downloading full image, just headers
url: this.imgSrc,
complete: function (xhr) {
// retrieve image type from server ("Content-Type" header)
$widget.attr('download', xhr.getResponseHeader("Content-Type").replace('/', '.'));
$widget.attr(
'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()) {
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);
},
has_custom_image: function () {
// check if the image of the widget is different from the default placeholder
return this.imgSrc && !this.imgSrc.includes('/placeholder.png');
}
return this.imgSrc != this.placeholder;
},
});
}
};
Loading…
Cancel
Save