forked from unimatrix/web
20 lines
3.4 KiB
JavaScript
20 lines
3.4 KiB
JavaScript
import {createOrganisationNetwork} from '/organisation-network.mjs';
|
||
import {createOrganisationPortraitTree} from '/clan-dynasty.js';
|
||
const registerStyle=document.createElement('link');registerStyle.rel='stylesheet';registerStyle.href='/clans.css';document.head.append(registerStyle);
|
||
import {renderClanRegister} from '/clan-directory-view.mjs';
|
||
import {formatDuneDate} from '/dune-date.js';
|
||
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
|
||
const [route,id]=location.pathname.split('/').filter(Boolean),company=route==='companies',kind=company?'company':'politics',noun=company?'Company':'Political House',host=document.querySelector('#clan-profile'),status=document.querySelector('#clan-status');
|
||
document.body.classList.add(company?'public-company':'public-politics');
|
||
const back=document.querySelector('.public-clan>nav a');back.href='/'+route;back.textContent='← '+noun+' register';
|
||
try{
|
||
const response=await fetch('/api/public/'+route+(id?'/'+encodeURIComponent(id):''),{cache:'no-store',credentials:id?'omit':'same-origin'}),data=await response.json();if(!response.ok)throw Object.assign(Error(data.message||'Register unavailable.'),{status:response.status});
|
||
if(!id){document.title=noun+' Registry | DuneRealms';const search=el('input'),results=el('div');search.type='search';search.placeholder='Search the register…';search.setAttribute('aria-label','Search organisations');host.append(el('h1',noun+' Registry'),search,results);const render=()=>{const q=search.value.toLocaleLowerCase();renderClanRegister(results,data.organisations.filter(r=>[r.name,r.tag,r.owner_name,r.owner_username,r.realm].some(v=>String(v||'').toLocaleLowerCase().includes(q))),{kind});};search.oninput=render;render();}
|
||
else{
|
||
const r=data.organisation;document.title=r.name+' · '+noun+' Register | DuneRealms';
|
||
const hero=createOrganisationPortraitTree(r,{kind});
|
||
const about=el('section',undefined,'public-clan-about');about.append(el('h2',company?'The enterprise':'The institution'),el('p',r.description||'No introduction has been published.'),el('p',r.realm));
|
||
const deed=el('section',undefined,'clan-deed-card'),art=el('div',undefined,'clan-deed-picture'),copy=el('div');art.setAttribute('role','img');art.setAttribute('aria-label',company?'Company register seal':'Protected office seal');art.style.backgroundImage='url(https://cp.dunerealms.com/assets/'+(company?'organisation-deeds-company-tiers-v1.png':'organisation-deeds-protected-v1.png')+')';art.style.backgroundRepeat='no-repeat';art.style.backgroundSize=company?'300% 100%':'200% 100%';art.style.backgroundPosition=company?({original:'center',royal:'right center'}[r.charter_kind]||'left center'):r.tag==='spacing_guild'?'right center':'left center';
|
||
copy.append(el('small',company?'COMMERCIAL REGISTER':'IMPERIAL REGISTER · OFFICE DEED'),el('h2',r.name),el('p',r.standing));if(r.created_at)copy.append(el('p','Est. '+formatDuneDate(Number(r.created_at))));if(r.term)copy.append(el('p','Term: '+formatDuneDate(r.term.startsAt)+' – '+formatDuneDate(r.term.expiresAt)));deed.append(art,copy);host.append(hero);if(company&&r.network)host.append(createOrganisationNetwork(r.network));host.append(about,deed);
|
||
}status.hidden=true;
|
||
}catch(error){status.textContent=error.message;host.replaceChildren();if(error.status===401){const login=el('a','Sign in →');login.href='/login.html?return_to='+encodeURIComponent(location.pathname);host.append(login);}}
|

Staff