file repo, cc, auto-open

This commit is contained in:
2026-05-21 23:31:36 +03:00
parent 650676037a
commit 9001eff317
7 changed files with 279 additions and 74 deletions
+96 -28
View File
@@ -923,7 +923,9 @@ function getContrastTextColor($hexColor)
data-department="<?= htmlspecialchars($row['reparti'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-employees="<?= htmlspecialchars($row['responsabili'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-due-date="<?= htmlspecialchars($row['due_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-check-date="<?= htmlspecialchars($row['check_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
data-check-date="<?= htmlspecialchars($row['check_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-recurrence="<?= htmlspecialchars($row['recurrence_type'] ?? 'once', ENT_QUOTES, 'UTF-8') ?>"
data-att-count="<?= (int)$row['attachment_count'] ?>">
<?php if (!empty($row['subject_name'])): ?>
<div class="mb-1"><?php
$subjectBadgeBg = $row['subject_color'] ?: '#6c757d';
@@ -1000,7 +1002,9 @@ function getContrastTextColor($hexColor)
data-department="<?= htmlspecialchars($row['reparti'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-employees="<?= htmlspecialchars($row['responsabili'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-due-date="<?= htmlspecialchars($row['due_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-check-date="<?= htmlspecialchars($row['check_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
data-check-date="<?= htmlspecialchars($row['check_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
data-recurrence="<?= htmlspecialchars($row['recurrence_type'] ?? 'once', ENT_QUOTES, 'UTF-8') ?>"
data-att-count="<?= (int)$row['attachment_count'] ?>">
<td>
<?php if (!empty($row['subject_name'])): ?>
<?php
@@ -1613,12 +1617,14 @@ function getContrastTextColor($hexColor)
var btn = $(this);
var attId = btn.data('att-id');
Swal.fire({
title: 'Eliminare allegato?',
title: 'Rimuovere l\'allegato?',
text: 'Il collegamento verrà rimosso da questa scadenza. Il file resta disponibile se è usato da altre scadenze.',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#dc3545',
cancelButtonText: 'Annulla',
confirmButtonText: 'Elimina'
confirmButtonText: 'Rimuovi',
reverseButtons: true
}).then(function(result) {
if (result.isConfirmed) {
fetch('scadenzario/ajax/delete_attachment.php?id=' + attId)
@@ -1631,6 +1637,13 @@ function getContrastTextColor($hexColor)
if ($('#attachmentsList .att-item').length === 0) {
renderAttachments([]);
}
Swal.fire({
icon: 'success',
title: 'Fatto',
text: data.message,
timer: 1800,
showConfirmButton: false
});
} else {
Swal.fire('Errore', data.message, 'error');
}
@@ -1703,41 +1716,96 @@ function getContrastTextColor($hexColor)
});
// Complete
function submitComplete(id, createNext, copyAttachments) {
var fd = new FormData();
fd.append('id', id);
fd.append('create_next', createNext ? '1' : '0');
fd.append('copy_attachments', copyAttachments ? '1' : '0');
fetch('scadenzario/ajax/complete_deadline.php', {
method: 'POST',
body: fd
})
.then(function(r) {
return r.json();
})
.then(function(data) {
if (data.success) {
Swal.fire({
icon: 'success',
title: 'Completata',
text: data.message,
timer: 1800,
showConfirmButton: false
})
.then(function() {
// Auto-open the newly created deadline; otherwise just refresh the list
if (data.new_id) {
window.location = 'scadenzario/index.php?edit=' + data.new_id;
} else {
location.reload();
}
});
} else {
Swal.fire('Errore', data.message, 'error');
}
})
.catch(function() {
Swal.fire('Errore', 'Errore di connessione.', 'error');
});
}
$(document).on('click', '.btn-complete', function() {
var el = $(this).closest('[data-id]');
var id = el.data('id');
var recurrence = el.data('recurrence') || 'once';
var attCount = parseInt(el.data('att-count'), 10) || 0;
// Non-recurring: simple confirm, no new deadline is created
if (recurrence === 'once') {
Swal.fire({
title: 'Completare la scadenza?',
text: 'La scadenza verrà contrassegnata come completata.',
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#198754',
cancelButtonText: 'Annulla',
confirmButtonText: 'Completa',
reverseButtons: true
}).then(function(result) {
if (result.isConfirmed) {
submitComplete(id, false, false);
}
});
return;
}
// Recurring: ask whether to create the next deadline; optionally carry attachments over
var attCheckbox = attCount > 0 ?
'<div class="form-check d-flex align-items-center justify-content-center gap-2 mt-3">' +
'<input class="form-check-input" type="checkbox" id="swCopyAtt" checked>' +
'<label class="form-check-label" for="swCopyAtt">Copia gli allegati (' + attCount + ') sulla nuova scadenza</label>' +
'</div>' :
'';
Swal.fire({
title: 'Completare la scadenza?',
html: 'Vuoi creare automaticamente la prossima scadenza ricorrente?' + attCheckbox,
icon: 'question',
showCancelButton: true,
showDenyButton: true,
confirmButtonColor: '#198754',
denyButtonColor: '#6c757d',
confirmButtonText: 'Completa e crea la prossima',
denyButtonText: 'Completa senza nuova',
cancelButtonText: 'Annulla',
confirmButtonText: 'Completa'
reverseButtons: true
}).then(function(result) {
if (result.isConfirmed) {
fetch('scadenzario/ajax/complete_deadline.php?id=' + id)
.then(function(r) {
return r.json();
})
.then(function(data) {
if (data.success) {
Swal.fire({
icon: 'success',
title: 'Completata',
text: data.message,
timer: 2500,
showConfirmButton: false
})
.then(function() {
location.reload();
});
} else {
Swal.fire('Errore', data.message, 'error');
}
})
.catch(function() {
Swal.fire('Errore', 'Errore di connessione.', 'error');
});
var copy = attCount > 0 ? document.getElementById('swCopyAtt').checked : false;
submitComplete(id, true, copy);
} else if (result.isDenied) {
submitComplete(id, false, false);
}
});
});