Grouping um settings, add pre and post Info, update SR & 4LD settings

Settings_um.htm: 
- modify addField (grouping)
- addInfo (pre and post texts)
This commit is contained in:
Ewoud
2022-11-20 13:53:47 +01:00
parent 9a0bc6ad87
commit e5b54c947b
10 changed files with 3331 additions and 3320 deletions

View File

@@ -107,6 +107,7 @@
function addField(k,f,o,a=false) { //key, field, (sub)object, isArray
if (isO(o)) {
urows += '<hr class="sml">';
if (f!=='unknown' && !k.includes(":")) urows += `<p><u>${f}</u></p>`; //WLEDMM show group title
for (const [s,v] of Object.entries(o)) {
// possibility to nest objects (only 1 level)
if (f!=='unknown' && !k.includes(":")) addField(k+":"+f,s,v);
@@ -135,8 +136,7 @@
t = "text"; c = `value="${o}" style="width:250px;"`;
break;
}
if (k.includes(":")) urows += k.substr(k.indexOf(":")+1);
urows += ` ${f}: `;
urows += ` ${f} `; //WLEDMM only show field (key is shown in grouping)
// https://stackoverflow.com/questions/11657123/posting-both-checked-and-unchecked-checkboxes
if (t=="checkbox") urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="false">`;
else if (!a) urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="${t}">`;
@@ -179,11 +179,21 @@
}
}
// https://stackoverflow.com/questions/26440494/insert-text-after-this-input-element-with-javascript
function addInfo(name,el,txt) {
//WLEDMM Add pre and post texts
function addInfo(name,el,txt, txt2="") {
console.log("addInfo", name, el, txt)
let obj = d.getElementsByName(name);
// console.log(obj);
if (!obj.length) return;
if (typeof el === "string" && obj[0]) obj[0].placeholder = el;
else if (obj[el]) obj[el].insertAdjacentHTML('afterend', '&nbsp;'+txt);
else if (obj[el]) {
if (txt2!="") {
obj[el].insertAdjacentHTML('beforebegin', txt + '&nbsp;');
obj[el].insertAdjacentHTML('afterend', '&nbsp;'+txt2);
}
else
obj[el].insertAdjacentHTML('afterend', '&nbsp;'+txt);
}
}
// load settings and insert values into DOM
function ldS() {