blob: cecd3b7eb7a8c7e6aeeb1cc0e6a705b18755eb95 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001function getFormData() {
2 var data = {
3 "incidents": [],
4 "records": []
5 };
6
7 ["incident", "record"].forEach(key => {
8 document.querySelectorAll("input[type=\"checkbox\"][data-"+key+"]:checked").forEach(el => {
9 data[key+"s"].push(el.getAttribute("data-"+key));
10 });
11 });
12
13 return data;
14}
15
16window.addEventListener("load", function() {
17 document.querySelectorAll(".mdl-checkbox[data-check-all=\"true\"] input[type=\"checkbox\"]").forEach(el => {
18 el.addEventListener("change", e => {
19 el.parentElement.parentElement.parentElement.parentElement.parentElement.querySelectorAll(".mdl-checkbox:not([data-check-all=\"true\"])").forEach(input => {
20 var checkbox = input.MaterialCheckbox;
21
22 if (el.checked) checkbox.check();
23 else checkbox.uncheck();
24 });
25 });
26 });
27
28 document.querySelector("#submit").addEventListener("click", e => {
29 var data = getFormData();
30
31 if (data.incidents.length == 0 && data.records.length == 0) {
32 document.querySelector(".mdl-js-snackbar").MaterialSnackbar.showSnackbar({
33 message: "Debes seleccionar al menos una incidencia o registro para poder validar.",
34 timeout: 5000
35 });
36
37 return;
38 }
39
40 var form = document.createElement("form");
41 form.setAttribute("action", "interstitialvalidations.php");
42 form.setAttribute("method", "POST");
43 form.style.display = "none";
44
45 ["incidents", "records"].forEach(key => {
46 var input = document.createElement("input");
47 input.setAttribute("name", key);
48 input.setAttribute("value", data[key]);
49 form.appendChild(input);
50 });
51
52 document.body.appendChild(form);
53 form.submit();
54 });
55});