blob: 781f8141b2c605682b4a519aa3744156a4f3d51a [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 getFormData() {
20 var data = {
21 "incidents": [],
22 "records": []
23 };
24
25 ["incident", "record"].forEach(key => {
26 document.querySelectorAll("input[type=\"checkbox\"][data-"+key+"]:checked").forEach(el => {
27 data[key+"s"].push(el.getAttribute("data-"+key));
28 });
29 });
30
31 return data;
32}
33
34window.addEventListener("load", function() {
35 document.querySelectorAll(".mdl-checkbox[data-check-all=\"true\"] input[type=\"checkbox\"]").forEach(el => {
36 el.addEventListener("change", e => {
37 el.parentElement.parentElement.parentElement.parentElement.parentElement.querySelectorAll(".mdl-checkbox:not([data-check-all=\"true\"])").forEach(input => {
38 var checkbox = input.MaterialCheckbox;
39
40 if (el.checked) checkbox.check();
41 else checkbox.uncheck();
42 });
43 });
44 });
45
46 document.querySelector("#submit").addEventListener("click", e => {
47 var data = getFormData();
48
49 if (data.incidents.length == 0 && data.records.length == 0) {
50 document.querySelector(".mdl-js-snackbar").MaterialSnackbar.showSnackbar({
51 message: "Debes seleccionar al menos una incidencia o registro para poder validar.",
52 timeout: 5000
53 });
54
55 return;
56 }
57
58 var form = document.createElement("form");
59 form.setAttribute("action", "interstitialvalidations.php");
60 form.setAttribute("method", "POST");
61 form.style.display = "none";
62
63 ["incidents", "records"].forEach(key => {
64 var input = document.createElement("input");
65 input.setAttribute("name", key);
66 input.setAttribute("value", data[key]);
67 form.appendChild(input);
68 });
69
70 document.body.appendChild(form);
71 form.submit();
72 });
73});