-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathLabelPicker.ts
More file actions
46 lines (39 loc) · 1.29 KB
/
LabelPicker.ts
File metadata and controls
46 lines (39 loc) · 1.29 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
/**
* Toggles the visibility of label groups based on the selected category.
*
* @author Alexander Ebert
* @copyright 2001-2023 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @woltlabExcludeBundle all
*/
type CategoryId = number;
type LabelGroupId = number;
function toggleVisibility(showLabelGroupIds: LabelGroupId[] | undefined): void {
if (showLabelGroupIds === undefined) {
showLabelGroupIds = [];
}
document.querySelectorAll("woltlab-core-label-picker").forEach((labelPicker) => {
const groupId = parseInt(labelPicker.dataset.groupId!);
if (showLabelGroupIds!.includes(groupId)) {
labelPicker.disabled = false;
labelPicker.closest("dl")!.hidden = false;
} else {
labelPicker.disabled = true;
labelPicker.closest("dl")!.hidden = true;
}
});
}
export function setup(categoryMapping: Map<CategoryId, LabelGroupId[]>): void {
if (categoryMapping.size === 0) {
return;
}
const categoryId = document.getElementById("categoryID") as HTMLSelectElement;
function updateVisibility() {
const value = parseInt(categoryId.value);
toggleVisibility(categoryMapping.get(value));
}
categoryId.addEventListener("change", () => {
updateVisibility();
});
updateVisibility();
}