forked from unimatrix/web
1 line
No EOL
3.5 KiB
JavaScript
1 line
No EOL
3.5 KiB
JavaScript
const API='/api/staff/roster';const SEAL_BASE='/assets/seals/';const DEPT_SEALS={development:'team-dev-150.png',operations:'department-network-staff-150.png',community_moderation:'department-forum-support-150.png',administration:'department-sales-150.png'};const TEAM_SEALS={dev:'department-dev-150.png','network-staff':'department-network-staff-150.png',support:'department-support-150.png','ban-appeals':'department-ban-appeals-150.png','forum-support':'department-forum-support-150.png',legal:'department-legal-v2-150.png',sales:'department-sales-150.png'};const rankNames={owner:'Owner',director:'Network Director',head:'Department Head',senior:'Senior Staff',staff:'Staff',trainee:'Trainee'};const el=(tag,cls,text)=>{const n=document.createElement(tag);if(cls)n.className=cls;if(text!=null)n.textContent=text;return n};const safeName=v=>typeof v==='string'&&/^[a-z0-9_]{3,32}$/.test(v);function seal(file,label){const wrap=el('span','bureau-seal');const image=el('img');image.src=SEAL_BASE+file;image.alt=label+' seal';image.loading='lazy';image.onerror=()=>{image.hidden=true};wrap.append(image);return wrap}function staffCard(person){const card=el('article','bureau-member');const name=el(safeName(person.username)?'a':'span','bureau-name',person.displayName||person.username||'Staff member');if(safeName(person.username))name.href='/people/'+encodeURIComponent(person.username);card.append(name,el('span','bureau-rank',rankNames[person.rank]||person.rank||'Staff'));if(person.subteam)card.append(el('span','bureau-subteam',person.subteam));const marks=el('div','bureau-member-seals');if(person.subteam){const match=Object.entries(TEAM_SEALS).find(([key])=>key===person.subteamKey);if(match)marks.append(seal(match[1],person.subteam))}for(const award of Array.isArray(person.seals)?person.seals:[]){if(award&&typeof award.file==='string'&&/^[a-z0-9_-]+\.png$/.test(award.file))marks.append(seal(award.file,award.label||'Award'))}if(person.crysknife===true)marks.append(seal('order-crysknife-v1.png','Order of the Crysknife'));if(marks.childElementCount)card.append(marks);return card}async function start(){const status=document.getElementById('staff-roster-status'),all=document.getElementById('staff-all'),departments=document.getElementById('staff-departments');try{const response=await fetch(API,{headers:{Accept:'application/json'}});if(!response.ok)throw Error('Roster API '+response.status);const data=await response.json();if(!Array.isArray(data.groups))throw Error('Invalid roster');let total=0;for(const group of data.groups){const section=el('section','bureau-department');section.append(el('h3','',group.label));const banner=el('div','bureau-dept-banner');if(DEPT_SEALS[group.key])banner.append(seal(DEPT_SEALS[group.key],group.label));banner.append(el('p','',group.subteams.map(t=>t.name).join(' · ')));section.append(banner);const cards=el('div','bureau-cards');for(const person of group.staff||[]){total++;const card=staffCard(person);cards.append(card);all.append(staffCard(person))}if(!cards.childElementCount)cards.append(el('p','bureau-empty','No public staff appointments listed yet.'));section.append(cards);departments.append(section)}status.textContent=total?total+' published staff member'+(total===1?'':'s')+' in the roster.':'No staff profiles have been approved for public listing yet.';if(!total)all.append(el('p','bureau-empty','The roster will populate when staff profiles are published.'))}catch{status.textContent='The staff roster is temporarily unavailable. Please use the support links below.'}}start(); |

Staff