mirror of https://github.com/OCA/web.git
Merge pull request #392 from Tecnativa/9.0-web_widget_image_download-mig
[9.0][MIG] web_widget_image_downloadpull/411/head
commit
8c3d66f39c
|
@ -0,0 +1,60 @@
|
||||||
|
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||||
|
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||||
|
:alt: License: LGPL-3
|
||||||
|
|
||||||
|
===========================
|
||||||
|
Web Widget - Image Download
|
||||||
|
===========================
|
||||||
|
|
||||||
|
This module was written to extend the functionality of the image widget and allows to download it.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
To use this module, you need to:
|
||||||
|
|
||||||
|
#. Go to the section `Contacts`.
|
||||||
|
#. Click on a contact.
|
||||||
|
#. Edit the contact.
|
||||||
|
#. Click the `Download` button (between `Edit` and `Clear`).
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/162/8.0
|
||||||
|
|
||||||
|
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>`_.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues
|
||||||
|
<https://github.com/OCA/web/issues>`_. In case of trouble, please
|
||||||
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
|
help us smashing it by providing a detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Flavio Corpa <flavio.corpa@tecnativa.com>
|
||||||
|
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
|
mission is to support the collaborative development of Odoo features and
|
||||||
|
promote its widespread use.
|
||||||
|
|
||||||
|
To contribute to this module, please visit https://odoo-community.org.
|
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
||||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
||||||
|
{
|
||||||
|
"name": "Web Widget - Image Download",
|
||||||
|
"summary": "Allows to download any image from its widget",
|
||||||
|
"version": "9.0.1.0.0",
|
||||||
|
"category": "web",
|
||||||
|
"website": "https://www.tecnativa.com",
|
||||||
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
|
"license": "LGPL-3",
|
||||||
|
"application": False,
|
||||||
|
"installable": True,
|
||||||
|
"data": [
|
||||||
|
"views/assets.xml",
|
||||||
|
],
|
||||||
|
"depends": [
|
||||||
|
"web",
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
"static/src/xml/web_widget_image_download.xml",
|
||||||
|
]
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +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_form .oe_form_field_image .oe_form_field_image_controls
|
||||||
|
.oe_form_binary_file_download {
|
||||||
|
color: inherit;
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* 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 core = require('web.core');
|
||||||
|
var $ = require('$');
|
||||||
|
|
||||||
|
core.form_widget_registry.get("image").include({
|
||||||
|
render_value: function () {
|
||||||
|
this._super();
|
||||||
|
var $widget = this.$el.find('.oe_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('/', '.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
$widget.attr('href', this.imgSrc);
|
||||||
|
},
|
||||||
|
|
||||||
|
has_custom_image: function () {
|
||||||
|
return this.imgSrc != this.placeholder;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
||||||
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<t t-extend="FieldBinaryImage">
|
||||||
|
<t t-jquery=".oe_form_binary_file_edit" t-operation="after">
|
||||||
|
<t t-if="widget.has_custom_image()">
|
||||||
|
<a class="fa fa-download fa-1g col-md-4 oe_form_binary_file_download" title="Download"></a>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</template>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
|
||||||
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<template id="assets_backend" inherit_id="web.assets_backend">
|
||||||
|
<xpath expr=".">
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="/web_widget_image_download/static/src/css/web_widget_image_download.css"/>
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="/web_widget_image_download/static/src/js/web_widget_image_download.js"/>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</odoo>
|
Loading…
Reference in New Issue