mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
ADD: Adding module web_widget_image_url
This commit is contained in:
36
web_widget_image_url/static/src/js/web_widget_image_url.js
Normal file
36
web_widget_image_url/static/src/js/web_widget_image_url.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2017 - 2018 Modoolar <info@modoolar.com>
|
||||
// License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html).
|
||||
|
||||
odoo.define('web_widget_image_url.FieldImageURL', function (require) {
|
||||
"use strict";
|
||||
|
||||
var AbstractField = require('web.AbstractField');
|
||||
var core = require('web.core');
|
||||
var registry = require('web.field_registry');
|
||||
var QWeb = core.qweb;
|
||||
var _t = core._t;
|
||||
|
||||
var UrlImage = AbstractField.extend({
|
||||
className: 'o_attachment_image',
|
||||
template: 'FieldImageURL',
|
||||
placeholder: "/web/static/src/img/placeholder.png",
|
||||
supportedFieldTypes: ['char'],
|
||||
|
||||
url(){
|
||||
return this.value ? this.value : this.placeholder;
|
||||
},
|
||||
|
||||
_render() {
|
||||
this._super(arguments);
|
||||
|
||||
var self = this;
|
||||
var $img = this.$("img:first");
|
||||
$img.on('error', function() {
|
||||
$img.attr('src', self.placeholder);
|
||||
self.do_warn(_t("Image"), _t("Could not display the selected image."));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
registry.add('image_url', UrlImage);
|
||||
});
|
||||
17
web_widget_image_url/static/src/xml/web_widget_image_url.xml
Normal file
17
web_widget_image_url/static/src/xml/web_widget_image_url.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
# Copyright 2017 - 2018 Modoolar <info@modoolar.com>
|
||||
# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html).
|
||||
-->
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="FieldImageURL">
|
||||
<span class="oe_form_field oe_form_field_image" t-att-style="widget.attrs.style">
|
||||
<img t-att-src="widget.url()"
|
||||
t-att-border="widget.readonly ? 0 : 1"
|
||||
t-att-name="widget.name"
|
||||
t-att-width="widget.attrs.img_width || widget.attrs.width"
|
||||
t-att-height="widget.attrs.img_height || widget.attrs.height"
|
||||
/>
|
||||
</span>
|
||||
</t>
|
||||
</templates>
|
||||
Reference in New Issue
Block a user