-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp.txt
More file actions
83 lines (70 loc) · 2.45 KB
/
tmp.txt
File metadata and controls
83 lines (70 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
boolean_radio.xml: deleted
boolean_radio.js:
import { _t } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { RadioField, radioField } from "@web/views/fields/radio/radio_field";
import { onMounted } from "@odoo/owl";
export class BooleanRadio extends RadioField {
static props = {
...RadioField.props,
yes_label_element_id: { type: String },
no_label_element_id: { type: String },
};
setup() {
super.setup(...arguments);
onMounted(() => {
this.updateLabels();
});
}
updateLabels() {
const trueLabel = document.getElementById(this.props.yes_label_element_id).innerText;
const falseLabel = document.getElementById(this.props.no_label_element_id).innerText;
document.getElementById( `${this.id}_true`).labels[0].textContent = trueLabel;
document.getElementById( `${this.id}_false`).labels[0].textContent = falseLabel;
}
get items() {
if (this.type === "boolean") return [["true", ""], ["false", ""]];
return super.items;
}
get value() {
if (this.type === "boolean") return this.props.record.data[this.props.name].toString();
return super.items;
}
/**
* @param {any} value
*/
onChange(value) {
if (this.type === "boolean") this.props.record.update({ [this.props.name]: value[0] === "true" });
super.onChange();
}
}
export const booleanRadio = {
...radioField,
component: BooleanRadio,
displayName: _t("Boolean display as radio field with translatable labels"),
supportedOptions: [
...radioField.supportedOptions,
{
label: _t("True association"),
name: "yes_label_element_id",
type: "string",
help: _t("Link an element with the boolean True value."),
},
{
label: _t("False association"),
name: "no_label_element_id",
type: "string",
help: _t("Link an element with the boolean False value."),
},
],
supportedTypes: ["boolean"],
extractProps({ options }, dynamicInfo) {
return {
...radioField.extractProps(...arguments),
readonly: dynamicInfo.readonly,
yes_label_element_id: options.yes_label_element_id,
no_label_element_id: options.no_label_element_id,
};
},
};
registry.category("fields").add("boolean_radio", booleanRadio);