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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
import {
OBSERVATION_TYPES,
GraduationChange,
submitGraduationChange,
Observation,
submitObservation
} from "../../js/graduation-ENV.js";
import { fetchGroups } from "../../js/group.js";
import { initSelection } from "../../js/selection.js";
import { getName } from "../../js/utils-ENV.js";
let group;
let name;
function toggle(btn) {
if (btn.innerHTML === "X")
btn.innerHTML = "o";
else
btn.innerHTML = "X";
document.getElementById("submit-mass-graduation").style.display = "block";
}
function observationClickHandler(ob, li) {
ob.style.background = "lightgray";
let observationDiv = li.observationDiv;
// Build the observation container
if(!observationDiv) {
observationDiv = document.createElement("div");
// Remember the observation div for this student
li.observationDiv = observationDiv;
observationDiv.id = `${li.student.name}-observation-container`;
observationDiv.classList.add("group-member-observation-container");
li.appendChild(observationDiv);
const obsTbl = document.createElement("table");
obsTbl.id = "group-member-observation-table";
observationDiv.appendChild(obsTbl);
const obsTh = document.createElement("thead");
obsTh.innerHTML = "<tr><td></td><td>Ja</td><td>Nein</td></tr>";
obsTbl.appendChild(obsTh);
const obsTbdy = document.createElement("tbody");
obsTbl.appendChild(obsTbdy);
for (const obsType of OBSERVATION_TYPES) {
const obsTr = document.createElement("tr");
const obsDesc = document.createElement("td");
obsDesc.innerHTML = obsType;
obsTr.appendChild(obsDesc);
const obsYes = document.createElement("td");
obsYes.innerHTML = "o";
obsYes.addEventListener("click", () => toggle(obsYes));
obsYes.dataset.yes = "true";
obsTr.appendChild(obsYes);
const obsNo = document.createElement("td");
obsNo.innerHTML = "o";
obsNo.addEventListener("click", () => toggle(obsNo) );
obsTr.appendChild(obsNo);
obsTbdy.appendChild(obsTr);
}
// Toggle the observation container visibility
} else {
if (observationDiv.style.display === "none") {
observationDiv.style.display = "block";
} else {
observationDiv.style.display = "none";
}
}
}
async function loadGroup(selected) {
group = selected;
const students = await group.getStudents();
document.getElementById("group-content").style.display = "block";
const ul = document.getElementById("group-members");
// Clear group list
ul.innerHTML = "";
for (const student of students) {
const li = document.createElement("li");
li.classList.add("group-member")
// Remember the student of the entry
li.student = student;
const ob = document.createElement("button");
ob.classList.add("group-member-observation-icon")
student.getGraduation().then((graduation) => {
if (!graduation.isObserved()) {
return;
}
ob.innerHTML = "👁"
ob.addEventListener("click", () => observationClickHandler(ob, li) );
});
li.appendChild(ob);
const i = document.createElement("img");
i.classList.add("group-member-icon")
student.getGraduation().then((graduation) => {
i.src = graduation.getIcon();
});
li.appendChild(i);
const n = document.createElement("span");
n.classList.add("group-member-name")
n.innerHTML = `${student.name}`;
li.appendChild(n);
for (const col of ["green", "orange", "red"]) {
const b = document.createElement("button");
b.classList.add(`group-member-${col}`)
b.innerHTML = "o";
b.addEventListener("click", () => toggle(b) );
li.appendChild(b);
}
const textarea = document.createElement("textarea");
textarea.classList.add("group-member-point-reason");
li.appendChild(textarea);
const p = document.createElement("button");
p.classList.add("group-member-print")
p.innerHTML = "🖶";
p.addEventListener("click", () => printRedPointNote(li) );
li.appendChild(p);
ul.appendChild(li);
}
}
function submitMassGraduation() {
for(const li of document.querySelectorAll("li.group-member")) {
const reason = li.querySelector(".group-member-point-reason").value;
const student = li.student;
if (li.querySelector(".group-member-green").innerHTML === "X") {
submitGraduationChange(student, GraduationChange.newGreenPointChange(reason, name));
}
if (li.querySelector(".group-member-orange").innerHTML === "X") {
submitGraduationChange(student, GraduationChange.newOrangePointChange(reason, name));
}
if (li.querySelector(".group-member-red").innerHTML === "X") {
submitGraduationChange(student, GraduationChange.newRedPointChange(reason, name));
}
if (li.observationDiv) {
let status = [];
for (const row of li.observationDiv.querySelectorAll("tbody > tr")) {
status.push(row.querySelector('td[data-yes="true"]').innerHTML === "X");
}
submitObservation(student, new Observation(Date.now(), status));
}
}
}
function printRedPointNote(li) {
print();
}
window.onload = function() {
initSelection(
"group-selection",
async function() { return (await fetchGroups()).values(); },
(group) => `${group.name}`,
loadGroup,
);
document.getElementById("submit-mass-graduation").addEventListener("click", submitMassGraduation);
name = getName();
}
|