summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/basic_fields.js
diff options
context:
space:
mode:
authorOdoo's Mergebot <robodoo@odoo.com>2020-09-03 12:52:32 +0200
committerGitHub <noreply@github.com>2020-09-03 12:52:32 +0200
commit0bee745c36c3cf8c411ffb65fab66ebd005ae274 (patch)
tree37ffe9250e3d1ab98589c3b26c74c573820d552d /addons/web/static/src/js/fields/basic_fields.js
parent13367ebd673c6941c8e06d99f2b66ca535ab4b3b (diff)
parent3670c413c3aaa9aec01b4d1fc4019f238ab213fc (diff)
[MERGE] base, various: avoid storing country flags and strengthen update of countries
Currently, 200+ country flags are stored in ALL db's as ir_attachment's (thus in the filestore), and also duplicated at each backup, ... To reduce the footprint of Odoo databases (and their backups), the country flags are now considered as static images and accessed as such, without storing their references in database. ##### New widget for static image URL's A new `image_url` widget is added (frontend & backend), to allow specification of a static URL in Char fields, enabling the access and display of `res.country` flags through their static urls : `/base/static/img/country_flags/<country_code>.png`. ##### Restriction of countries creation & deletion To ensure no inconsistency can be introduced because the flags are now static, we now restrict the creation and deletion of countries. Countries are nearly static data, they shouldn't ever be deleted... This prevents common database inconsistencies, bugs and feature disabling. Manually created countries can easily be wrongly configured, won't behave as expected and/or will crash with Odoo integration (delivery carriers, taxes, VAT validation/formatting). Therefore, creation/deletion of countries is limited to admins, supposed to know what they are doing... LINKS Task ID-2325371 Backport of #52774 (upgrade: https://github.com/odoo/upgrade/pull/1338) COM PR: #56997 (upgrade will be backported in https://github.com/odoo/upgrade/pull/1735) -- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 3e49fdbf250..8ebde6cbda9 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -1955,6 +1955,45 @@ var FieldBinaryImage = AbstractFieldBinary.extend({
},
});
+var CharImageUrl = AbstractField.extend({
+ className: 'o_field_image',
+ description: _lt("Image"),
+ supportedFieldTypes: ['char'],
+ placeholder: "/web/static/src/img/placeholder.png",
+
+ _renderReadonly: function () {
+ var self = this;
+ const url = this.value;
+ if (url) {
+ var $img = $(qweb.render("FieldBinaryImage-img", {widget: this, url: url}));
+ // override css size attributes (could have been defined in css files)
+ // if specified on the widget
+ const width = this.nodeOptions.size ? this.nodeOptions.size[0] : this.attrs.width;
+ const height = this.nodeOptions.size ? this.nodeOptions.size[1] : this.attrs.height;
+ if (width) {
+ $img.attr('width', width);
+ $img.css('max-width', width + 'px');
+ }
+ if (height) {
+ $img.attr('height', height);
+ $img.css('max-height', height + 'px');
+ }
+ this.$('> img').remove();
+ this.$el.prepend($img);
+
+ $img.one('error', function () {
+ $img.attr('src', self.placeholder);
+ self.displayNotification({
+ type: 'info',
+ message: _t("Could not display the specified image url."),
+ });
+ });
+ }
+
+ return this._super.apply(this, arguments);
+ },
+});
+
var KanbanFieldBinaryImage = FieldBinaryImage.extend({
// In kanban views, there is a weird logic to determine whether or not a
// click on a card should open the record in a form view. This logic checks
@@ -1966,6 +2005,17 @@ var KanbanFieldBinaryImage = FieldBinaryImage.extend({
events: {},
});
+var KanbanCharImageUrl = CharImageUrl.extend({
+ // In kanban views, there is a weird logic to determine whether or not a
+ // click on a card should open the record in a form view. This logic checks
+ // if the clicked element has click handlers bound on it, and if so, does
+ // not open the record (assuming that the click will be handled by someone
+ // else). In the case of this widget, there are clicks handler but they
+ // only apply in edit mode, which is never the case in kanban views, so we
+ // simply remove them.
+ events: {},
+});
+
var FieldBinaryFile = AbstractFieldBinary.extend({
description: _lt("File"),
template: 'FieldBinaryFile',
@@ -3539,6 +3589,8 @@ return {
AbstractFieldBinary: AbstractFieldBinary,
FieldBinaryImage: FieldBinaryImage,
KanbanFieldBinaryImage: KanbanFieldBinaryImage,
+ CharImageUrl: CharImageUrl,
+ KanbanCharImageUrl: KanbanCharImageUrl,
FieldBoolean: FieldBoolean,
BooleanToggle: BooleanToggle,
FieldChar: FieldChar,