fix: corretta modifica massiva dall'interfaccia ricerca spudorata.

This commit is contained in:
Gabriele Cimaschi committed 2026-08-27 15:01:08 +02:00
1 parent 3f3885130a
commit 8a617ecb22
1 file changed
+84 -4
+84 -4
View File
@@ -496,6 +496,9 @@ const RicercaSpudorataView = {
const batchApply = document.getElementById('batch-apply');
if (batchApply) batchApply.addEventListener('click', () => this.applyBatch());
const batchAddGroup = document.getElementById('batch-add-group');
if (batchAddGroup) batchAddGroup.addEventListener('click', () => this.addToGroup());
const batchMerge = document.getElementById('batch-merge');
if (batchMerge) batchMerge.addEventListener('click', () => this.mergeBatch());
@@ -716,10 +719,10 @@ const RicercaSpudorataView = {
}
try {
const ticketIds = Array.from(this.selectedIds).map(id => parseInt(id));
const res = await App.api('/api/tickets/batch', {
method: 'POST',
body: JSON.stringify({ ticketIds, updates })
const ticket_ids = Array.from(this.selectedIds).map(id => parseInt(id, 10));
const res = await App.api('/api/tickets/batch/update', {
method: 'PATCH',
body: JSON.stringify({ ticket_ids, updates })
});
Toast.success(res.message || 'Ticket aggiornati con successo');
@@ -745,6 +748,12 @@ const RicercaSpudorataView = {
t.owner_last = foundUser.last_name;
}
}
if (updates.responsible_user_id) {
t.responsible_user_id = updates.responsible_user_id;
}
if (updates.type_id) {
t.type_id = updates.type_id;
}
}
});
}
@@ -756,6 +765,77 @@ const RicercaSpudorataView = {
}
},
async addToGroup() {
if (this.selectedIds.size === 0) return;
try {
const groups = await App.api('/api/groups');
if (!groups || groups.length === 0) {
Toast.warning('non sono presenti gruppi');
return;
}
const groupOptions = groups.map(g => `<option value="${g.id}">${App.escapeHtml(g.nome)}</option>`).join('');
const dialogHtml = `
<div id="batch-group-modal" style="position: fixed; inset: 0; z-index: 8000; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center;">
<div style="background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); width: 400px; max-width: 90vw; padding: var(--space-lg); box-shadow: var(--shadow-lg);">
<h4 style="margin: 0 0 var(--space-md) 0; font-size: 1rem; font-weight: 600; color: var(--text-primary);">Aggiungi a Gruppo</h4>
<p style="font-size: 0.85rem; color: var(--text-secondary); margin-bottom: var(--space-md);">Seleziona il gruppo a cui aggiungere i <strong>${this.selectedIds.size}</strong> ticket selezionati:</p>
<select id="batch-group-select" class="form-select" style="width: 100%; margin-bottom: var(--space-lg);">
${groupOptions}
</select>
<div style="display: flex; gap: var(--space-sm); justify-content: flex-end;">
<button class="btn btn-ghost btn-sm" id="batch-group-cancel">Annulla</button>
<button class="btn btn-primary btn-sm" id="batch-group-confirm">Aggiungi</button>
</div>
</div>
</div>
`;
const modalContainer = document.createElement('div');
modalContainer.innerHTML = dialogHtml;
document.body.appendChild(modalContainer);
const closeModal = () => modalContainer.remove();
document.getElementById('batch-group-cancel').addEventListener('click', closeModal);
document.getElementById('batch-group-confirm').addEventListener('click', async () => {
const groupId = document.getElementById('batch-group-select').value;
if (!groupId) return;
const confirmBtn = document.getElementById('batch-group-confirm');
confirmBtn.disabled = true;
confirmBtn.textContent = 'Aggiunta...';
let addedCount = 0;
let errorsCount = 0;
for (const ticketId of this.selectedIds) {
try {
await App.api(`/api/groups/${groupId}/tickets`, {
method: 'POST',
body: JSON.stringify({ ticket_identifier: ticketId })
});
addedCount++;
} catch (err) {
errorsCount++;
}
}
closeModal();
if (addedCount > 0) {
Toast.success(`${addedCount} ticket aggiunti al gruppo!`);
this.cancelBatchSelection();
} else {
Toast.error('Impossibile aggiungere i ticket al gruppo selezionato.');
}
});
} catch (err) {
Toast.error('Errore caricamento gruppi: ' + err.message);
}
},
async mergeBatch() {
if (this.selectedOrder.length < 2) return;