blob: b60d6e0a2d11f793a64151d6d894f38420d15926 [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 getRawWorkers() {
20 var parameters = [];
21 document.querySelectorAll("tr[data-worker-id]").forEach(tr => {
22 if (tr.querySelector("input[type=\"checkbox\"]").checked) {
23 parameters.push(tr.getAttribute("data-worker-id"));
24 }
25 });
26
27 return parameters;
28}
29
30function getParameters() {
31 var parameters = [];
32 var workers = getRawWorkers();
33 workers.forEach(worker => {
34 parameters.push("workers[]="+worker);
35 });
36
37 if (parameters.length == 0) return false;
38
39 return parameters.join("&");
40}
41
42window.addEventListener("load", function() {
43 var datatable = $('.datatable').DataTable({
44 paging: false,
45 ordering: false,
46 info: false,
47 searching:true
48 });
49
50 document.querySelector("#usuario").addEventListener("input", function(evt) {
51 this.search(evt.target.value);
52 this.draw(true);
53 }.bind(datatable));
54
55 document.querySelector(".filter").addEventListener("click", function() {
56 document.querySelector("#filter").showModal();
57 /* Or dialog.show(); to show the dialog without a backdrop. */
58 });
59
60 ["copytemplate", "addincidentbulk"].forEach(action => {
61 document.getElementById(action).addEventListener("click", function() {
62 var parameters = getParameters();
63 if (parameters === false) return;
64
65 var url = "dynamic/"+action+".php?"+parameters;
66 dynDialog.load(url);
67 });
68 });
69
70 document.getElementById("addrecurringincident").addEventListener("click", function () {
71 var workers = getRawWorkers();
72 if (workers.length > 1) {
73 if (document.querySelector(".mdl-js-snackbar") === null) {
74 document.body.insertAdjacentHTML('beforeend', '<div class="mdl-snackbar mdl-js-snackbar"><div class="mdl-snackbar__text"></div><button type="button" class="mdl-snackbar__action"></button></div>');
75 componentHandler.upgradeElement(document.querySelector(".mdl-js-snackbar"));
76 }
77
78 document.querySelector(".mdl-js-snackbar").MaterialSnackbar.showSnackbar(
79 {
80 message: "Solo se puede añadir una incidencia recurrente a un solo trabajador.",
81 timeout: 5000
82 }
83 );
84 // Display error message
85 } else if (workers.length == 1) {
86 window.location = "incidents.php?openRecurringFormWorker="+workers[0];
87 }
88 });
89});