SimpleChatTC:UI:Common helper to edit obj members of few types

Make the previously relatively generic flow wrt apiRequestOptions
settings into a fully generic reusable by others flow.

Rather had stopped short of it, when previously moved onto other
things at that time.
This commit is contained in:
hanishkvc 2025-10-20 13:58:27 +05:30
parent 6e5b532313
commit b771e42dc1
2 changed files with 40 additions and 1 deletions

View File

@ -1174,7 +1174,7 @@ class Me {
}); });
elDiv.appendChild(bb.div); elDiv.appendChild(bb.div);
this.show_settings_apirequestoptions(elDiv); ui.ui_show_obj_props_edit(elDiv, this.apiRequestOptions, Object.keys(this.apiRequestOptions), "ApiRequestOptions")
let sel = ui.el_creatediv_select("SetApiEP", "ApiEndPoint", ApiEP.Type, this.apiEP, (val)=>{ let sel = ui.el_creatediv_select("SetApiEP", "ApiEndPoint", ApiEP.Type, this.apiEP, (val)=>{
// @ts-ignore // @ts-ignore

View File

@ -230,3 +230,42 @@ export function el_creatediv_input(id, label, type, defaultValue, cb, className=
div.appendChild(el); div.appendChild(el);
return { div: div, el: el }; return { div: div, el: el };
} }
/**
* Auto create ui input elements for fields in apiRequestOptions
* Currently supports text and number field types.
* @param {HTMLDivElement} elDiv
* @param {any} oObj
* @param {Array<string>} lProps
* @param {string} sLegend
*/
export function ui_show_obj_props_edit(elDiv, oObj, lProps, sLegend) {
let typeDict = {
"string": "text",
"number": "number",
};
let fs = document.createElement("fieldset");
let legend = document.createElement("legend");
legend.innerText = sLegend;
fs.appendChild(legend);
elDiv.appendChild(fs);
for(const k in lProps) {
let val = oObj[k];
let type = typeof(val);
if (((type == "string") || (type == "number"))) {
let inp = el_creatediv_input(`Set${k}`, k, typeDict[type], oObj[k], (val)=>{
if (type == "number") {
val = Number(val);
}
oObj[k] = val;
});
fs.appendChild(inp.div);
} else if (type == "boolean") {
let bbtn = el_creatediv_boolbutton(`Set{k}`, k, {true: "true", false: "false"}, val, (userVal)=>{
oObj[k] = userVal;
});
fs.appendChild(bbtn.div);
}
}
}