From 9d6c4ec3fb96c4dc53a8c5e68fb414c471dd441d Mon Sep 17 00:00:00 2001 From: solocla Date: Fri, 23 Oct 2026 17:45:32 +0200 Subject: [PATCH] disattuivsa uodate --- public/userarea/worksheets.php | 162 +++++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 47 deletions(-) diff --git a/public/userarea/worksheets.php b/public/userarea/worksheets.php index 85c1ee7f..f2559622 100644 --- a/public/userarea/worksheets.php +++ b/public/userarea/worksheets.php @@ -525,6 +525,53 @@ $worksheets = $pdo->query(" opacity: 0.65; } + .ws-actions { + display: inline-flex; + align-items: center; + gap: 6px; + } + + .btn-icon { + width: 32px; + height: 32px; + padding: 0; + display: inline-flex; + align-items: center; + justify-content: center; + border-radius: 8px; + } + + .btn-icon i { + font-size: 1.1rem; + } + + .ws-switch { + margin: 0 4px 0 0; + padding-left: 2.6em; + min-height: auto; + } + + .ws-switch .form-check-input { + width: 2.4em; + height: 1.3em; + margin-top: 0; + cursor: pointer; + } + + .ws-switch .form-check-input:checked { + background-color: #198754; + border-color: #198754; + } + + .ws-switch .form-check-input:not(:checked):not(:disabled) { + background-color: #f8d7da; + border-color: #f1aeb5; + } + + .ws-switch .form-check-input:disabled { + cursor: not-allowed; + } + .table td, .table th { vertical-align: middle; @@ -628,48 +675,54 @@ $worksheets = $pdo->query(" - - - - - +
+ +
+ + > +
- + + + + + + + + + - - + + + - - - - - +
@@ -742,11 +795,17 @@ $worksheets = $pdo->query(" }); }); - $(document).on('click', '.toggle-ws-status', function() { - const id = $(this).data('id'); - const action = $(this).data('action'); - const name = $('
').text($(this).data('name') || '').html(); - const isDeact = action === 'deactivate'; + + $(document).on('change', '.toggle-ws-status', function() { + const input = this; + const id = $(input).data('id'); + const name = $('
').text($(input).data('name') || '').html(); + const isDeact = !input.checked; // l'utente l'ha appena spento + const action = isDeact ? 'deactivate' : 'reactivate'; + + const revert = () => { + input.checked = !input.checked; + }; Swal.fire({ title: isDeact ? 'Disattivare il foglio?' : 'Riattivare il foglio?', @@ -754,25 +813,30 @@ $worksheets = $pdo->query("
${name}
${isDeact - ? 'Il foglio resta nello storico ma non è più il foglio attivo della matrice. Potrai riattivarlo in seguito.' + ? 'Il foglio resta nello storico ma non è più il foglio attivo della matrice.' : 'Il foglio torna a essere il foglio attivo della matrice.'}
`, icon: 'question', showCancelButton: true, - confirmButtonColor: isDeact ? '#f59e0b' : '#198754', + confirmButtonColor: isDeact ? '#dc3545' : '#198754', cancelButtonColor: '#6c757d', confirmButtonText: isDeact ? 'Sì, disattiva' : 'Sì, riattiva', cancelButtonText: 'Annulla' }).then(result => { - if (!result.isConfirmed) return; + if (!result.isConfirmed) { + revert(); + return; + } + + input.disabled = true; fetch('', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - body: `ajax=1&action=${encodeURIComponent(action)}&id=${encodeURIComponent(id)}` + body: `ajax=1&action=${action}&id=${encodeURIComponent(id)}` }) .then(r => r.json()) .then(data => { @@ -784,6 +848,8 @@ $worksheets = $pdo->query(" showConfirmButton: false }).then(() => location.reload()); } else { + input.disabled = false; + revert(); Swal.fire({ icon: 'error', title: 'Errore', @@ -792,6 +858,8 @@ $worksheets = $pdo->query(" } }) .catch(() => { + input.disabled = false; + revert(); Swal.fire({ icon: 'error', title: 'Errore',