From 1d6e4948d2e8534379b6815e931a6eaa58955e18 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 29 Apr 2020 07:21:34 +0000 Subject: [IMP] web: add BadgeField component This new field component displays the field's value inside a bootstrap pill badge. Supported field types are 'char', 'selection' and 'many2one'. The background color of the badge can be customized by using the decoration-xxx mechanism, e.g. Part of task 2195254 --- .../web/static/src/js/fields/basic_fields_owl.js | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'addons/web/static/src/js/fields/basic_fields_owl.js') diff --git a/addons/web/static/src/js/fields/basic_fields_owl.js b/addons/web/static/src/js/fields/basic_fields_owl.js index a00b14fb9ee..8a5915410ee 100644 --- a/addons/web/static/src/js/fields/basic_fields_owl.js +++ b/addons/web/static/src/js/fields/basic_fields_owl.js @@ -7,6 +7,27 @@ odoo.define('web.basic_fields_owl', function (require) { const _lt = core._lt; + + /** + * FieldBadge displays the field's value inside a bootstrap pill badge. + * The supported field's types are 'char', 'selection' and 'many2one'. + * + * By default, the background color of the badge is a light gray, but it can + * be customized by setting a 'decoration-xxx' attribute on the field. + * For instance, + * + * renders a badge with a red background on records matching the condition. + */ + class FieldBadge extends AbstractField { + _getClassFromDecoration(decoration) { + return `bg-${decoration.split('-')[1]}-light`; + } + } + FieldBadge.description = _lt("Badge"); + FieldBadge.supportedFieldTypes = ['selection', 'many2one', 'char']; + FieldBadge.template = 'web.FieldBadge'; + + class FieldBoolean extends AbstractField { patched() { super.patched(); @@ -105,7 +126,9 @@ odoo.define('web.basic_fields_owl', function (require) { FieldBoolean.supportedFieldTypes = ['boolean']; FieldBoolean.template = 'web.FieldBoolean'; + return { + FieldBadge, FieldBoolean, }; }); -- cgit v1.2.3