Skip to content

Commit 1f9430d

Browse files
committed
feat: aggiunta tasto "Seleziona tutti" sui gruppi
1 parent bd44da2 commit 1f9430d

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

modules/viste/edit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
globals.translations.working_query = "'.tr('Query funzionante').'";
152152
globals.translations.query_works_correctly = "'.tr('La query attuale funziona correttamente!').'";
153153
globals.translations.error = "'.tr('Errore').'";
154+
globals.translations.select_all = "'.tr('Seleziona tutti').'";
154155
</script>
155156
<link rel="stylesheet" href="'.base_path().'/modules/viste/css/main.css">
156157
<script src="'.base_path().'/modules/viste/js/main.js"></script>

modules/viste/js/main.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function copyQueryToClipboard() {
55
var copyText = document.getElementById("query-to-copy");
66
copyText.select();
77
document.execCommand("copy");
8-
8+
99
// Mostra un messaggio di conferma
1010
swal(globals.translations.copied, globals.translations.query_copied, "success");
1111
}
@@ -35,6 +35,41 @@ function testQuery() {
3535
});
3636
}
3737

38+
/**
39+
* Aggiunge i pulsanti "Seleziona tutti" dinamicamente alle label dei gruppi
40+
*/
41+
function addSelectAllButtons() {
42+
// Cerca tutte le label che contengono "Gruppi con accesso"
43+
$("label:contains('Gruppi con accesso')").each(function() {
44+
var label = $(this);
45+
label.css("display", "block");
46+
47+
// Crea il pulsante solo se non esiste già
48+
if (label.find(".btn-select-all-groups").length === 0) {
49+
var button = $('<div class="pull-right"><button type="button" class="btn btn-xs btn-default btn-select-all-groups" style="margin-left: 5px;"><i class="fa fa-check-square-o"></i> ' + globals.translations.select_all + '</button></div>');
50+
label.append(button);
51+
}
52+
});
53+
54+
// Gestione del click sul pulsante "Seleziona tutti"
55+
$(document).off("click", ".btn-select-all-groups").on("click", ".btn-select-all-groups", function(e) {
56+
e.preventDefault();
57+
58+
// Trova il select associato alla label
59+
var formGroup = $(this).closest(".form-group");
60+
var selectElement = formGroup.find("select");
61+
62+
// Seleziona tutte le opzioni
63+
selectElement.find("option").prop("selected", true);
64+
65+
// Aggiorna il plugin select2 se presente
66+
if ($.fn.select2) {
67+
selectElement.trigger("change");
68+
}
69+
});
70+
}
71+
72+
3873
/**
3974
* Inizializzazione degli event listener quando il documento è pronto
4075
*/
@@ -43,4 +78,15 @@ $(document).ready(function() {
4378
$("#copy-query-btn").click(function() {
4479
copyQueryToClipboard();
4580
});
81+
82+
// Aggiungi il pulsante "Seleziona tutti" accanto alle label dei gruppi
83+
addSelectAllButtons();
84+
85+
// Quando viene aggiunto un nuovo campo, aggiungi anche il pulsante
86+
$(document).on("click", "#add", function() {
87+
// Attendiamo che il nuovo campo sia stato aggiunto e inizializzato
88+
setTimeout(function() {
89+
addSelectAllButtons();
90+
}, 500);
91+
});
4692
});

0 commit comments

Comments
 (0)