web/website/control-panel/public/organisation-settings.mjs

9 lines
3.1 KiB
JavaScript

import {organisationTabs} from './organisation-tabs.mjs';
// Internal settings-page template. Adapters supply existing authorised forms.
export function createOrganisationSettings(sections,{keyContent=null}={}){
if(!document.querySelector('link[data-organisation-settings]')){const css=document.createElement('link');css.rel='stylesheet';css.href=new URL('./organisation-settings.css',import.meta.url).href;css.dataset.organisationSettings='';document.head.append(css);}
const root=document.createElement('div');root.className='organisation-settings-grid';
for(const {title,description,content,pending=false,danger=false} of sections){const card=document.createElement('section');card.className='organisation-settings-card'+(danger?' organisation-settings-danger':'');const heading=document.createElement('h3');heading.textContent=title;card.append(heading);if(pending){const badge=document.createElement('span');badge.className='organisation-settings-status';badge.textContent='Coming soon';card.append(badge);}const copy=document.createElement('p');copy.textContent=description;card.append(copy);if(content){if(content.tagName==='FORM')content.querySelector(':scope > h3')?.remove();card.append(content);}root.append(card);}
const groups=[['identity','Identity',['Identity & homeworld','Clan emblem']],['messages','Messages',['Message of the day']],['leadership','Leadership',['Leadership & roles','Ownership deed & dynasty']],['charter','Charter',['Claim charter & capacity','Relations & subhouses']],['keys','Keys',[]],['archive','Archive',['Archive clan']]].map(([id,title,titles])=>{const content=document.createElement('div');content.className='organisation-settings-grid';for(const card of [...root.children])if(titles.includes(card.querySelector('h3')?.textContent))content.append(card);if(id==='keys'&&keyContent){content.append(keyContent);}else if(id==='keys'){const card=document.createElement('section');card.className='organisation-settings-card';const heading=document.createElement('h3');heading.textContent='Unused upgrade keys';const note=document.createElement('p');note.textContent='Owner and member upgrade rights, including subclans. Design preview: private keys and ownership checks are not connected.';const scroll=document.createElement('div');scroll.style.overflow='auto';const table=document.createElement('table');const head=document.createElement('tr');for(const label of ['Holder','Clan / subclan','Type','Purpose','Origin','Status']){const cell=document.createElement('th');cell.textContent=label;head.append(cell);}const thead=document.createElement('thead');thead.append(head);const body=document.createElement('tbody'),row=document.createElement('tr'),cell=document.createElement('td');cell.colSpan=6;cell.textContent='Authorised key register will appear here. No private member keys are loaded.';row.append(cell);body.append(row);table.append(thead,body);scroll.append(table);card.append(heading,note,scroll);content.append(card);}return{id,title,content};});
if(root.children.length){groups[0].content.append(...root.children);}return organisationTabs(groups,{label:'Organisation settings sections'});
}