summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-04-29 07:21:46 +0000
committerAaron Bohy <aab@odoo.com>2020-05-05 10:05:12 +0000
commita0c7284b6667e2a9f57eed2b19c19fc07174b39d (patch)
treec83a5af5425bb9117f9d7148f3c7a597000c765f
parentc54007f0e349989f680338111d315bf55c4eab27 (diff)
[IMP] web: add 'label' attribute on AbstractField
If set, this value will be displayed as column name in list views. This attribute could be used in the future in form view for the same purpose. Part of task 2195254
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js5
-rw-r--r--addons/web/static/src/js/fields/abstract_field_owl.js5
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js5
-rw-r--r--addons/web/static/tests/views/list_tests.js32
4 files changed, 46 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 4767f54d998..ab6f226a66e 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -82,6 +82,11 @@ var AbstractField = Widget.extend({
*/
noLabel: false,
/**
+ * Currently only used in list view.
+ * If set, this value will be displayed as column name.
+ */
+ label: '',
+ /**
* Abstract field class
*
* @constructor
diff --git a/addons/web/static/src/js/fields/abstract_field_owl.js b/addons/web/static/src/js/fields/abstract_field_owl.js
index fe908e6ce72..f97faae35ed 100644
--- a/addons/web/static/src/js/fields/abstract_field_owl.js
+++ b/addons/web/static/src/js/fields/abstract_field_owl.js
@@ -627,6 +627,11 @@ odoo.define('web.AbstractFieldOwl', function (require) {
* If this flag is set to true, the list column name will be empty.
*/
AbstractField.noLabel = false;
+ /**
+ * Currently only used in list view.
+ * If set, this value will be displayed as column name.
+ */
+ AbstractField.label = "";
return AbstractField;
});
diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js
index 93576be9348..98febd8efa8 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -812,8 +812,11 @@ var ListRenderer = BasicRenderer.extend({
var description = string || field.string;
if (node.attrs.widget) {
$th.addClass(' o_' + node.attrs.widget + '_cell');
- if (this.state.fieldsInfo.list[name].Widget.prototype.noLabel) {
+ const FieldWidget = this.state.fieldsInfo.list[name].Widget;
+ if (FieldWidget.prototype.noLabel) {
description = '';
+ } else if (FieldWidget.prototype.label) {
+ description = FieldWidget.prototype.label;
}
}
$th.text(description)
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index 03e62488ba4..2ad91dcae40 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -304,6 +304,38 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('column names (noLabel, label, string and default)', async function (assert) {
+ assert.expect(4);
+
+ const FieldChar = fieldRegistry.get('char');
+ fieldRegistry.add('nolabel_char', FieldChar.extend({
+ noLabel: true,
+ }));
+ fieldRegistry.add('label_char', FieldChar.extend({
+ label: "Some static label",
+ }));
+
+ const list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: `
+ <tree>
+ <field name="display_name" widget="nolabel_char"/>
+ <field name="foo" widget="label_char"/>
+ <field name="int_field" string="My custom label"/>
+ <field name="text"/>
+ </tree>`,
+ });
+
+ assert.strictEqual(list.$('thead th[data-name=display_name]').text(), '');
+ assert.strictEqual(list.$('thead th[data-name=foo]').text(), 'Some static label');
+ assert.strictEqual(list.$('thead th[data-name=int_field]').text(), 'My custom label');
+ assert.strictEqual(list.$('thead th[data-name=text]').text(), 'text field');
+
+ list.destroy();
+ });
+
QUnit.test('simple editable rendering', async function (assert) {
assert.expect(15);