bemade-addons/recursive_tree_view/static/src/list_controller.js
Marc Durepos 6bab956a54 [ADD] recursive_tree_view: new module for hierarchical models
Allows the viewing of hierarchical models (i.e. parent-child
relationships) directly in a tree view. Simply add the recursive
attribute to the tree tag with `recursive="1"` or `recursive="true"` or
`recursive="True"`.

Parent-child field is autodetected from the model based on the
_parent_name field which is standard in the Odoo ORM.

Currently there is no option for expanding all children, but this may be
added in future versions.
2024-10-30 12:11:55 -04:00

37 lines
1 KiB
JavaScript

/** @odoo-module **/
import {ListController} from '@web/views/list/list_controller';
import {patch} from '@web/core/utils/patch';
import {useBus} from "@web/core/utils/hooks";
patch(ListController.prototype, {
async setup() {
if (this.props.archInfo.recursive) {
this.recursive = true;
useBus(this.env.bus, "expand-collapse-parent", this.onExpandCollapseParent);
} else {
this.recursive = false;
}
super.setup();
},
async onExpandCollapseParent(ev) {
const parentId = ev.detail;
const record = this.model.findRecordInHierarchy(parentId);
if (record.expanded) {
record.expanded = false;
} else {
await this.model._loadChildren(record.children);
record.expanded = true;
}
},
get modelParams() {
const params = super.modelParams;
if (this.recursive) {
params["config"]["recursive"] = true;
}
return params;
},
});