web/website/control-panel/public/council-preview.mjs
Dev 6deb4a2e7d DuneRealms V2 clean baseline
Owner-authorised history reset; current source tree preserved exactly.
2026-11-13 00:05:14 +01:00

41 lines
9.3 KiB
JavaScript
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.

import {proclamationBox} from './proclamations-view.mjs';
// UI-only examples: no requests, persisted balances, messages or appointments.
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
const button=text=>{const b=el('button',text);b.type='button';b.disabled=true;return b;};
const note=()=>el('p','DEMO · Fictional records. No money, messages, appointments or rewards are submitted.','politics-demo-note');
function card(title,text){const n=el('article',undefined,'politics-card');n.append(el('h3',title),el('p',text));return n;}
function field(host,label,value,type='text'){const l=el('label',label),f=el(type==='textarea'?'textarea':'input');if(type!=='textarea')f.type=type;f.value=value;l.append(f);host.append(l);return f;}
function confirm(host){const l=el('label',undefined,'politics-accept'),c=el('input');c.type='checkbox';l.append(c,el('span','Are you sure?'));host.append(l);return c;}
function memberSearch(host){const q=field(host,'Search own-faction members','','search'),results=el('select');results.setAttribute('aria-label','Matching demo faction member');const names=['Demo AmberWarden','Demo WaterArchivist','Demo DawnBuilder'];function draw(){results.replaceChildren(el('option','Choose a demo member'));for(const name of names.filter(n=>n.toLowerCase().includes(q.value.toLowerCase()))){const option=el('option',name);option.value=name;results.append(option);}}q.addEventListener('input',draw);draw();host.append(results);return results;}
export function councilPreview(){const root=el('div',undefined,'politics-content');
const appointment=card('Faction Leader Control · Appoint your adviser','House leaders appoint a Mentat; the Reverent Mother appoints a Concord Sister. The appointment expires with the current two-week House term.');appointment.append(note());const form=el('div',undefined,'politics-charter');memberSearch(form);const role=el('label','Office'),select=el('select');select.append(el('option','Mentat'),el('option','Concord Sister'));role.append(select);form.append(role);confirm(form);form.append(button('Appoint adviser — preview only'));appointment.append(form);root.append(appointment);
root.append(proclamationBox('house',{editor:true}));
const bank=card('Faction Bank','Bank controls belong to the active Mentat or Concord Sister. A decorative rank alone grants no banking access.');bank.append(note());const balance=el('div',undefined,'council-balance');balance.append(el('small','DEMO FACTION BALANCE'),el('strong','100,000 Dunemarks'),el('span','Kit income is credited to this bank.'));bank.append(balance);
const actions=el('div',undefined,'politics-grid');for(const kind of ['Donate to member','Deposit','Withdraw']){const form=el('div',undefined,'politics-charter');form.append(el('h4',kind));if(kind==='Donate to member')memberSearch(form);else form.append(el('p',kind==='Deposit'?'Personal bank → faction bank':'Faction bank → personal bank'));const amount=field(form,'Amount in Dunemarks','100','number');amount.min='1';amount.step='1';confirm(form);form.append(button(kind+' — preview only'));actions.append(form);}bank.append(actions);
const transactions=el('ul',undefined,'council-ledger');for(const text of ['+2,500 · Demo faction kit income','+1,000 · Demo personal deposit','−500 · Demo donation to AmberWarden'])transactions.append(el('li',text));bank.append(el('h4','Transaction history · examples'),transactions);root.append(bank);
const kit=card('Faction Kit · Imperial Tailor','One active kit per faction. The Mentat or Concord Sister may publish a replacement with a different, freely chosen name. Existing purchases and receipts remain intact.');kit.append(note());const k=el('div',undefined,'politics-charter');field(k,'New kit name','The Amber Watch');k.append(el('p','Replaces: The Desert Vanguard · demo kit'),button('Edit faction kit — preview only'));kit.append(k);root.append(kit);
const travel=card('Civil War · Guild passage','For the rally camp, war teleport is blocked for three hours. Each House can buy out its own blockade for 15% of its faction bank balance.');travel.append(note(),el('p','Example: 100,000 × 15% = 15,000 Dunemarks. The one-hour per-player war-teleport cooldown still applies.'));confirm(travel);travel.append(button('Pay Guild bribe — preview only'));root.append(travel);return root;}
const messages=[
['System','Elections','Vote received','A demo candidate received a vote. Current top 3: DuneWeaver 84, AmberWarden 79, SandCartographer 74. Voter identity is private.'],
['System','Appointments','Mentat appointed','Demo WaterArchivist has been appointed for the current House term.'],
['System','Rallies','Support received','Demo House Jade supports the rally.'],
['System','War','Imperial approval','Example only: the Emperor supports the proposed declaration.'],
['System','Transport','Blockade active','Example only: rally-camp war teleport blocked for three hours.'],
['System','Faction Bank','Kit income received','Example credit: 2,500 Dunemarks.'],
['System','Faction Kit','Kit replaced','The Amber Watch replaces The Desert Vanguard in this demo.'],
['System','Clan','Invitation received','Demo Clan Lantern has invited you.'],
['System','Rewards','Kit claim available','Example Sardaukar-themed Legendary+ battle kit: armour and weapons. No items are issued.'],
['House','Demo House Amber','Diplomatic proposal','A fictional message from another House.'],
['Clan','Demo Clan Lantern','Community build','A fictional clan message.'],
['User','Demo DawnBuilder','Welcome','A fictional personal message.']
].map(([type,tag,title,body],id)=>({id,type,tag,title,body,read:false,deleted:false}));
const inboxViews=new Set();
export function inboxPreview(){const root=card('Shared inbox','One inbox across Personal CP and Faction Council: User, House, Clan and System. All records below are local examples.');root.append(note());const filters=el('div',undefined,'politics-inbox-filters'),search=el('input'),type=el('select'),tag=el('select');search.type='search';search.placeholder='Search demo messages';search.setAttribute('aria-label','Search demo messages');type.setAttribute('aria-label','Message type');tag.setAttribute('aria-label','System subtag');for(const t of ['All','User','House','Clan','System'])type.append(el('option',t));for(const t of ['All subtags','Elections','Appointments','Rallies','War','Transport','Faction Bank','Faction Kit','Clan','Rewards'])tag.append(el('option',t));filters.append(search,type,tag);root.append(filters);const list=el('div',undefined,'politics-inbox-list');root.append(list);
function draw(){list.replaceChildren();for(const m of messages.filter(m=>!m.deleted&&(type.value==='All'||m.type===type.value)&&(tag.value==='All subtags'||m.type==='System'&&m.tag===tag.value)&&(m.title+' '+m.body+' '+m.tag).toLowerCase().includes(search.value.toLowerCase()))){const item=el('details',undefined,'politics-message'),summary=el('summary'),badge=el('span','['+m.type+']','message-tag message-tag-'+m.type.toLowerCase());summary.append(badge,el('span','['+m.tag+']'),el('strong',m.title),el('small',m.read?'Read':'Unread'));item.append(summary,el('p',m.body));const remove=el('button','Delete demo message');remove.type='button';const sure=confirm(item);remove.disabled=true;sure.addEventListener('change',()=>remove.disabled=!sure.checked);remove.addEventListener('click',()=>{m.deleted=true;for(const update of inboxViews)update();});item.addEventListener('toggle',()=>{if(item.open&&!m.read){m.read=true;summary.lastChild.textContent='Read';}});item.append(remove);list.append(item);}if(!list.children.length)list.append(el('p','No matching demo messages.'));}
for(const control of [search,type,tag])control.addEventListener('input',draw);inboxViews.add(draw);draw();return root;}
export function resetInboxViews(){inboxViews.clear();}
export function motdPreview(){const grid=el('section',undefined,'politics-grid council-motds');grid.setAttribute('aria-label','Messages of the day');for(const [kind,author,seal,message]of [['Faction','Faction leader','office-house_leader.png','Stand together beneath our banner. Bring your proposals to the council, and let no voice of our House go unheard.'],['Imperial','Emperor','emperor-v1.png','To every House of the realm: let measured counsel precede action, and let the peace of our people guide the chamber.']]){const box=card(kind+' Message','DEMO · Example proclamation');const art=el('img');art.src='https://www.dunerealms.com/assets/seals/'+seal;art.alt='';art.width=art.height=48;box.prepend(art);box.append(el('blockquote',message),el('p','Issued by: Demo '+author+' · Example date: 8 November 2026','council-motd-author'));grid.append(box);}return grid;}
export function motdEditor(kind='Faction'){const imperial=kind==='Imperial',owner=imperial?'Emperor':'current faction leader';const box=card(kind+' Message settings','Only the '+owner+' may publish this message.');const art=el('img');art.src='https://www.dunerealms.com/assets/seals/'+(imperial?'emperor-v1.png':'office-house_leader.png');art.alt='';art.width=art.height=48;box.prepend(art);box.append(note());const form=el('div',undefined,'politics-charter');const text=field(form,kind+' message of the day','','textarea');text.rows=3;text.maxLength=1000;text.placeholder=imperial?'Address every House of the realm…':'Address the members of your faction…';confirm(form);form.append(button('Publish '+kind.toLowerCase()+' message — preview only'));box.append(form);return box;}