PROVENANCE
Condition Documentation
`; } function wireDossier(art){ const cs=document.getElementById('condSel'); if(cs) cs.onchange=()=>{ art.condition=cs.value; save(); }; const ex=document.getElementById('examInp'); if(ex) ex.onchange=()=>{ art.examiner=ex.value.trim(); setExaminer(art.examiner); save(); }; const sign=document.getElementById('btnSign'); if(sign) sign.onclick=()=>{art.examiner=ex.value.trim();setExaminer(art.examiner);if(save())signDossier(art);}; wireLoan(art); const b=document.getElementById('btnPrint'); if(!b) return; b.onclick=async()=>{ art.examiner=(document.getElementById('examInp').value||'').trim(); setExaminer(art.examiner); save(); b.disabled=true; b.textContent='Recording…'; const output=document.getElementById('dossierOut'); output.innerHTML=''; try{ const {html, rid, hash, file}=await buildDossier(art); const nPins=art.photos.reduce((s,p)=>s+p.pins.length,0); if(!output.isConnected) return; output.innerHTML=`
${nPins} finding${nPins===1?'':'s'} documented
${art.photos.length} photo${art.photos.length===1?'':'s'} · ${art.custody.length} custody event${art.custody.length===1?'':'s'} · ${art.climate.length} climate reading${art.climate.length===1?'':'s'} · tamper-evident hash recorded
Dossier ${rid}
`+html+`
`; document.getElementById('btnDoPrint').onclick=()=>window.print(); document.getElementById('btnDoFile').onclick=()=>{ const blob=new Blob([file],{type:'text/html'}); const a=document.createElement('a'); a.href=URL.createObjectURL(blob); a.download='provenance-dossier-'+rid+'.html'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(()=>URL.revokeObjectURL(a.href),4000); toast('Dossier file downloaded, send it to the adjuster'); }; document.getElementById('btnEmail').onclick=()=>emailClaimSummary(art,rid,hash); document.getElementById('dossierDoc').scrollIntoView({behavior:'smooth'}); toast('Dossier ready, print or save as PDF'); }catch(err){toast('Could not seal dossier. Try again in a browser with secure hashing support.');} finally{b.disabled=false;b.innerHTML=IC.doc+' Generate dossier';} }; } function wireTab(art,tab){ if(tab==='photos') wirePhotos(art); else if(tab==='custody') wireCustody(art); else if(tab==='climate') wireClimate(art); else wireDossier(art); } /* ---------- claim-settlement email draft (Item 8) ---------- */ function emailClaimSummary(art,rid,hash){ const sev={minor:0,moderate:0,severe:0}; art.photos.forEach(p=>p.pins.forEach(pin=>{ if(sev[pin.severity]!=null) sev[pin.severity]++; })); const nPins=sev.minor+sev.moderate+sev.severe; const lines=[ 'Condition dossier for '+(art.title||'Untitled')+((art.artist?', '+art.artist:'')+(art.year?' ('+art.year+')':'')), 'Declared value: '+fmtMoney(art.value), 'Overall condition: '+(art.condition||'Not assessed'), 'Examiner: '+(art.examiner||'Not recorded'), 'Dossier ID: '+rid, 'Generated: '+fmtDate(new Date().toISOString()), 'Findings: '+nPins+' total ('+sev.severe+' severe, '+sev.moderate+' moderate, '+sev.minor+' minor)', 'Evidence: '+art.photos.length+' photos, '+art.custody.length+' custody events, '+art.climate.length+' climate readings', 'Integrity hash (SHA-256): '+hash, 'This hash was computed on the examiner\u2019s device when the dossier was generated. It records the evidence used for this document at that moment.', '', 'Print the dossier to PDF and attach it before sending. Reply to this email with questions.' ]; const subject='Condition dossier '+rid+': '+(art.title||'Untitled'); location.href='mailto:?subject='+encodeURIComponent(subject)+'&body='+encodeURIComponent(lines.join('\n')); } /* ================= export / import ================= */ function exportBackup(){ try{ const blob=new Blob([JSON.stringify(failedBackup||DB)],{type:'application/json'}); const a=document.createElement('a'); a.href=URL.createObjectURL(blob); a.download='provenance-backup-'+new Date().toISOString().slice(0,10)+'.json'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(()=>URL.revokeObjectURL(a.href),4000); toast('Backup downloaded'); return true; }catch(e){ toast('Could not export backup. Please try again.'); return false; } } document.getElementById('btnExport').onclick=()=>{ exportBackup(); }; document.getElementById('btnImport').onclick=()=>document.getElementById('importFile').click(); document.getElementById('importFile').onchange=e=>{ const f=e.target.files[0]; if(!f) return; const r=new FileReader(); r.onload=()=>{ try{ const d=JSON.parse(r.result); if(!d.artworks) throw 0; DB=d; if(save()){ render(); toast('Backup imported'); } }catch(_){ toast('Invalid backup file'); } }; r.readAsText(f); e.target.value=''; }; /* ================= init ================= */ load(); render(); refreshStorageInfo(); if(loadWarning==='corrupt') toast('Saved records were unreadable, so the list was reset to empty.'); else if(loadWarning==='unavailable') toast('Device storage is unavailable. Records will not be saved.'); /* ---------- PWA: offline banner, install prompt, service worker (Item 9) ---------- */ (function(){ const netBanner=document.getElementById('netBanner'); function paintNet(){ netBanner.classList.toggle('hidden',navigator.onLine); } window.addEventListener('online',paintNet); window.addEventListener('offline',paintNet); paintNet(); let deferredPrompt=null; window.addEventListener('beforeinstallprompt',e=>{ e.preventDefault(); deferredPrompt=e; try{ if(localStorage.getItem('provenance.install.dismissed')) return; }catch(_){} if(document.getElementById('installBanner')) return; const b=document.createElement('div'); b.className='installbanner'; b.id='installBanner'; b.innerHTML=`
Install ProvenanceAdd it to the home screen for full-screen dock use.
`; document.body.appendChild(b); document.getElementById('instYes').onclick=async()=>{ b.remove(); if(deferredPrompt){ deferredPrompt.prompt(); try{ await deferredPrompt.userChoice; }catch(_){} deferredPrompt=null; } }; document.getElementById('instNo').onclick=()=>{ try{ localStorage.setItem('provenance.install.dismissed','1'); }catch(_){} b.remove(); }; }); if('serviceWorker' in navigator&&/^https?:$/.test(location.protocol)){ window.addEventListener('load',()=>{ navigator.serviceWorker.register('sw.js').catch(()=>{}); }); } })(); /* ---- sync bridge (consumed by sync.js; local-first, sync never blocks UI) ---- */ window.__provenance = { getS: () => DB, /* Loud persist: on quota the blocking sheet opens, nothing fails silently. * The old silent saveLocal() was removed; every write must be audible. */ save: () => save(), refresh: () => render() }; /* device sync entry point (topbar button) */ document.getElementById('btnSync').innerHTML = IC.layers; document.getElementById('btnSync').onclick = () => { openSheet('

Device sync

Same key on phone + laptop = same records.

'+storageMeter() +'

Privacy policy

'); refreshStorageInfo(); if (window.__provenanceSyncUI) window.__provenanceSyncUI(); };