-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathdetermination-template.js
More file actions
75 lines (69 loc) · 2.02 KB
/
Copy pathdetermination-template.js
File metadata and controls
75 lines (69 loc) · 2.02 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
(function () {
const field_blocks_ids = JSON.parse(
document.getElementById("block-ids").textContent
);
let DeterminationCopy = class {
static selector() {
return "#id_" + field_blocks_ids["determination"];
}
constructor(node) {
this.node = node;
this.bindEventListeners();
}
bindEventListeners() {
this.node.addEventListener(
"change",
(e) => {
this.getMatchingCopy(e.target.value);
},
false
);
}
getMatchingCopy(value) {
const proposal_form = document.querySelector("#id_proposal_form");
if (["", "0", "1"].includes(value)) {
if (proposal_form) {
proposal_form.disabled = true;
proposal_form.required = false;
}
if (value === "") {
this.text = "";
} else if (value === "0") {
this.text = document.querySelector(
'div[data-type="rejected"]'
).textContent;
} else if (value === "1") {
this.text = document.querySelector(
'div[data-type="more_info"]'
).textContent;
}
} else if (value === "2") {
this.text = document.querySelector(
'div[data-type="accepted"]'
).textContent;
if (proposal_form) {
proposal_form.disabled = false;
proposal_form.required = true;
}
}
this.updateTextArea(this.text);
}
updateTextArea(text) {
this.message_box = document.querySelector(
"#id_" + field_blocks_ids["message"] + "_ifr"
);
this.message_box.contentDocument.getElementsByTagName(
"body"
)[0].innerHTML = text;
}
};
document.querySelectorAll(DeterminationCopy.selector()).forEach((el) => {
new DeterminationCopy(el);
});
window.addEventListener("load", function (event) {
const proposal_form_field = document.querySelector("#id_proposal_form");
if (proposal_form_field && !proposal_form_field.value) {
proposal_form_field.disabled = true;
}
});
})();