@@ -136,7 +228,9 @@ $statusLabel = [
- | Nessuna newsletter. Creane una nuova o importane una da The Newsletter. |
+
+ | Nessuna newsletter. Creane una nuova o importane una da The Newsletter. |
+
body.append(k, v));
- const r = await fetch(API, { method: 'POST', body, credentials: 'same-origin' });
+ const r = await fetch(API, {
+ method: 'POST',
+ body,
+ credentials: 'same-origin'
+ });
let j = null;
- try { j = await r.json(); } catch (e) { }
+ try {
+ j = await r.json();
+ } catch (e) {}
if (!j || !j.success) throw new Error((j && j.message) || 'Errore del server.');
return j;
}
function esc(s) {
- return String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
+ return String(s ?? '').replace(/[&<>"']/g, c => ({
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": '''
+ } [c]));
}
document.getElementById('btnNew').addEventListener('click', async () => {
@@ -212,16 +318,24 @@ $statusLabel = [
});
if (!r.isConfirmed) return;
try {
- const j = await api('create', { title: r.value });
+ const j = await api('create', {
+ title: r.value
+ });
location.href = 'newsletter_editor.php?id=' + j.id;
- } catch (e) { Swal.fire('Errore', e.message, 'error'); }
+ } catch (e) {
+ Swal.fire('Errore', e.message, 'error');
+ }
});
document.querySelectorAll('.js-dup').forEach(b => b.addEventListener('click', async () => {
try {
- const j = await api('duplicate', { id: b.dataset.id });
+ const j = await api('duplicate', {
+ id: b.dataset.id
+ });
location.href = 'newsletter_editor.php?id=' + j.id;
- } catch (e) { Swal.fire('Errore', e.message, 'error'); }
+ } catch (e) {
+ Swal.fire('Errore', e.message, 'error');
+ }
}));
document.querySelectorAll('.js-del').forEach(b => b.addEventListener('click', async () => {
@@ -235,25 +349,45 @@ $statusLabel = [
cancelButtonText: 'Annulla'
});
if (!r.isConfirmed) return;
- try { await api('delete', { id: b.dataset.id }); location.reload(); } catch (e) { Swal.fire('Errore', e.message, 'error'); }
+ try {
+ await api('delete', {
+ id: b.dataset.id
+ });
+ location.reload();
+ } catch (e) {
+ Swal.fire('Errore', e.message, 'error');
+ }
}));
document.getElementById('btnImport').addEventListener('click', async () => {
- Swal.fire({ title: 'Carico le newsletter…', didOpen: () => Swal.showLoading() });
+ Swal.fire({
+ title: 'Carico le newsletter…',
+ didOpen: () => Swal.showLoading()
+ });
let list;
try {
- const r = await fetch(API + '?action=list_wp', { credentials: 'same-origin' });
+ const r = await fetch(API + '?action=list_wp', {
+ credentials: 'same-origin'
+ });
const j = await r.json();
if (!j.success) throw new Error(j.message);
list = j.emails;
- } catch (e) { return Swal.fire('Errore', e.message || 'Impossibile leggere The Newsletter.', 'error'); }
+ } catch (e) {
+ return Swal.fire('Errore', e.message || 'Impossibile leggere The Newsletter.', 'error');
+ }
- const labels = { new: 'bozza', sending: 'in invio', paused: 'in pausa', sent: 'inviata', error: 'errore' };
+ const labels = {
+ new: 'bozza',
+ sending: 'in invio',
+ paused: 'in pausa',
+ sent: 'inviata',
+ error: 'errore'
+ };
const html = '' + list.map(m =>
- '
' + esc(m.subject || '(senza oggetto)') + '
' +
- 'n. ' + m.id + ' · ' + esc(labels[m.status] || m.status) + ' · ' + esc((m.created || '').slice(0, 10)) + '
' +
- '
'
- ).join('') + '
' +
+ '' + esc(m.subject || '(senza oggetto)') + '
' +
+ 'n. ' + m.id + ' · ' + esc(labels[m.status] || m.status) + ' · ' + esc((m.created || '').slice(0, 10)) + '
' +
+ '
'
+ ).join('') + '' +
'Le bozze non ancora inviate restano collegate: "Pubblica" aggiornerà quella stessa newsletter.
';
Swal.fire({
@@ -267,9 +401,13 @@ $statusLabel = [
b.disabled = true;
b.textContent = '…';
try {
- const j = await api('import_wp', { wp_id: b.dataset.id });
+ const j = await api('import_wp', {
+ wp_id: b.dataset.id
+ });
location.href = 'newsletter_editor.php?id=' + j.id;
- } catch (e) { Swal.fire('Errore', e.message, 'error'); }
+ } catch (e) {
+ Swal.fire('Errore', e.message, 'error');
+ }
}));
}
});
@@ -277,4 +415,4 @@ $statusLabel = [