summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2024-08-21 01:58:20 +0300
committerMarin Ivanov <[email protected]>2024-08-21 01:58:20 +0300
commitc550c3bc1c6cce7bb8a4916348e91dfb71074919 (patch)
treedc51abc4c6ae67be04f75acd81e8f27fb10242c9
parent4010314ed257aeb09cfea9e24ed9e34731375245 (diff)
fix cmd() and sending form data
-rw-r--r--app.js21
-rw-r--r--index.html10
2 files changed, 17 insertions, 14 deletions
diff --git a/app.js b/app.js
index 8ffe96c..b265f76 100644
--- a/app.js
+++ b/app.js
@@ -19,19 +19,19 @@
window.onunhandledrejection = (e) => {
setError(e.reason);
};
- let parseini = (data) => fromEntries(data.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split("=")));
- let buildini = (data, prefix="") => entries(data).map(([k,v])=>`${prefix}${k}=${v}\n`).join();
+ let parsetxt = (data) => fromEntries(data.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split("=")));
+ let buildtxt = (data) => entries(data).map(([k,v])=>`${k}=${v}\n`).join("");
let resptext = r => {
if (!r.ok){
throw new Error(r.statusText);
}
return r.text();
};
- getconfig = () => fetch("/cgi-bin/getconfig").then(resptext).then(x => parseini(x));
+ getconfig = () => fetch("/cgi-bin/getconfig").then(resptext).then(x => parsetxt(x));
cmd = (body) => fetch("/cgi-bin/cmd",{method:"POST",body}).then(resptext);
- setconfig = (data, prefix) => {
+ setconfig = (data) => {
loading(1);
- cmd(buildini(data, prefix)+"save\n")
+ cmd(buildtxt(data)+"save\n")
.finally(() => loading(0))
};
loadconfig = () => {
@@ -43,7 +43,7 @@
})
.finally(() => loading(0));
}
- reboot = (data, prefix) => {
+ reboot = (data) => {
let ok = 0;
loading(1);
cmd("reboot\n")
@@ -107,14 +107,17 @@
function CSettings(section) {
let s = config.sections[section];
- let form_ = form(
+ let f = form(
table(...s.fields.map(x => CSettingInput(x))),
input("submit").$value("Save")
);
- form_.onsubmit = (e) => {e.preventDefault(); setconfig({});}
+ f.onsubmit = (e) => {
+ e.preventDefault();
+ setconfig(fromEntries(new FormData(f)));
+ }
return div(
h1(s.title),
- form_,
+ f,
)
}
diff --git a/index.html b/index.html
index 2527724..0915708 100644
--- a/index.html
+++ b/index.html
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf8">
- <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="viewport" content="width=device-width,initial-scale=1">
<title>WebIF 2.0</title>
<link rel="stylesheet" href="style.css">
</head>
@@ -13,12 +13,12 @@
</div>
<div id="loader" title="click to hide">
<div>
- <div class="loadspin"></div>
- <p>Loading...</p>
- </div>
+ <div class="loadspin"></div>
+ <p>Loading...</p>
+ </div>
</div>
- <script src="ka.js"></script>
<script src="config.js"></script>
+ <script src="ka.js"></script>
<script src="app.js"></script>
</body>
</html>