web/website/integrations/osticket/dev-jarvis-form.js
2026-11-21 20:22:37 +01:00

26 lines
2.9 KiB
JavaScript

const form=document.getElementById('jarvis-dev-request');
if(form){
const data=JSON.parse(document.getElementById('jarvis-request-catalogue').textContent),route=form.elements.workflow,action=form.elements.action_id,fields=document.getElementById('jarvis-action-fields'),help=document.getElementById('jarvis-route-help'),effect=document.getElementById('jarvis-action-effect');
const notes={existing:'Use the existing Jarvis adapter. Do not create a source change for an operation already supported.',idea:'Describe your future idea in plain language. Existing-action fields are disabled; a reviewer can check feasibility and the catalogue for you.',capability:'Describe what the new key or action should allow. A reviewer checks existing capabilities before any new implementation.',code:'Use Git and CI for implementation changes. Preserve existing Jarvis adapters and permissions.',devkey:'DEV KEY REQUEST: review only. Developer issuance and execution remain outside the website.'};
let initial={};try{initial=JSON.parse(data.values.action_parameters||'{}');}catch{}
function renderAction(values={}){
fields.replaceChildren();const chosen=data.catalogue.actions.find(a=>a.id===action.value);
effect.textContent=chosen?(chosen.effect||'Use the registered domain action; confirm its current adapter and authority.')+(chosen.fixedTargets.length?' Fixed targets: '+chosen.fixedTargets.join(', ')+'.':''):'';
for(const f of chosen?.fields||[]){
const label=document.createElement('label'),input=document.createElement(f.type==='textarea'?'textarea':'input'),caption=document.createElement('span');caption.textContent=f.label+(f.required?' *':'');
if(input.tagName==='INPUT')input.type=['number','datetime-local'].includes(f.type)?f.type:'text';input.name='jarvis_values['+f.name+']';input.required=!!f.required;input.maxLength=f.maxLength||240;if(f.min!==undefined)input.min=f.min;input.value=values[f.name]??'';
label.append(caption,input);fields.append(label);
}
}
function updateRoute(){
for(const block of form.querySelectorAll('[data-jarvis-routes]')){
const show=block.dataset.jarvisRoutes.split(' ').includes(route.value);block.hidden=!show;for(const control of block.querySelectorAll('input,select,textarea'))control.disabled=!show;
}
help.textContent=notes[route.value]||'Choose a route before completing the request.';
action.required=route.value==='existing';
form.elements.catalogue_review.required=['code','devkey'].includes(route.value);form.elements.missing_capability.required=route.value==='capability';
for(const name of ['dev_actor','dev_actions','dev_expiry','destructive_actions','dev_acknowledgement'])form.elements[name].required=route.value==='devkey';
form.elements.risk.required=route.value==='devkey';
}
action.addEventListener('change',()=>{renderAction();updateRoute();});route.addEventListener('change',updateRoute);renderAction(initial);updateRoute();
}