[REF] *: list: renderer templates called dynamically

Several modules need to modify some parts of the templates used by the
list renderer. Those being called recursively (and with parameters
sometimes), it is quite lengthy to do. Now the call to templates are done
dynamically so that it is easier to extend the templates by specifying
some static keys of the ListRenderer.

Part-of: odoo/odoo#97984
This commit is contained in:
Mathieu Duckerts-Antoine
2022-08-29 13:49:09 +02:00
parent 9b1456a2ec
commit 8b1d92c787
7 changed files with 15 additions and 35 deletions
@@ -58,6 +58,7 @@ export class SectionAndNoteListRenderer extends ListRenderer {
}
}
SectionAndNoteListRenderer.template = "account.sectionAndNoteListRenderer";
SectionAndNoteListRenderer.recordRowTemplate = "account.SectionAndNoteListRenderer.RecordRow";
export class SectionAndNoteFieldOne2Many extends X2ManyField {
setup() {
@@ -4,15 +4,6 @@
<xpath expr="//table" position="attributes">
<attribute name="t-att-class">'o_section_and_note_list_view'</attribute>
</xpath>
<xpath expr="//t[@t-call='web.ListRenderer.Rows']" position="attributes">
<attribute name="t-call">account.SectionAndNoteListRenderer.Rows</attribute>
</xpath>
</t>
<t t-name="account.SectionAndNoteListRenderer.Rows" t-inherit="web.ListRenderer.Rows" t-inherit-mode="primary" owl="1">
<xpath expr="//t[@t-call='web.ListRenderer.RecordRow']" position="attributes">
<attribute name="t-call">account.SectionAndNoteListRenderer.RecordRow</attribute>
</xpath>
</t>
<t t-name="account.SectionAndNoteListRenderer.RecordRow" t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="primary" owl="1">
@@ -24,16 +24,11 @@ export class ResumeListRenderer extends CommonSkillsListRenderer {
}
setDefaultColumnWidths() {}
get RowsTemplate() {
return 'hr_skills.ResumeListRenderer.Rows';
}
get RecordRowTemplate() {
return 'hr_skills.ResumeListRenderer.RecordRow';
}
}
ResumeListRenderer.template = 'hr_skills.ResumeListRenderer';
ResumeListRenderer.rowsTemplate = "hr_skills.ResumeListRenderer.Rows";
ResumeListRenderer.recordRowTemplate = "hr_skills.ResumeListRenderer.RecordRow";
export class ResumeX2ManyField extends SkillsX2ManyField {}
ResumeX2ManyField.components = {
@@ -7,11 +7,6 @@
<xpath expr="//thead" position="attributes">
<attribute name="style">visibility: collapse;</attribute>
</xpath>
<xpath expr="//tbody[hasclass('ui-sortable')]/t" position="replace">
<t t-call="{{RowsTemplate}}">
<t t-set="list" t-value="props.list"/>
</t>
</xpath>
<xpath expr="//table" position="after">
<t t-if="!showTable">
<button t-on-click="props.onAdd" class="btn btn-secondary" role="button" t-if="isEditable">
@@ -36,7 +31,7 @@
</tr>
<t t-foreach="skill_group[1].list.records" t-as="record" t-key="record.id">
<t t-set="group" t-value="skill_group[1]"/>
<t t-call="{{RecordRowTemplate}}"/>
<t t-call="{{ constructor.recordRowTemplate }}"/>
</t>
</t>
</t>
@@ -53,12 +53,5 @@ export class CommonSkillsListRenderer extends ListRenderer {
return await super.onCellClicked(record, column, ev);
}
get RowsTemplate() {
return 'hr_skills.SkillsListRenderer.Rows';
}
get RecordRowTemplate() {
return 'web.ListRenderer.RecordRow';
}
}
CommonSkillsListRenderer.rowsTemplate = "hr_skills.SkillsListRenderer.Rows";
@@ -1702,6 +1702,11 @@ export class ListRenderer extends Component {
}
ListRenderer.template = "web.ListRenderer";
ListRenderer.rowsTemplate = "web.ListRenderer.Rows";
ListRenderer.recordRowTemplate = "web.ListRenderer.RecordRow";
ListRenderer.groupRowTemplate = "web.ListRenderer.GroupRow";
ListRenderer.components = { DropdownItem, Field, ViewButton, CheckBox, Dropdown, Pager };
ListRenderer.props = [
"activeActions?",
@@ -31,7 +31,7 @@
</tr>
</thead>
<tbody class="ui-sortable">
<t t-call="web.ListRenderer.Rows">
<t t-call="{{ constructor.rowsTemplate }}">
<t t-set="list" t-value="props.list"/>
</t>
</tbody>
@@ -71,7 +71,7 @@
<t t-name="web.ListRenderer.Rows" owl="1">
<t t-if="!list.isGrouped">
<t t-foreach="list.records" t-as="record" t-key="record.id">
<t t-call="web.ListRenderer.RecordRow"/>
<t t-call="{{ constructor.recordRowTemplate }}"/>
</t>
<tr t-if="displayRowCreates">
<td t-if="withHandleColumn"/>
@@ -111,9 +111,9 @@
</t>
<t t-else="">
<t t-foreach="list.groups" t-as="group" t-key="group.id">
<t t-call="web.ListRenderer.GroupRow"/>
<t t-call="{{ constructor.groupRowTemplate }}"/>
<t t-if="!group.isFolded">
<t t-call="web.ListRenderer.Rows">
<t t-call="{{ constructor.rowsTemplate }}">
<t t-set="list" t-value="group.list"/>
</t>
<tr t-if="!group.list.isGrouped and props.editable and props.activeActions['create']">