66 lines
2.8 KiB
JavaScript
66 lines
2.8 KiB
JavaScript
// ── documenti_export.js — Excel & PDF export ──
|
|
// Depends on _Doc namespace. Export uses ALL filter-visible blocks (not just current page).
|
|
|
|
document.getElementById('btn-excel').addEventListener('click', function() {
|
|
var csvRows = [['Sessione', 'Corso', 'Azienda', 'Cartella', 'Tipo', 'Stato', 'File', 'Note', 'Caricato']];
|
|
_Doc.blocks.forEach(function(block) {
|
|
if (block.style.display === 'none') return; // filter-hidden: skip
|
|
var sessione = block.dataset.sessione || '';
|
|
var corso = block.dataset.corso || '';
|
|
var azienda = block.dataset.azienda || '';
|
|
block.querySelectorAll('.doc-row').forEach(function(row) {
|
|
if (row.style.display === 'none') return;
|
|
csvRows.push([
|
|
sessione, corso, azienda,
|
|
row.dataset.subfolder || '',
|
|
row.dataset.doctype || '',
|
|
row.dataset.status || '',
|
|
row.dataset.filename || '',
|
|
row.dataset.note || '',
|
|
row.dataset.uploaded || '',
|
|
]);
|
|
});
|
|
});
|
|
var csv = csvRows.map(function(r) {
|
|
return r.map(function(v) {
|
|
var s = String(v).replace(/"/g, '""');
|
|
return (s.indexOf(',') !== -1 || s.indexOf('"') !== -1 || s.indexOf('\n') !== -1) ? '"' + s + '"' : s;
|
|
}).join(',');
|
|
}).join('\r\n');
|
|
var blob = new Blob(['\uFEFF' + csv], { type: 'text/csv;charset=utf-8;' });
|
|
var url = URL.createObjectURL(blob);
|
|
var a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = 'documenti_' + new Date().toISOString().slice(0, 10) + '.csv';
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(url);
|
|
});
|
|
|
|
document.getElementById('btn-pdf').addEventListener('click', function() {
|
|
// Temporarily show all filter-visible blocks (including pag-hidden) for print
|
|
var pagHidden = _Doc.blocks.filter(function(b) { return b.classList.contains('pag-hidden'); });
|
|
pagHidden.forEach(function(b) { b.classList.remove('pag-hidden'); });
|
|
|
|
var wasOpen = _Doc.blocks.map(function(b) { return b.open; });
|
|
_Doc.blocks.forEach(function(b) {
|
|
if (b.style.display === 'none') {
|
|
b.classList.add('print-hidden');
|
|
} else {
|
|
var visibleRows = Array.prototype.filter.call(b.querySelectorAll('.doc-row'), function(r) { return r.style.display !== 'none'; });
|
|
if (visibleRows.length === 0) { b.classList.add('print-hidden'); } else { b.open = true; }
|
|
}
|
|
});
|
|
document.querySelectorAll('.doc-row').forEach(function(r) {
|
|
if (r.style.display === 'none') r.classList.add('print-hidden');
|
|
});
|
|
|
|
window.print();
|
|
|
|
// Restore state
|
|
_Doc.blocks.forEach(function(b, i) { b.classList.remove('print-hidden'); b.open = wasOpen[i]; });
|
|
document.querySelectorAll('.doc-row.print-hidden').forEach(function(r) { r.classList.remove('print-hidden'); });
|
|
pagHidden.forEach(function(b) { b.classList.add('pag-hidden'); });
|
|
});
|