[MIG] web_widget_image_download

This commit is contained in:
kutyel
2016-07-22 17:24:47 +02:00
committed by manu
parent eea7a78d42
commit 80c0cde4b0
8 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
/* Copyright 2016 Flavio Corpa <flavio.corpa@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;
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
*/
odoo.define('web_widget_image_download', function (require) {
'use strict';
var common = require('web.form_common');
common.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');
$.ajax({
type: 'HEAD',
url: this.imgSrc,
complete: function (xhr) {
// retrieve image type from server ("Content-Type" header)
$widget.attr('download', xhr.getResponseHeader("Content-Type").replace('/', '.'));
}
});
// use jquery instead of `replace` with qweb (to avoid breaking inheritance)
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 () {
// check if the image of the widget is different from the default placeholder
return this.imgSrc && !this.imgSrc.includes('/placeholder.png');
}
});
});

View File

@@ -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>