brendmanager/public/opportunities.html
2026-11-16 10:51:07 +05:00

83 lines
8.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>PR-возможности</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:6px;max-width:460px;margin-top:16px}#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="/">← На главную</a></p>
<h1>PR-возможности</h1>
<p>Только возможности, которые Татьяна нашла и ведёт сама. Без рассылок, покупки баз контактов и продаж.</p>
<div>Стадия: <select id="filter"></select> <span id="err"></span></div>
<table id="list"></table>
<form id="f"><input type="hidden" id="id">
<input id="title" placeholder="Название мероприятия *"><input id="organizer" placeholder="Организатор">
<label>Дедлайн <input type="date" id="deadline"></label><input id="topic" placeholder="Тема выступления">
<select id="stage"></select><input id="nextStep" placeholder="Следующий шаг"><select id="type"></select>
<input id="url" placeholder="Ссылка на мероприятие"><input id="email" type="email" data-ph="card.email"><textarea id="notes" placeholder="Заметки"></textarea>
<div><button>Сохранить</button> <button type="button" id="del" hidden>Удалить</button> <button type="button" id="new">Новая</button> <button type="button" id="prep" hidden data-t="letter.prepare"></button></div></form>
<p id="lmsg" role="alert"></p>
<section id="letter" hidden>
<h2 data-t="letter.heading"></h2><p id="lintro" data-t="letter.intro"></p>
<div><span data-t="letter.stage"></span>: <span id="lstage"></span></div>
<div><span data-t="letter.to"></span>: <b id="lto"></b></div>
<label><span data-t="letter.subject"></span><input id="lsubject"></label>
<label><span data-t="letter.body"></span><textarea id="lbody"></textarea></label>
<p id="lhint"></p>
<label id="lcodebox"><span id="lcodehint"></span><input id="lcode" type="password" autocomplete="off" data-ph="letter.code"></label>
<div><button type="button" id="lsave" data-t="letter.save"></button> <button type="button" id="lapprove" data-t="letter.approve"></button>
<button type="button" id="lsend" data-t="letter.send"></button> <button type="button" id="lcopy" data-t="letter.copy"></button>
<button type="button" id="lmark" data-t="letter.markSent"></button></div>
</section>
<script>
let META,ITEMS=[];const $=id=>document.getElementById(id);
const esc=s=>String(s??"").replace(/[&<>"']/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[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")||navigator.language||"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;$("letter").hidden=!L;if(L){$("lsubject").value=L.subject;$("lbody").value=L.body}paint()}
function paint(){if(!L)return;const sent=L.status==="sent",ok=L.status==="approved"&&!DIRTY;
$("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;
$("lsend").hidden=$("lmark").hidden=$("lcodebox").hidden=sent;$("lsend").disabled=$("lmark").disabled=!ok;$("lcopy").disabled=!(ok||sent);
$("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><th>Название</th><th>Организатор</th><th>Дедлайн</th><th>Стадия</th><th>Следующий шаг</th></tr>"+
(ITEMS.map(o=>`<tr class="row ${o.overdue?"overdue":""}" data-id="${o.id}"><td>${esc(o.title)}</td><td>${esc(o.organizer)}</td><td>${esc(o.deadline||"—")}${o.overdue?" (просрочено)":""}</td><td>${esc(o.stage)}</td><td>${esc(o.nextStep)}</td></tr>`).join("")||"<tr><td colspan=5><i>пусто</i></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}
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("Удалить карточку окончательно?")&&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()}};
api("GET","/api/texts").then(d=>{if(!d)return;T=d.texts;LANG=d.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)});
api("GET","/api/opportunities/meta").then(m=>{META=m;
$("filter").innerHTML='<option value="">Все</option>'+m.stages.map(s=>`<option>${esc(s)}</option>`).join("");
$("stage").innerHTML=m.stages.map(s=>`<option>${esc(s)}</option>`).join("");
$("type").innerHTML='<option value="">—</option>'+m.types.map(s=>`<option>${esc(s)}</option>`).join("");fill(null);load()});
</script></body></html>