@@ -395,6 +439,54 @@ async function enrichEntity(kind, id){
if(target) target.innerHTML = html;
}
+function enrichSelectAll(kind, id, on){
+ const tbody = document.getElementById('enrich-diff-'+kind+'-'+id);
+ if(!tbody) return;
+ tbody.querySelectorAll('input[type=checkbox]').forEach(cb => { cb.checked = !!on; });
+}
+
+async function enrichApply(kind, id){
+ const target = document.getElementById('enrich-out-'+kind+'-'+id);
+ const tbody = document.getElementById('enrich-diff-'+kind+'-'+id);
+ const preview = (window._enrichPreviews||{})[kind+':'+id];
+ if(!preview){ alert('Prvo pokreni "▶ Pokreni"'); return; }
+ const proposed = preview.proposed || {};
+ const fields = {};
+ if(tbody){
+ tbody.querySelectorAll('input[type=checkbox]:checked').forEach(cb => {
+ const f = cb.getAttribute('data-field');
+ if(f && proposed[f] !== undefined) fields[f] = proposed[f];
+ });
+ } else {
+ Object.assign(fields, proposed);
+ }
+ if(!Object.keys(fields).length){ alert('Označi barem jedno polje za primjenu.'); return; }
+ if(target) target.innerHTML = '
⏳ Spremam u bazu…
';
+ try{
+ const r = await fetch(API+'/v2/enrich/'+kind+'/'+id+'/apply', {
+ method:'POST',
+ headers:{'Content-Type':'application/json'},
+ body: JSON.stringify({fields, sources: preview.sources || []}),
+ });
+ const data = await r.json();
+ if(!r.ok){ throw new Error(data.detail || ('HTTP '+r.status)); }
+ // Refresh the entire detail panel so the new values render
+ if(kind === 'klub' && typeof openKlub === 'function') await openKlub(id);
+ else if(kind === 'savez' && typeof openSavez === 'function') await openSavez(id);
+ else if(kind === 'sportas' && typeof openSportas === 'function') await openSportas(id);
+ setTimeout(() => enrichEntity(kind, id), 350);
+ const cnt = Object.keys(data.applied||{}).length;
+ const t = document.createElement('div');
+ t.style.cssText = 'position:fixed;bottom:20px;right:20px;background:var(--ok,#1ec773);color:#0b1a16;padding:10px 16px;border-radius:6px;font-weight:700;z-index:9999;box-shadow:0 4px 16px rgba(0,0,0,.4)';
+ t.textContent = '✓ Spremljeno '+cnt+' polja u bazu';
+ document.body.appendChild(t);
+ setTimeout(()=>t.remove(), 3500);
+ }catch(e){
+ console.error(e);
+ if(target) target.innerHTML = '
Greška pri spremanju: '+esc(e.message||String(e))+'
';
+ }
+}
+
function enrichBlock(kind, id){
return `