fix mail sand 2
This commit is contained in:
@@ -288,11 +288,7 @@ function setupEventListeners() {
|
||||
office_id: currentOffice.id
|
||||
});
|
||||
|
||||
if (res && res.status !== 403 && res.status !== 500 && res.ok !== false) {
|
||||
// API wrapper usually returns response object or parses JSON?
|
||||
// api.post returns response object if 200-299, but wrapper handles some.
|
||||
// Let's assume standard fetch response or check wrapper.
|
||||
// api.js Wrapper returns fetch Response.
|
||||
if (res && res.status >= 200 && res.status < 300) {
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
@@ -306,7 +302,9 @@ function setupEventListeners() {
|
||||
}
|
||||
} else {
|
||||
const err = res ? await res.json() : {};
|
||||
utils.showMessage('Errore: ' + (err.detail || 'Invio fallito'), 'error');
|
||||
console.error("Test Email Error:", err);
|
||||
const errMsg = err.detail ? (typeof err.detail === 'object' ? JSON.stringify(err.detail) : err.detail) : 'Invio fallito';
|
||||
utils.showMessage('Errore: ' + errMsg, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -314,4 +312,51 @@ function setupEventListeners() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const bulkEmailBtn = document.getElementById('bulkEmailBtn');
|
||||
if (bulkEmailBtn) {
|
||||
bulkEmailBtn.addEventListener('click', async () => {
|
||||
const dateVal = document.getElementById('testEmailDate').value;
|
||||
|
||||
// Validate office
|
||||
if (!currentOffice || !currentOffice.id) {
|
||||
return utils.showMessage('Errore: Nessun ufficio selezionato', 'error');
|
||||
}
|
||||
|
||||
if (!dateVal) {
|
||||
return utils.showMessage('Per il test a TUTTI è obbligatorio selezionare una data specifica.', 'error');
|
||||
}
|
||||
|
||||
if (!confirm(`Sei sicuro di voler inviare una mail di promemoria a TUTTI gli utenti con parcheggio assegnato per il giorno ${dateVal}?\n\nQuesta azione invierà vere email.`)) return;
|
||||
|
||||
utils.showMessage('Invio mail massive in corso...', 'warning');
|
||||
|
||||
try {
|
||||
const res = await api.post('/api/parking/test-email', {
|
||||
date: dateVal,
|
||||
office_id: currentOffice.id,
|
||||
bulk_send: true
|
||||
});
|
||||
|
||||
if (res && res.status >= 200 && res.status < 300) {
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
let msg = `Processo completato per il ${data.date}. Inviate: ${data.count || 0}, Fallite: ${data.failed || 0}.`;
|
||||
if (data.mode === 'BULK' && (data.count || 0) === 0) msg += " (Nessun assegnatario trovato)";
|
||||
utils.showMessage(msg, 'success');
|
||||
} else {
|
||||
utils.showMessage('Errore durante l\'invio.', 'error');
|
||||
}
|
||||
} else {
|
||||
const err = res ? await res.json() : {};
|
||||
console.error("Bulk Test Email Error:", err);
|
||||
const errMsg = err.detail ? (typeof err.detail === 'object' ? JSON.stringify(err.detail) : err.detail) : 'Invio fallito';
|
||||
utils.showMessage('Errore: ' + errMsg, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
utils.showMessage('Errore di comunicazione col server: ' + e.message, 'error');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,10 @@
|
||||
</small>
|
||||
</div>
|
||||
<button id="testEmailBtn" class="btn btn-secondary">
|
||||
Test Invio Mail
|
||||
Test (Solo a Me)
|
||||
</button>
|
||||
<button id="bulkEmailBtn" class="btn btn-warning" title="Invia mail reale a tutti gli assegnatari">
|
||||
Test (A Tutti)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user