[REF] *: manage columns record by record in list

Several modules need to display records data in a list table in a way
suitable to possibly different record types. Here we refactor the list
renderer to allows to specify columns (and their colspans) record by
record.

Part-of: odoo/odoo#97984
This commit is contained in:
Mathieu Duckerts-Antoine
2022-08-29 13:49:09 +02:00
parent 8b1d92c787
commit 1870b49d31
3 changed files with 7 additions and 3 deletions
@@ -23,7 +23,7 @@
</t>
<t t-name="hr_skills.ResumeListRenderer.RecordRow" owl="1" t-inherit-mode="primary" t-inherit="web.ListRenderer.RecordRow">
<xpath expr="//t[@t-foreach='state.columns']" position="replace">
<xpath expr="//t[@t-foreach='getColumns(record)']" position="replace">
<t t-set="data" t-value="record.data"/>
<td class="o_resume_timeline_cell position-relative pe-lg-2">
<div class="rounded-circle bg-info position-relative"/>
@@ -587,6 +587,10 @@ export class ListRenderer extends Component {
return classNames.join(" ");
}
getColumns(record) {
return this.state.columns;
}
/**
* Returns the classnames to apply to the row representing the given record.
* @param {Record} record
@@ -189,9 +189,9 @@
<td t-on-keydown.synthetic="(ev) => this.onCellKeydown(ev, group, record)" t-if="hasSelectors" class="o_list_record_selector" t-on-click.stop="() => this.toggleRecordSelection(record)" tabindex="-1">
<CheckBox disabled="!!props.list.editedRecord or props.list.model.useSampleModel" value="record.selected" onChange.bind="() => this.toggleRecordSelection(record)" />
</td>
<t t-foreach="state.columns" t-as="column" t-key="column.id">
<t t-foreach="getColumns(record)" t-as="column" t-key="column.id">
<t t-if="column.type === 'field'">
<td t-on-keydown.synthetic="(ev) => this.onCellKeydown(ev, group, record)" class="o_data_cell" t-att-name="column.name" t-att-class="getCellClass(column, record)" t-att-data-tooltip="getCellTitle(column, record)" data-tooltip-delay="1000" t-on-click="(ev) => this.onCellClicked(record, column, ev)" tabindex="-1">
<td t-on-keydown.synthetic="(ev) => this.onCellKeydown(ev, group, record)" class="o_data_cell" t-att-name="column.name" t-att-colspan="column.colspan" t-att-class="getCellClass(column, record)" t-att-data-tooltip="getCellTitle(column, record)" data-tooltip-delay="1000" t-on-click="(ev) => this.onCellClicked(record, column, ev)" tabindex="-1">
<t t-if="!evalModifier(column.modifiers.invisible, record)">
<t t-if="canUseFormatter(column, record)" t-esc="getFormattedValue(column, record)"/>
<Field t-else="" name="column.name" record="record" type="column.widget" class="getFieldClass(column)" fieldInfo="props.archInfo.fieldNodes[column.name]" setDirty="(isDirty) => this.setDirty(isDirty)"/>