[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
This commit is contained in:
@@ -81,6 +81,11 @@ var AbstractField = Widget.extend({
|
||||
* If this flag is set to true, the list column name will be empty.
|
||||
*/
|
||||
noLabel: false,
|
||||
/**
|
||||
* Currently only used in list view.
|
||||
* If set, this value will be displayed as column name.
|
||||
*/
|
||||
label: '',
|
||||
/**
|
||||
* Abstract field class
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user