Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
BIN
web_widget_domain_editor_dialog/static/src/img/behaviour.gif
Executable file
BIN
web_widget_domain_editor_dialog/static/src/img/behaviour.gif
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
36
web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js
Executable file
36
web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js
Executable file
@@ -0,0 +1,36 @@
|
||||
/* Copyright 2019 Tecnativa - David Vidal
|
||||
* Copyright 2024 Tecnativa - Carlos Roca
|
||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
import {DomainEditorDialog} from "./widget_domain_editor_dialog.esm";
|
||||
import {DomainField} from "@web/views/fields/domain/domain_field";
|
||||
import {_t} from "@web/core/l10n/translation";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
|
||||
patch(DomainField.prototype, {
|
||||
onButtonClick(ev) {
|
||||
const self = this;
|
||||
ev.preventDefault();
|
||||
if (this.props.readonly) {
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
if (!this.props.value) {
|
||||
this.props.value = "[]";
|
||||
}
|
||||
this.addDialog(DomainEditorDialog, {
|
||||
title: _t("Select records..."),
|
||||
noCreate: true,
|
||||
multiSelect: true,
|
||||
resModel: this.getResModel(),
|
||||
dynamicFilters: [
|
||||
{
|
||||
description: _t("Selected domain"),
|
||||
domain: this.getEvaluatedDomain(),
|
||||
},
|
||||
],
|
||||
context: this.getContext(),
|
||||
onSelected: function (resIds) {
|
||||
self.update(this.get_domain(resIds));
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
/* Copyright 2019 Tecnativa - David Vidal
|
||||
* Copyright 2024 Tecnativa - Carlos Roca
|
||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
import {Domain} from "@web/core/domain";
|
||||
import {SelectCreateDialog} from "@web/views/view_dialogs/select_create_dialog";
|
||||
import {deepEqual} from "@web/core/utils/objects";
|
||||
|
||||
export function findChildren(comp, predicate = (e) => e) {
|
||||
const queue = [];
|
||||
[].unshift.apply(queue, Object.values(comp.__owl__.children));
|
||||
|
||||
while (queue.length > 0) {
|
||||
const curNode = queue.pop();
|
||||
if (predicate(curNode)) {
|
||||
return curNode;
|
||||
}
|
||||
[].unshift.apply(queue, Object.values(curNode.component.__owl__.children));
|
||||
}
|
||||
}
|
||||
|
||||
export class DomainEditorDialog extends SelectCreateDialog {
|
||||
/**
|
||||
* Bind this to allow call get_domain from onSelected function definition.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
async select(resIds) {
|
||||
if (this.props.onSelected) {
|
||||
const onselected = this.props.onSelected.bind(this);
|
||||
await onselected(resIds);
|
||||
this.props.close();
|
||||
}
|
||||
}
|
||||
|
||||
_getDomainOfGroups(groups, domain) {
|
||||
const groups_unfolded = groups.filter((g) => !g.isFolded);
|
||||
const groups_domain = [];
|
||||
for (const group of groups_unfolded) {
|
||||
const group_list = group.list;
|
||||
if (group_list.groupBy.length) {
|
||||
groups_domain.push(this._getDomainOfGroups(group_list.groups, domain));
|
||||
} else {
|
||||
let group_domain = group_list.domain.slice();
|
||||
domain.forEach((d) => {
|
||||
group_domain = group_domain.filter((x) => !deepEqual(x, d));
|
||||
});
|
||||
group_domain = group_domain.filter((x) => x !== "&");
|
||||
groups_domain.push(group_domain);
|
||||
}
|
||||
}
|
||||
return Domain.or(groups_domain).toList();
|
||||
}
|
||||
|
||||
get_domain(resIds) {
|
||||
const dynamicList = findChildren(
|
||||
this,
|
||||
(node) =>
|
||||
node.component &&
|
||||
node.component.model &&
|
||||
node.component.model.root &&
|
||||
["DynamicGroupList", "DynamicRecordList"].includes(
|
||||
node.component.model.root.constructor.name
|
||||
)
|
||||
).component.model.root;
|
||||
let domain = dynamicList.domain;
|
||||
let group_domain = [];
|
||||
const checkbox = document.querySelector(".o_list_record_selector input");
|
||||
const isChecked = checkbox ? checkbox.checked : false;
|
||||
if (isChecked) {
|
||||
if (dynamicList.groupBy.length) {
|
||||
group_domain = this._getDomainOfGroups(dynamicList.groups, domain);
|
||||
}
|
||||
} else {
|
||||
domain = domain.concat([["id", "in", resIds]]);
|
||||
}
|
||||
return JSON.stringify(domain.concat(group_domain));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user