blob: 85f52a48f40d55934b9d832e0a05426dad1200c1 [file] [log] [blame]
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01001/* (license-header)
2 * hores
3 * Copyright (c) 2023 Adrià Vilanova Martínez
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public
16 * License along with this program.
17 * If not, see http://www.gnu.org/licenses/.
18 */
Copybara botbe50d492023-11-30 00:16:42 +010019function toggleTr(tr, show) {
20 var checkbox = tr.querySelector("label").MaterialCheckbox;
21 if (show) {
22 tr.style.display = "table-row";
23 checkbox.enable();
24 } else {
25 tr.style.display = "none";
26 checkbox.disable();
27 }
28}
29
30window.addEventListener("load", function() {
31 document.querySelectorAll("tr[data-worker-id]").forEach(tr => {
32 var checkbox = tr.querySelector("input[type=\"checkbox\"]");
33
34 checkbox.setAttribute("name", "workers[]");
35 checkbox.setAttribute("value", tr.getAttribute("data-worker-id"));
36
37 toggleTr(tr, false);
38 });
39
40 document.querySelectorAll(".select-all").forEach(el => {
41 el.addEventListener("click", e => {
42 var allchecked = true;
43 el.getAttribute("data-workers").split(",").forEach(workerid => {
44 var tr = document.querySelector("tr[data-worker-id=\""+workerid+"\"]");
45 var checkbox = tr.querySelector("label").MaterialCheckbox;
46 if (checkbox.inputElement_.disabled) return;
47 if (!checkbox.inputElement_.checked) allchecked = false;
48 tr.classList.add("is-selected");
49 checkbox.check();
50 });
51
52 if (allchecked) {
53 el.getAttribute("data-workers").split(",").forEach(workerid => {
54 var tr = document.querySelector("tr[data-worker-id=\""+workerid+"\"]");
55 var checkbox = tr.querySelector("label").MaterialCheckbox;
56 tr.classList.remove("is-selected");
57 checkbox.uncheck();
58 });
59 }
60 });
61 });
62
63 var multiselectEl = document.querySelector(".mdl-custom-multiselect");
64 if (multiselectEl !== null) {
65 multiselectEl.addEventListener("custom-multiselect-change", e => {
66 var companies = [];
67 document.querySelectorAll(".mdl-custom-multiselect .mdl-custom-multiselect__item input[type=\"checkbox\"]").forEach(checkbox => {
68 if (checkbox.checked) {
69 companies.push(checkbox.value);
70 }
71 });
72
73 document.querySelectorAll("tr[data-worker-id]").forEach(tr => {
74 toggleTr(tr, companies.includes(tr.getAttribute("data-company-id")));
75 });
76 });
77 }
78
79 document.querySelectorAll("input[name=\"companies\[\]\"]").forEach(input => {
80 input.checked = true;
81 var customevent = document.createEvent("HTMLEvents");
82 customevent.initEvent("change", false, true);
83 input.dispatchEvent(customevent);
84 });
85
86 document.getElementById("format").addEventListener("change", e => {
87 document.getElementById("pdf").style.display = (document.getElementById("format").value != "1" && document.getElementById("format").value != "2" ? "none" : "block");
88 });
89});