From 00d3073b081ea9e342f7bd99ddf2eafcacf9e3fd Mon Sep 17 00:00:00 2001 From: BlasenhauerJ Date: Fri, 9 Dec 2022 18:28:45 +0100 Subject: [PATCH] get custom method and check disabled state --- src/ui/static/js/services.js | 66 ++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/src/ui/static/js/services.js b/src/ui/static/js/services.js index e7f59f922..3d4182a34 100644 --- a/src/ui/static/js/services.js +++ b/src/ui/static/js/services.js @@ -387,7 +387,7 @@ class Multiple { try { const cloneTitles = clone.querySelectorAll("h5"); cloneTitles.forEach((title) => { - title.textContent = `${title.textContent} #${ + title.textContent = `${title.textContent} ${ multipleEls.length >= 2 ? `#${topNum + 1}` : `` }`; }); @@ -487,28 +487,25 @@ class Multiple { if (inp.getAttribute("type") === "checkbox") { if (data["value"] === "yes") inp.setAttribute("checked", ""); if (data["value"] === "no") inp.removeAttribute("checked"); - if (data["method"] !== "ui" || data["method"] !== "default") { - inp.setAttribute("disabled", ""); - } else { - inp.removeAttribute("disabled"); - } + inp.setAttribute("default-method", data["method"]); } if (inp.getAttribute("type") !== "checkbox") { inp.setAttribute("value", data["value"]); - - if (data["method"] !== "ui" || data["method"] !== "default") { - inp.setAttribute("disabled", ""); - } else { - inp.removeAttribute("disabled"); - } + inp.setAttribute("default-method", data["method"]); } } catch (err) {} //or select try { const select = cloneSetting.querySelector("select"); this.setNameID(select, key); + const name = select.getAttribute("services-setting-select-default"); + const selTxt = document.querySelector( + `[services-setting-select-text='${name}']` + ); + selTxt.textContent = data["value"]; + selTxt.setAttribute("value", data["value"]); const options = select.options; for (let i = 0; i < options.length; i++) { @@ -517,12 +514,7 @@ class Multiple { ? option.setAttribute("selected") : option.removeAttribute("selected"); } - - if (data["method"] !== "ui" || data["method"] !== "default") { - select.setAttribute("disabled", ""); - } else { - select.removeAttribute("disabled"); - } + inp.setAttribute("default-method", data["method"]); } catch (err) {} //get the num, check if a container with this num exist @@ -605,6 +597,44 @@ class Multiple { } } } + //check enabled/disabled + this.setDisabled(); + }); + } + + setDisabled() { + const multipleCtnr = document.querySelectorAll( + "[services-settings-multiple]" + ); + multipleCtnr.forEach((container) => { + const settings = container.querySelectorAll("[setting-container]"); + + settings.forEach((setting) => { + //replace input info + try { + const inp = setting.querySelector("input"); + const method = inp.getAttribute("default-method"); + if (method === "ui" || method === "default") { + inp.removeAttribute("disabled"); + } else { + inp.setAttribute("disabled", ""); + } + } catch (err) {} + //or select + try { + const select = setting.querySelector("select"); + const method = select.getAttribute("default-method"); + const name = select.getAttribute("services-setting-select-default"); + const selDOM = document.querySelector( + `button[services-setting-select='${name}']` + ); + if (method === "ui" || method === "default") { + selDOM.setAttribute("disabled", ""); + } else { + selDOM.setAttribute("disabled", ""); + } + } catch (err) {} + }); }); }