blob: 03121f827799eb68beae269844980052e62536d6 [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 incidents = [];
21
22 document.querySelectorAll("input[type=\"checkbox\"][data-incident]:checked").forEach(el => {
23 incidents.push(el.getAttribute("data-incident"));
24 });
25
26 return incidents;
27}
28
29function getParameters() {
30 var parameters = [];
31 var incidents = getFormData();
32 incidents.forEach(incident => {
33 parameters.push("incidents[]="+incident);
34 });
35
36 if (parameters.length == 0) return false;
37
38 return parameters.join("&");
39}
40
41window.addEventListener("load", function() {
42 document.querySelector(".addincident").addEventListener("click", function() {
43 document.querySelector("#addincident").showModal();
44 /* Or dialog.show(); to show the dialog without a backdrop. */
45 });
46
47 document.querySelector(".addrecurringincident").addEventListener("click", function() {
48 document.querySelector("#addrecurringincident").showModal();
49 /* Or dialog.show(); to show the dialog without a backdrop. */
50 });
51
52 document.querySelector(".filter").addEventListener("click", function() {
53 document.querySelector("#filter").showModal();
54 /* Or dialog.show(); to show the dialog without a backdrop. */
55 });
56
57 if (_showResultsPaginated) {
58 document.getElementById("limit-change").addEventListener("change", _ => {
59 var limit = parseInt(document.getElementById("limit-change").value);
60 var firstIncidentPos = _page*_limit;
61 var page = Math.floor(firstIncidentPos/limit) + 1;
62
63 var url = new URL(location.href);
64 url.searchParams.set("limit", limit);
65 url.searchParams.set("page", page);
66 location.href = url;
67 });
68 }
69
70 document.querySelectorAll(".mdl-checkbox[data-check-all=\"true\"] input[type=\"checkbox\"]").forEach(el => {
71 el.addEventListener("change", e => {
72 el.parentElement.parentElement.parentElement.parentElement.parentElement.querySelectorAll(".mdl-checkbox:not([data-check-all=\"true\"])").forEach(input => {
73 var checkbox = input.MaterialCheckbox;
74 if (checkbox.inputElement_.disabled) return;
75
76 if (el.checked) checkbox.check();
77 else checkbox.uncheck();
78 });
79 });
80 });
81
82 document.getElementById("deleteincidentsbulk").addEventListener("click", e => {
83 var parameters = getParameters();
84
85 if (parameters === false) {
86 document.querySelector(".mdl-js-snackbar").MaterialSnackbar.showSnackbar({
87 message: "Debes seleccionar al menos una incidencia para poder eliminar.",
88 timeout: 5000
89 });
90
91 return;
92 }
93
94 var url = "dynamic/deleteincidentsbulk.php?"+parameters;
95 dynDialog.load(url);
96 });
97});