diff --git a/views/scripts/config.js b/views/scripts/config.js index 26c4fd97..f8fb1eb8 100644 --- a/views/scripts/config.js +++ b/views/scripts/config.js @@ -1,10 +1,12 @@ var showConfig = document.getElementById("show-config"); +var rawConfig = {}; showConfig.addEventListener("click", () => { var configForm = document.getElementById("config-form"); fetch("/config") .then(response => response.json()) - .then(data => { + .then(data => { + rawConfig = data; configForm.style.display = "block"; processChildren(configForm, data); }); @@ -17,11 +19,42 @@ function processChildren(element, data) { child.className = "config-element"; child.appendChild(document.createTextNode(key + ": ")); if (data[key] === Object(data[key])) { - console.log(key, data[key]); processChildren(child, data[key]); } else { - child.textContent+=data[key]; + var value = document.createElement("span"); + value.id = key+"-value"; + value.textContent = data[key]; + createEditButton(value); + value.addEventListener("click", (event) => { + var inputNewText = document.createElement("input"); + inputNewText.type = "text"; + inputNewText.class = "config-element-edit"; + inputNewText.id = key+"-value"; + console.log(value.parentNode); + console.log(value); + child.replaceChild(inputNewText, value); + console.log(event); + }); + child.appendChild(value); } element.appendChild(child); } +} + +function createEditButton(parent) { + var editButton = document.createElement("button"); + editButton.type = "button"; + editButton.className = "config-edit-button"; + editButton.textContent = "🖊️"; + editButton.id = "parentId-" + parent.id; + // console.log(parent); + editButton.addEventListener("click", (event) => { + var inputNewText = document.createElement("input"); + inputNewText.type = "text"; + inputNewText.class = "config-element-edit"; + parent.parentNode.replaceChild(inputNewText, parent); + // console.log(event); + }) + // console.log("edit button", editButton); + parent.appendChild(editButton); } \ No newline at end of file