From 5b737ca90b191ac2d511545db51b05ebc7070837 Mon Sep 17 00:00:00 2001 From: MaxineMuster <146550015+MaxineMuster@users.noreply.github.com> Date: Tue, 14 May 2024 21:07:04 +0200 Subject: [PATCH] Fix possible wrong index / shorten JS code (#1238) * extend pin cfg page: introduce a function te get number of channels for an IO role in JS code generate all elements, but hide and disable unused fields. This way the should not count for POST action * Fix for possible wrong index when pin can't be PWM shorten code --------- Co-authored-by: openshwprojects <85486843+openshwprojects@users.noreply.github.com> --- src/httpserver/http_fns.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index a752888a4..c9d81a16c 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -2441,20 +2441,12 @@ int http_fn_cfg_pins(http_request_t* request) { poststr(request, "];"); poststr(request, "function hide_show() {" - "switch (r[this.selectedIndex][1]){" - "case 0:" - " e=getElement('r'+this.name); e.disabled=true;e.style.display='none';" - " e=getElement('e'+this.name); e.disabled=true;e.style.display='none';" - " break;" - "case 1:" - " e=getElement('r'+this.name); e.disabled=false;e.style.display='inline';" - " e=getElement('e'+this.name); e.disabled=true;e.style.display='none';" - " break;" - "case 2:" - " e=getElement('r'+this.name); e.disabled=false;e.style.display='inline';" - " e=getElement('e'+this.name); e.disabled=false;e.style.display='inline';" - " break;" - "};" + "n=this.name;" + "er=getElement('r'+n);" + "ee=getElement('e'+n);" + "ch=r[this.value][1];" // since we might have skiped PWM entries in options list, don't use "selectedIndex" but "value" (it's even shorter ;-) + "er.disabled = (ch<1); er.style.display= ch<1 ? 'none' : 'inline';" + "ee.disabled = (ch<2); ee.style.display= ch<2 ? 'none' : 'inline';" "}"); poststr(request, "function f(alias, id, c, b, ch1, ch2) {" @@ -2479,7 +2471,6 @@ int http_fn_cfg_pins(http_request_t* request) { "}" "var y = document.createElement(\"input\");" "y.className = \"hele\";" - "y.type = \"text\";" "y.name = \"r\"+id;" "y.id = \"r\"+id;" "y.disabled = ch1==null;" @@ -2488,7 +2479,6 @@ int http_fn_cfg_pins(http_request_t* request) { "d.appendChild(y);" "y = document.createElement(\"input\");" "y.className = \"hele\";" - "y.type = \"text\";" "y.name = \"e\"+id;" "y.id = \"e\"+id;" "y.disabled = ch2==null ;"