disattuivsa uodate
This commit is contained in:
+115
-47
@@ -525,6 +525,53 @@ $worksheets = $pdo->query("
|
|||||||
opacity: 0.65;
|
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 td,
|
||||||
.table th {
|
.table th {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
@@ -628,48 +675,54 @@ $worksheets = $pdo->query("
|
|||||||
<td><?= h($ws['approved_by'] ?? '-') ?></td>
|
<td><?= h($ws['approved_by'] ?? '-') ?></td>
|
||||||
<td><?= h(formatDateTimeIT($ws['created_at'] ?? '')) ?></td>
|
<td><?= h(formatDateTimeIT($ws['created_at'] ?? '')) ?></td>
|
||||||
<td class="text-nowrap">
|
<td class="text-nowrap">
|
||||||
<?php if ($isActive): ?>
|
<div class="ws-actions">
|
||||||
<button class="btn btn-sm btn-outline-primary"
|
<?php
|
||||||
onclick="location.href='manage-worksheet.php?id=<?= (int)$ws['id'] ?>'">
|
if ($isActive) {
|
||||||
✏️ Modifica
|
$switchTitle = 'Attivo: clicca per disattivare';
|
||||||
</button>
|
} elseif ($canReactivate) {
|
||||||
<?php else: ?>
|
$switchTitle = 'Disattivato: clicca per riattivare';
|
||||||
<button class="btn btn-sm btn-outline-secondary"
|
} else {
|
||||||
onclick="location.href='manage-worksheet.php?id=<?= (int)$ws['id'] ?>'">
|
$switchTitle = 'Non riattivabile: esiste già un\'altra revisione attiva di ' . $worksheetLabel;
|
||||||
👁️ Vedi
|
}
|
||||||
</button>
|
?>
|
||||||
<?php endif; ?>
|
<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"
|
<?php if ($isActive): ?>
|
||||||
data-id="<?= (int)$ws['id'] ?>"
|
<a href="manage-worksheet.php?id=<?= (int)$ws['id'] ?>"
|
||||||
data-name="<?= h(($ws['matrice_nome'] ?? 'Foglio') . ' ' . $worksheetLabel) ?>"
|
class="btn btn-sm btn-icon btn-outline-primary" title="Modifica">
|
||||||
data-rev="<?= h($revisionLabel) ?>"
|
<i class='bx bx-edit-alt'></i>
|
||||||
data-fl="<?= h($worksheetLabel) ?>"
|
</a>
|
||||||
<?= !$isActive ? 'disabled title="Foglio già revisionato/inattivo"' : '' ?>>
|
<?php else: ?>
|
||||||
REV
|
<a href="manage-worksheet.php?id=<?= (int)$ws['id'] ?>"
|
||||||
</button>
|
class="btn btn-sm btn-icon btn-outline-secondary" title="Vedi">
|
||||||
|
<i class='bx bx-show'></i>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($isActive): ?>
|
<span title="<?= $isActive ? 'Crea nuova revisione' : 'Foglio già revisionato/inattivo' ?>">
|
||||||
<button class="btn btn-sm btn-outline-warning toggle-ws-status"
|
<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-id="<?= (int)$ws['id'] ?>"
|
||||||
data-action="deactivate"
|
data-name="<?= h($wsFullName) ?>"
|
||||||
data-name="<?= h($wsFullName) ?>">
|
title="Elimina">
|
||||||
⏸️ Disattiva
|
<i class='bx bx-trash'></i>
|
||||||
</button>
|
</button>
|
||||||
<?php elseif ($canReactivate): ?>
|
</div>
|
||||||
<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>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -742,11 +795,17 @@ $worksheets = $pdo->query("
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '.toggle-ws-status', function() {
|
|
||||||
const id = $(this).data('id');
|
$(document).on('change', '.toggle-ws-status', function() {
|
||||||
const action = $(this).data('action');
|
const input = this;
|
||||||
const name = $('<div>').text($(this).data('name') || '').html();
|
const id = $(input).data('id');
|
||||||
const isDeact = action === 'deactivate';
|
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({
|
Swal.fire({
|
||||||
title: isDeact ? 'Disattivare il foglio?' : 'Riattivare il foglio?',
|
title: isDeact ? 'Disattivare il foglio?' : 'Riattivare il foglio?',
|
||||||
@@ -754,25 +813,30 @@ $worksheets = $pdo->query("
|
|||||||
<div><strong>${name}</strong></div>
|
<div><strong>${name}</strong></div>
|
||||||
<div class="mt-2 small text-muted">
|
<div class="mt-2 small text-muted">
|
||||||
${isDeact
|
${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.'}
|
: 'Il foglio torna a essere il foglio attivo della matrice.'}
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
icon: 'question',
|
icon: 'question',
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonColor: isDeact ? '#f59e0b' : '#198754',
|
confirmButtonColor: isDeact ? '#dc3545' : '#198754',
|
||||||
cancelButtonColor: '#6c757d',
|
cancelButtonColor: '#6c757d',
|
||||||
confirmButtonText: isDeact ? 'Sì, disattiva' : 'Sì, riattiva',
|
confirmButtonText: isDeact ? 'Sì, disattiva' : 'Sì, riattiva',
|
||||||
cancelButtonText: 'Annulla'
|
cancelButtonText: 'Annulla'
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
if (!result.isConfirmed) return;
|
if (!result.isConfirmed) {
|
||||||
|
revert();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.disabled = true;
|
||||||
|
|
||||||
fetch('', {
|
fetch('', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'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(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@@ -784,6 +848,8 @@ $worksheets = $pdo->query("
|
|||||||
showConfirmButton: false
|
showConfirmButton: false
|
||||||
}).then(() => location.reload());
|
}).then(() => location.reload());
|
||||||
} else {
|
} else {
|
||||||
|
input.disabled = false;
|
||||||
|
revert();
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Errore',
|
title: 'Errore',
|
||||||
@@ -792,6 +858,8 @@ $worksheets = $pdo->query("
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
input.disabled = false;
|
||||||
|
revert();
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Errore',
|
title: 'Errore',
|
||||||
|
|||||||
Reference in New Issue
Block a user