22 lines
8.3 KiB
JavaScript
22 lines
8.3 KiB
JavaScript
import {canAwardCrysknife} from './panel-layout.mjs';
|
|
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
|
const dashboard=document.getElementById('dashboard'),nav=dashboard?.querySelector('nav');
|
|
const section=el('section');section.id='crysknife';section.hidden=true;
|
|
const hero=el('header');hero.className='cp-user-page-hero order-hero';const seal=el('img');seal.src='https://www.dunerealms.com/assets/seals/order-crysknife-v1.png';seal.alt='Holy Order of the Crysknife seal';seal.width=128;seal.height=128;const intro=el('div');intro.append(el('small','DUNEREALMS · HONOUR & SERVICE'),el('h2','Order of the Crysknife'),el('p','Recognise someone whose dedication has made a lasting difference to our community.'));hero.append(seal,intro);
|
|
const form=el('form');form.className='order-award-card';const cardTitle=el('div');cardTitle.className='order-card-heading';cardTitle.append(el('small','A RECOGNITION THAT LASTS'),el('h3','Bestow the Crysknife'),el('p','Choose the recipient, tell their story and confirm the honour.'));form.append(cardTitle);const recipientLabel=el('label','01 · Choose a recipient'),select=el('select');select.required=true;select.name='recipient';recipientLabel.append(select);
|
|
const citationLabel=el('label','02 · Honour citation'),citation=el('textarea');citation.name='citation';citation.required=true;citation.maxLength=2000;citation.placeholder='Describe their contribution and why they deserve this honour.';citationLabel.append(citation,el('small','Up to 2,000 characters and 20 lines. This citation appears with their honour.'));
|
|
const confirmLabel=el('label'),confirm=el('input');confirm.type='checkbox';confirm.required=true;confirmLabel.className='order-confirm';confirmLabel.append(confirm,el('span','Are you sure? I confirm this person should receive the Crysknife and this citation is ready.'));
|
|
const submit=el('button','Award the Crysknife');submit.className='order-award-button';submit.type='submit';const status=el('p');status.role='status';status.setAttribute('aria-live','polite');status.className='order-status';form.append(recipientLabel,citationLabel,confirmLabel,submit);section.append(hero,el('p','Only unimatrix, unimatrix999, grmacken and current members of the Order can award this honour. Existing recipients are excluded.'),form,status);dashboard?.append(section);const link=el('a','Order of the Crysknife');link.href='#crysknife';nav?.append(link);
|
|
const lore=el('aside');lore.className='order-lore-card';const loreText=el('div');loreText.append(el('small','WORDS FROM THE DEEP DESERT'),el('h3','A blade. A bond. A legacy.'),el('p','A crysknife carries the memory of the deep desert. In our Order, its meaning is service: standing beside the community, keeping faith through difficult seasons, and leaving something worthy for those who follow.'),el('small','DuneRealms Order lore'));const portrait=el('figure');portrait.className='order-stilgar';const face=el('img');face.src='https://www.dunerealms.com/assets/stilgar-portrait-v1.png';face.alt='Minecraft-style portrait of Stilgar';face.width=240;face.height=240;const quote=el('blockquote','“As written!”'),caption=el('figcaption','Stilgar · Dune: Part Two');portrait.append(face,quote,caption);lore.append(loreText,portrait);hero.after(lore);
|
|
const hall=el('section');hall.className='order-hall';hall.setAttribute('aria-label','Crysknife Hall of Fame');
|
|
const hallBanner=el('header');hallBanner.className='order-hall-banner';const hallHeading=el('div');hallHeading.append(el('small','THE IMPERIAL REGISTER OF HONOUR'),el('h3','Hall of Fame'),el('p','The names endure. The desert remembers.'));hallBanner.append(hallHeading);
|
|
for(const side of ['left','right']){const standard=el('div');standard.className='order-standard order-standard-'+side;const emblem=el('img');emblem.src='https://www.dunerealms.com/assets/seals/order-crysknife-v1.png';emblem.alt='';emblem.width=64;emblem.height=64;standard.append(emblem,el('span','✦'));hallBanner.append(standard);}
|
|
const hallBody=el('div');hallBody.className='order-hall-body';const hallTitle=el('div');hallTitle.className='order-hall-title';hallTitle.append(el('span','◆ ━━━━━ ✦ ━━━━━ ◆'),el('h4','Recipients'),el('p','Honoured members of the Holy Order of the Crysknife'));
|
|
const hallGrid=el('div');hallGrid.className='order-recipient-grid';const hallStatus=el('p');hallStatus.role='status';const hallPages=el('nav');hallPages.className='order-hall-pages';hallPages.setAttribute('aria-label','Recipient pages');hallBody.append(hallTitle,hallGrid,hallStatus,hallPages);hall.append(hallBanner,hallBody);section.append(hall);let hallSerial=0;
|
|
async function loadRecipients(page=1){if(!canAwardCrysknife(currentUser))return;const n=++hallSerial;hallStatus.textContent='Opening the register…';try{const r=await fetch('/api/ranks/honour?recipients=1&page='+page,{cache:'no-store'}),d=await r.json();if(!r.ok)throw Error(d.message||'The register could not be loaded.');if(n!==hallSerial)return;hallGrid.replaceChildren();for(const member of d.recipients){const card=el('article');card.className='order-recipient-card';const portrait=el('div');portrait.className='order-recipient-portrait';const face=el('span');face.className=member.skin?'order-member-skin':'order-member-avatar';face.setAttribute('role','img');face.setAttribute('aria-label',member.username+' Minecraft avatar');const skin=el('img');skin.src=member.avatar;skin.alt='';skin.width=64;skin.height=64;face.append(skin);if(member.skin){const hat=skin.cloneNode();hat.className='order-member-hat';face.append(hat);}const badge=el('img');badge.className='order-member-seal';badge.src='https://www.dunerealms.com/assets/seals/order-crysknife-v1.png';badge.alt='Crysknife recipient';badge.width=34;badge.height=34;portrait.append(face,badge);const info=el('div');info.className='order-recipient-copy';info.append(el('small','HOLY ORDER'),el('h5',member.username));const profile=el('a','View profile & honours →');profile.href=member.profile;info.append(profile);card.append(portrait,info);hallGrid.append(card);}hallPages.replaceChildren();if(d.pages>1){for(const[label,to]of [['← Previous',page-1],['Next →',page+1]]){const b=el('button',label);b.type='button';b.disabled=to<1||to>d.pages;b.onclick=()=>loadRecipients(to);hallPages.append(b);}hallPages.insertBefore(el('span','Page '+page+' of '+d.pages),hallPages.lastChild);}hallStatus.textContent=d.total?d.total+' honoured '+(d.total===1?'recipient':'recipients'):'The register is awaiting its first recipient.';}catch(e){if(n===hallSerial)hallStatus.textContent=e.message;}}
|
|
let currentUser=null,serial=0,busy=false;
|
|
async function load(){if(!canAwardCrysknife(currentUser))return;loadRecipients();const n=++serial;submit.disabled=true;select.disabled=true;try{const r=await fetch('/api/ranks/honour?candidates=1',{cache:'no-store'}),d=await r.json();if(!r.ok)throw Error(d.message||'Could not load recipients.');if(n!==serial)return;select.replaceChildren();const placeholder=el('option','Choose a recipient');placeholder.value='';select.append(placeholder);for(const row of d.candidates){const option=el('option',row.username);option.value=row.id;select.append(option);}select.disabled=!d.candidates.length;submit.disabled=!d.candidates.length;if(!d.candidates.length)status.textContent='There are no eligible non-recipients.';}catch(e){if(n===serial)status.textContent=e.message;}}
|
|
form.addEventListener('submit',async e=>{e.preventDefault();if(busy||!form.reportValidity())return;busy=true;submit.disabled=true;status.textContent='Saving the award…';try{const r=await fetch('/api/ranks/honour',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'award',userId:select.value,citation:citation.value,confirmed:confirm.checked})}),d=await r.json();if(!r.ok)throw Error(d.message||'The award could not be saved.');form.reset();await load();status.textContent=d.message;}catch(e){status.textContent=e.message;submit.disabled=false;}finally{busy=false;}});
|
|
function session(user){currentUser=user;serial++;section.hidden=!canAwardCrysknife(user);form.hidden=!canAwardCrysknife(user);if(location.hash==='#crysknife')load();}
|
|
window.addEventListener('dune:session',e=>session(e.detail));window.addEventListener('dune:page',e=>{if(e.detail?.page==='crysknife')load();});
|
|
try{const r=await fetch('/api/auth/session',{cache:'no-store'});if(r.ok)session((await r.json()).user);}catch{}
|

Staff