disattuivsa uodate
This commit is contained in:
+115
-47
@@ -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("
|
||||
<td><?= h($ws['approved_by'] ?? '-') ?></td>
|
||||
<td><?= h(formatDateTimeIT($ws['created_at'] ?? '')) ?></td>
|
||||
<td class="text-nowrap">
|
||||
<?php if ($isActive): ?>
|
||||
<button class="btn btn-sm btn-outline-primary"
|
||||
onclick="location.href='manage-worksheet.php?id=<?= (int)$ws['id'] ?>'">
|
||||
✏️ Modifica
|
||||
</button>
|
||||
<?php else: ?>
|
||||
<button class="btn btn-sm btn-outline-secondary"
|
||||
onclick="location.href='manage-worksheet.php?id=<?= (int)$ws['id'] ?>'">
|
||||
👁️ Vedi
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<div class="ws-actions">
|
||||
<?php
|
||||
if ($isActive) {
|
||||
$switchTitle = 'Attivo: clicca per disattivare';
|
||||
} elseif ($canReactivate) {
|
||||
$switchTitle = 'Disattivato: clicca per riattivare';
|
||||
} else {
|
||||
$switchTitle = 'Non riattivabile: esiste già un\'altra revisione attiva di ' . $worksheetLabel;
|
||||
}
|
||||
?>
|
||||
<div class="form-check form-switch ws-switch" title="<?= h($switchTitle) ?>">
|
||||
<input class="form-check-input toggle-ws-status" type="checkbox" role="switch"
|
||||
data-id="<?= (int)$ws['id'] ?>"
|
||||
data-name="<?= h($wsFullName) ?>"
|
||||
<?= $isActive ? 'checked' : '' ?>
|
||||
<?= (!$isActive && !$canReactivate) ? 'disabled' : '' ?>>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-sm btn-outline-info btn-rev create-revision"
|
||||
data-id="<?= (int)$ws['id'] ?>"
|
||||
data-name="<?= h(($ws['matrice_nome'] ?? 'Foglio') . ' ' . $worksheetLabel) ?>"
|
||||
data-rev="<?= h($revisionLabel) ?>"
|
||||
data-fl="<?= h($worksheetLabel) ?>"
|
||||
<?= !$isActive ? 'disabled title="Foglio già revisionato/inattivo"' : '' ?>>
|
||||
REV
|
||||
</button>
|
||||
<?php if ($isActive): ?>
|
||||
<a href="manage-worksheet.php?id=<?= (int)$ws['id'] ?>"
|
||||
class="btn btn-sm btn-icon btn-outline-primary" title="Modifica">
|
||||
<i class='bx bx-edit-alt'></i>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a href="manage-worksheet.php?id=<?= (int)$ws['id'] ?>"
|
||||
class="btn btn-sm btn-icon btn-outline-secondary" title="Vedi">
|
||||
<i class='bx bx-show'></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($isActive): ?>
|
||||
<button class="btn btn-sm btn-outline-warning toggle-ws-status"
|
||||
<span title="<?= $isActive ? 'Crea nuova revisione' : 'Foglio già revisionato/inattivo' ?>">
|
||||
<button class="btn btn-sm btn-icon btn-outline-info create-revision"
|
||||
data-id="<?= (int)$ws['id'] ?>"
|
||||
data-name="<?= h(($ws['matrice_nome'] ?? 'Foglio') . ' ' . $worksheetLabel) ?>"
|
||||
data-rev="<?= h($revisionLabel) ?>"
|
||||
data-fl="<?= h($worksheetLabel) ?>"
|
||||
<?= !$isActive ? 'disabled' : '' ?>>
|
||||
<i class='bx bx-git-branch'></i>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<button class="btn btn-sm btn-icon btn-outline-danger delete-ws"
|
||||
data-id="<?= (int)$ws['id'] ?>"
|
||||
data-action="deactivate"
|
||||
data-name="<?= h($wsFullName) ?>">
|
||||
⏸️ Disattiva
|
||||
data-name="<?= h($wsFullName) ?>"
|
||||
title="Elimina">
|
||||
<i class='bx bx-trash'></i>
|
||||
</button>
|
||||
<?php elseif ($canReactivate): ?>
|
||||
<button class="btn btn-sm btn-outline-success toggle-ws-status"
|
||||
data-id="<?= (int)$ws['id'] ?>"
|
||||
data-action="reactivate"
|
||||
data-name="<?= h($wsFullName) ?>">
|
||||
▶️ Riattiva
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
<button class="btn btn-sm btn-outline-danger delete-ws"
|
||||
data-id="<?= (int)$ws['id'] ?>"
|
||||
data-name="<?= h(($ws['matrice_nome'] ?? 'Foglio') . ' ' . $worksheetLabel . ' rev. ' . $revisionLabel) ?>">
|
||||
🗑️ Elimina
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -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 = $('<div>').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 = $('<div>').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("
|
||||
<div><strong>${name}</strong></div>
|
||||
<div class="mt-2 small text-muted">
|
||||
${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.'}
|
||||
</div>
|
||||
`,
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user