/* ===== crm5x: мой статус на отклике + фильтр/сортировка "требует ответа" ===== */ (function(){ var MYST=["Новый","В работе","Жду ответа","Созвон","Тестовое","Оффер","Отказ","Заморожен"]; var TERM={"Отказ":1,"Оффер":1,"Отозвано":1,"Заморожен":1,"Клиент":1}; if(!window.__appFilter)window.__appFilter="all"; function ds(d){ try{ return (typeof daysSince==="function")?daysSince(d):0; }catch(e){ return 0; } } function needsReply(a){ return /ответ получен|приглаш|созвон|интервью|оффер|коммерческое|предложение/i.test(a.status||""); } function isStale(a){ return ds(a.date)>=5 && !TERM[a.status] && !TERM[a.mystatus]; } function inWork(a){ return /в работе|созвон|тестов/i.test(a.mystatus||""); } function passFilter(a){ var f=window.__appFilter; if(f==="reply")return needsReply(a); if(f==="stale")return isStale(a); if(f==="work")return inWork(a); return true; } function prio(a){ if(needsReply(a))return 0; if(isStale(a))return 1; if(TERM[a.status]||TERM[a.mystatus])return 3; return 2; } function chip(id,label,n){ var on=window.__appFilter===id; return ''; } window.appSetFilter=function(f){ window.__appFilter=f; try{renderList("applies");}catch(e){} }; var _rl=window.renderList; window.renderList=function(coll){ if(coll!=="applies"||typeof _rl!=="function"){ return _rl?_rl(coll):undefined; } var q=(SEARCH.applies||"").toLowerCase(); var all=db.applies.filter(function(r){return !q||JSON.stringify(r).toLowerCase().indexOf(q)>=0;}); var nR=all.filter(needsReply).length, nS=all.filter(isStale).length, nW=all.filter(inWork).length; var rows=all.filter(passFilter).slice().sort(function(a,b){ var pa=prio(a),pb=prio(b); if(pa!==pb)return pa-pb; return (b.date||"").localeCompare(a.date||""); }); var el=document.getElementById("list"), cnt=document.getElementById("cnt"); if(cnt)cnt.textContent=rows.length+" из "+db.applies.length; var bar='
'+chip("all","Все",all.length)+chip("reply","Требует ответа",nR)+chip("stale","Зависли",nS)+chip("work","В работе",nW)+'
'; if(!rows.length){ el.innerHTML=bar+'
Пусто по этому фильтру.
'; return; } var head='КомпанияВакансияМой статусСтатус hh'; var body=rows.map(function(a){ var col=(typeof stColor==="function")?stColor(a.mystatus||a.status):""; var stale=isStale(a)?' висит '+ds(a.date)+' дн':""; var src=(typeof srcBadge==="function")?srcBadge(a.source||"HH.ru"):""; var my=a.mystatus?''+esc(a.mystatus)+'':''; return ''+ ''+esc(a.company||"—")+''+src+'
'+esc(a.date||"")+stale+'
'+ ''+esc(trim(a.vacancy,46))+''+my+''+esc(a.status||"—")+''; }).join(""); el.innerHTML=bar+''+head+body+'
'; }; var _oe=window.openEdit; if(typeof _oe==="function" && !_oe.__myst){ var wo=function(coll,id){ _oe.call(this,coll,id); if(coll!=="applies")return; setTimeout(function(){ var dlg=document.getElementById("dialog"); if(!dlg||dlg.querySelector("#mystrow"))return; var a=(db.applies||[]).find(function(x){return x.id==id;}); if(!a)return; var opts=MYST.map(function(s){return '';}).join(""); var row=document.createElement("div"); row.id="mystrow"; row.style.cssText="display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:0 0 12px;padding:10px 12px;background:#f6f7fb;border-radius:10px"; row.innerHTML='Мой статус:'+ ''+ 'hh-статус ведётся сам, этот — твой'; dlg.insertBefore(row, dlg.firstChild); var sel=document.getElementById("myst"); if(sel)sel.onchange=function(){ a.mystatus=sel.value; try{save();}catch(e){} try{renderList("applies");}catch(e){} }; },170); }; wo.__myst=1; window.openEdit=wo; } try{ if(typeof TAB!=="undefined" && TAB==="applies" && typeof renderList==="function") renderList("applies"); }catch(e){} })();