2021-11-27 16:50:05 +01:00
|
|
|
var showConfig = document.getElementById("show-config");
|
2021-11-28 00:00:47 +01:00
|
|
|
var rawConfig = {};
|
2021-11-27 17:14:49 +01:00
|
|
|
|
2021-11-27 16:50:05 +01:00
|
|
|
showConfig.addEventListener("click", () => {
|
2021-11-27 17:14:49 +01:00
|
|
|
var configForm = document.getElementById("config-form");
|
2021-11-27 16:50:05 +01:00
|
|
|
fetch("/config")
|
|
|
|
.then(response => response.json())
|
2021-11-28 00:00:47 +01:00
|
|
|
.then(data => {
|
|
|
|
rawConfig = data;
|
2021-11-27 16:52:54 +01:00
|
|
|
configForm.style.display = "block";
|
2021-11-27 17:14:49 +01:00
|
|
|
processChildren(configForm, data);
|
2021-11-27 16:50:05 +01:00
|
|
|
});
|
2021-11-27 17:14:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function processChildren(element, data) {
|
|
|
|
for (let key in data) {
|
|
|
|
var child = document.createElement("div");
|
|
|
|
child.id = key;
|
2021-11-27 20:39:05 +01:00
|
|
|
child.className = "config-element";
|
2021-11-27 17:14:49 +01:00
|
|
|
child.appendChild(document.createTextNode(key + ": "));
|
|
|
|
if (data[key] === Object(data[key])) {
|
|
|
|
processChildren(child, data[key]);
|
|
|
|
} else {
|
2021-11-28 00:00:47 +01:00
|
|
|
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);
|
2021-11-27 17:14:49 +01:00
|
|
|
}
|
|
|
|
element.appendChild(child);
|
|
|
|
}
|
2021-11-28 00:00:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-11-27 17:14:49 +01:00
|
|
|
}
|