105 lines
11 KiB
HTML
105 lines
11 KiB
HTML
<!doctype html>
|
|
<html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title data-t="ui.opp.title"></title>
|
|
<style>
|
|
body{font:15px system-ui,sans-serif;margin:0;padding:16px;max-width:1100px;margin:auto;color:#222}
|
|
h1{font-size:20px}table{border-collapse:collapse;width:100%}td,th{border:1px solid #ddd;padding:4px 8px;text-align:left}
|
|
tr.overdue{background:#ffe3e0}tr.row{cursor:pointer}form{display:grid;gap:8px;max-width:460px}h2{font-size:16px;margin-top:24px}
|
|
label{display:grid;gap:2px}label>span{font-size:13px;color:#555}.none{color:#555;font-style:italic}input,select,textarea,button{font:inherit}button:disabled{color:#888;background:#eee;border:1px solid #ccc;cursor:not-allowed}.lbtn{display:flex;gap:8px;align-items:baseline;margin:6px 0}.lbtn small{color:#555}.hint{font-size:13px;color:#555}
|
|
#err,#lmsg{color:#b00}
|
|
#letter{max-width:640px;margin-top:16px;padding:12px;border:1px solid #ddd;border-radius:6px;display:grid;gap:8px}
|
|
#letter[hidden]{display:none}#letter h2{font-size:17px;margin:0}#letter textarea{min-height:240px;font:inherit}
|
|
#letter input,#letter textarea{width:100%;box-sizing:border-box}#lstage{font-weight:600}#lhint{color:#555}
|
|
</style></head><body>
|
|
<p><a href="/" data-t="ui.common.home"></a></p>
|
|
<h1 data-t="ui.opp.title"></h1>
|
|
<p data-t="ui.opp.intro"></p>
|
|
<label style="max-width:460px;margin-bottom:8px"><span data-t="ui.opp.filter"></span><select id="filter" data-tip="ui.opp.filterTip"></select></label>
|
|
<p id="err" role="alert"></p>
|
|
<table id="list"></table>
|
|
<h2 id="hForm" data-t="ui.opp.hNew"></h2>
|
|
<form id="f"><input type="hidden" id="id">
|
|
<label><span data-t="ui.opp.f.title"></span><input id="title" data-ph="ui.opp.f.titlePh" aria-required="true"></label>
|
|
<label><span data-t="ui.opp.f.organizer"></span><input id="organizer" data-ph="ui.opp.f.organizerPh"></label>
|
|
<label><span data-t="ui.opp.f.deadline"></span><input type="date" id="deadline" data-tip="ui.opp.f.deadlineTip"></label>
|
|
<label><span data-t="ui.opp.f.topic"></span><input id="topic" data-ph="ui.opp.f.topicPh"></label>
|
|
<label><span data-t="ui.opp.f.stage"></span><select id="stage" data-tip="ui.opp.f.stageTip"></select></label>
|
|
<label><span data-t="ui.opp.f.next"></span><input id="nextStep" data-ph="ui.opp.f.nextPh"></label>
|
|
<label><span data-t="ui.opp.f.type"></span><select id="type" data-tip="ui.opp.f.typeTip"></select></label>
|
|
<label><span data-t="ui.opp.f.url"></span><input id="url" type="url" data-ph="ui.opp.f.urlPh"></label>
|
|
<label><span data-t="card.email"></span><input id="email" type="email" data-ph="ui.opp.f.emailPh"></label>
|
|
<label><span data-t="ui.opp.f.notes"></span><textarea id="notes" data-ph="ui.opp.f.notesPh"></textarea></label>
|
|
<div><button data-t="ui.opp.save" data-tip="ui.opp.saveTip"></button> <button type="button" id="del" hidden data-t="ui.opp.del" data-tip="ui.opp.delTip"></button> <button type="button" id="new" data-t="ui.opp.clear" data-tip="ui.opp.clearTip"></button> <button type="button" id="prep" hidden data-t="letter.prepare" data-tip="ui.opp.prepTip"></button></div></form>
|
|
<section id="letter">
|
|
<h2 data-t="letter.heading"></h2><p id="lpick" data-t="letter.pick"></p><p id="lintro" data-t="letter.intro" hidden></p>
|
|
<div id="lstagebox" hidden><span id="lstagel"></span><span id="lstage"></span></div>
|
|
<div id="ltobox" hidden><span id="ltol"></span><b id="lto"></b></div>
|
|
<div id="lform" hidden>
|
|
<label><span data-t="letter.subjectReq"></span><input id="lsubject" data-ph="letter.subjectPh" aria-required="true"></label>
|
|
<label><span data-t="letter.bodyReq"></span><textarea id="lbody" data-ph="letter.bodyPh" aria-required="true"></textarea></label>
|
|
<p id="lhint"></p>
|
|
<p id="lcodehint"></p>
|
|
<label id="lcodebox"><span data-t="letter.code"></span><input id="lcode" type="password" autocomplete="off" data-ph="letter.codePh" aria-describedby="lcodehint lmsg"></label>
|
|
<p id="lmsg" role="alert"></p>
|
|
</div>
|
|
<div><button type="button" id="lsave" data-t="letter.save"></button> <button type="button" id="lapprove" disabled data-t="letter.approve"></button> <small id="lapprn" data-t="letter.btnWhy.pick"></small></div>
|
|
<p id="lwhy" class="hint" role="status"></p>
|
|
<div class="lbtn"><button type="button" id="lsend" disabled data-t="letter.send"></button><small id="lsendn" data-t="letter.btnWhy.pick"></small></div>
|
|
<div class="lbtn"><button type="button" id="lcopy" disabled data-t="letter.copy"></button><small id="lcopyn" data-t="letter.btnWhy.pick"></small></div>
|
|
<div class="lbtn"><button type="button" id="lmark" disabled aria-disabled="true" data-t="letter.markSent"></button><small id="lmarkn" data-t="letter.btnWhy.approve"></small></div>
|
|
</section>
|
|
<script>
|
|
let META,ITEMS=[];const $=id=>document.getElementById(id);
|
|
const esc=s=>String(s??"").replace(/[&<>"']/g,c=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
|
|
const F=["title","organizer","deadline","topic","stage","nextStep","type","url","notes","email"];
|
|
let T={},LANG="ru",L=null,DIRTY=false,CODESET=false;
|
|
const WANT=new URLSearchParams(location.search).get("lang")||"ru";
|
|
const t=(k,v={})=>(T[k]??"").replace(/\{(\w+)\}/g,(_,n)=>v[n]??"");
|
|
async function api(m,u,b){const r=await fetch(u,{method:m,headers:{"content-type":"application/json","x-lang":WANT},body:b&&JSON.stringify(b)});
|
|
const d=await r.json();$(u.includes("/letter")?"lmsg":"err").textContent=r.ok?"":d.error;return r.ok?d:null}
|
|
const when=s=>new Date(s).toLocaleString(LANG,{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"});
|
|
function showLetter(d){L=d&&d.letter;DIRTY=false;if(d)CODESET=d.codeSet;if(L){$("lsubject").value=L.subject;$("lbody").value=L.body}paint()}
|
|
function paintEmpty(){for(const k of["lstagel","lstage","ltol","lto"])$(k).textContent="";$("lpick").hidden=false;for(const k of["lintro","lstagebox","ltobox","lform","lsave","lmark"])$(k).hidden=true;$("lmark").parentElement.hidden=true;$("lhint").textContent=$("lwhy").textContent="";
|
|
$("lapprove").hidden=false;$("lapprove").disabled=true;$("lapprn").textContent=t("letter.btnWhy.pick");for(const k of["lsend","lcopy"]){$(k).parentElement.hidden=false;$(k).hidden=false;$(k).disabled=true;$(k+"n").textContent=t("letter.btnWhy.pick")}
|
|
$("lcodebox").hidden=$("lcodehint").hidden=true}
|
|
function paint(){if(!L)return paintEmpty();$("lpick").hidden=true;$("lform").hidden=false;$("lstagebox").hidden=!L.status;$("ltobox").hidden=!L.to;$("lmark").parentElement.hidden=false;const sent=L.status==="sent",ok=L.status==="approved"&&!DIRTY;
|
|
$("lstagel").textContent=L.status?t("letter.stage")+": ":"";$("ltol").textContent=L.to?t("letter.to")+": ":"";$("lto").textContent=L.to;$("lsubject").readOnly=$("lbody").readOnly=sent;
|
|
$("lstage").textContent=t("stage."+L.status)+(L.sentAt?" · "+when(L.sentAt)+" ("+t("letter.approvedAt",{when:when(L.approvedAt)})+")":L.approvedAt?" · "+when(L.approvedAt):"");
|
|
$("lintro").hidden=sent;
|
|
$("lhint").textContent=DIRTY?t("letter.unsaved"):t(sent?"letter.hintSent":ok?"letter.hintApproved":"letter.hintDraft");
|
|
$("lsave").hidden=sent;$("lsave").disabled=!DIRTY;$("lapprove").hidden=L.status!=="draft";$("lapprove").disabled=DIRTY;$("lapprn").textContent=DIRTY?t("letter.btnWhy.save"):"";
|
|
$("lsend").hidden=$("lmark").hidden=$("lcodebox").hidden=$("lcodehint").hidden=sent;$("lsend").disabled=$("lmark").disabled=!ok;$("lcopy").disabled=!(ok||sent);
|
|
$("lwhy").textContent=sent?"":DIRTY?t("letter.why.dirty"):L.status==="draft"?t("letter.why.draft"):"";
|
|
for(const k of["lsend","lmark","lcopy"]){$(k).parentElement.hidden=sent;const off=$(k).disabled;$(k+"n").textContent=off?t(DIRTY?"letter.btnWhy.save":"letter.btnWhy.approve"):t("letter."+{lsend:"sendNote",lcopy:"copyNote",lmark:"markNote"}[k])}
|
|
$("lcodehint").textContent=t(CODESET?"letter.codeHint":"letter.codeHintNew")}
|
|
const lurl=()=>"/api/opportunities/"+$("id").value+"/letter";
|
|
for(const k of["lsubject","lbody"])$(k).oninput=()=>{if(L&&L.status!=="sent"){DIRTY=true;paint()}};
|
|
addEventListener("beforeunload",e=>{if(DIRTY){e.preventDefault();e.returnValue=""}});
|
|
$("prep").onclick=async()=>{const d=await api("POST",lurl());if(d){showLetter(d);$("letter").scrollIntoView({behavior:"smooth"})}};
|
|
$("lsave").onclick=async()=>{const d=await api("PUT",lurl(),{subject:$("lsubject").value,body:$("lbody").value});if(d){showLetter(d);$("lhint").textContent=t("letter.saved")}};
|
|
$("lapprove").onclick=async()=>{const d=await api("POST",lurl()+"/approve",{code:$("lcode").value,subject:L.subject,body:L.body});if(d)showLetter(d)};
|
|
$("lsend").onclick=()=>{if(L&&L.mailto)location.href=L.mailto};
|
|
$("lcopy").onclick=async()=>{try{await navigator.clipboard.writeText(L.subject+"\n\n"+L.body)}catch{$("lbody").select();document.execCommand("copy")}$("lhint").textContent=t("letter.copied")};
|
|
$("lmark").onclick=async()=>{const d=await api("POST",lurl()+"/sent",{code:$("lcode").value});if(d)showLetter(d)};
|
|
async function load(){const d=await api("GET","/api/opportunities?stage="+encodeURIComponent($("filter").value));if(d){ITEMS=d.items;render()}}
|
|
function render(){$("list").innerHTML="<tr>"+["title","organizer","deadline","stage","next"].map(k=>`<th>${esc(t("ui.opp.col."+k))}</th>`).join("")+"</tr>"+
|
|
(ITEMS.map(o=>`<tr class="row ${o.overdue?"overdue":""}" data-id="${o.id}" title="${esc(t("ui.opp.rowTip"))}"><td>${esc(o.title)}</td><td>${esc(o.organizer)}</td><td>${esc(o.deadline||"—")}${o.overdue?" ("+esc(t("ui.opp.overdue"))+")":""}</td><td>${esc(t("ui.opp.stage."+META.stages.indexOf(o.stage))||o.stage)}</td><td>${esc(o.nextStep)}</td></tr>`).join("")||`<tr><td colspan=5 class="none">${esc(t($("filter").value?"ui.opp.filterEmpty":"ui.opp.empty"))}</td></tr>`)}
|
|
function fill(o){if(DIRTY&&!confirm(t("letter.confirmLeave")))return;showLetter(null);$("lmsg").textContent="";$("prep").hidden=!o;
|
|
if(o)api("GET","/api/opportunities/"+o.id+"/letter").then(d=>{if(d&&$("id").value==o.id){CODESET=d.codeSet;if(d.letter)showLetter(d)}});
|
|
$("id").value=o?o.id:"";for(const k of F)$(k).value=o?(o[k]??""):(k==="stage"?META.stages[0]:"");$("del").hidden=!o;$("hForm").textContent=t(o?"ui.opp.hEdit":"ui.opp.hNew")}
|
|
document.addEventListener("click",e=>{const r=e.target.closest("tr.row");if(r)fill(ITEMS.find(o=>o.id==r.dataset.id))});
|
|
$("new").onclick=()=>fill(null);$("filter").onchange=load;
|
|
$("del").onclick=async()=>{if(confirm(t("ui.opp.confirmDelete"))&&await api("DELETE","/api/opportunities/"+$("id").value)){fill(null);load()}};
|
|
$("f").onsubmit=async e=>{e.preventDefault();const b={};for(const k of F)b[k]=$(k).value;b.deadline=b.deadline||null;
|
|
const id=$("id").value;if(await(id?api("PUT","/api/opportunities/"+id,b):api("POST","/api/opportunities",b))){fill(null);load()}};
|
|
Promise.all([api("GET","/api/texts"),api("GET","/api/opportunities/meta")]).then(([d,m])=>{if(!d||!m)return;T=d.texts;LANG=d.lang;META=m;paint();
|
|
document.title=t("ui.opp.title");document.documentElement.lang=LANG;
|
|
for(const e of document.querySelectorAll("[data-t]"))e.textContent=t(e.dataset.t);
|
|
for(const e of document.querySelectorAll("[data-ph]"))e.placeholder=t(e.dataset.ph);
|
|
for(const e of document.querySelectorAll("[data-tip]"))e.title=t(e.dataset.tip);
|
|
const opt=(p,l)=>l.map((s,i)=>`<option value="${esc(s)}">${esc(t(p+i)||s)}</option>`).join("");
|
|
$("filter").innerHTML=`<option value="">${esc(t("ui.opp.all"))}</option>`+opt("ui.opp.stage.",m.stages);
|
|
$("stage").innerHTML=opt("ui.opp.stage.",m.stages);
|
|
$("type").innerHTML=`<option value="">${esc(t("ui.opp.typeNone"))}</option>`+opt("ui.opp.type.",m.types);fill(null);load()});
|
|
</script></body></html>
|