Odoo18-Base/addons/resource/static/src/section_list_renderer.js
2025-01-06 10:57:38 +07:00

57 lines
1.6 KiB
JavaScript

/** @odoo-module */
import { ListRenderer } from "@web/views/list/list_renderer";
import { useEffect } from "@odoo/owl";
export class SectionListRenderer extends ListRenderer {
setup() {
super.setup();
this.displayType = "line_section";
this.titleField = "title";
useEffect(
(table) => {
if (table) {
table.classList.add("o_section_list_view");
}
},
() => [this.tableRef.el]
);
}
getColumns(record) {
const columns = super.getColumns(record);
if (this.isSection(record)) {
return this.getSectionColumns(columns);
}
return columns;
}
getRowClass(record) {
const classNames = super.getRowClass(record).split(" ");
if (this.isSection(record)) {
classNames.push(`o_is_${this.displayType}`, `fw-bold`);
}
return classNames.join(" ");
}
getSectionColumns(columns) {
const sectionColumns = columns.filter((col) => col.widget === "handle");
let colspan = columns.length - sectionColumns.length;
if (this.activeActions.onDelete) {
colspan++;
}
const titleCol = columns.find(
(col) => col.type === "field" && col.name === this.titleField
);
sectionColumns.push({ ...titleCol, colspan });
return sectionColumns;
}
isSection(record) {
return record.data.display_type === this.displayType;
}
}
SectionListRenderer.recordRowTemplate = "resource.SectionListRenderer.RecordRow";