summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js45
-rw-r--r--index.html9
-rw-r--r--ka.js4
-rw-r--r--style.css20
4 files changed, 57 insertions, 21 deletions
diff --git a/app.js b/app.js
index 889afc0..8dec438 100644
--- a/app.js
+++ b/app.js
@@ -6,10 +6,15 @@ const loading = (val) => {
loader.$click(() => loading(0));
let error = null;
+function errClose() {
+ error = null;
+ app.reload();
+}
let data = {};
function onerror(err) {
error = err;
console.error(err);
+ app.reload();
}
function parsedata(r) {
return Object.fromEntries(r.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split('=')));
@@ -24,7 +29,7 @@ function cmd(url, body) {
})
.then(r => parsedata(r));
};
-function loaddata() {
+function loadconfig() {
loading(1);
cmd("/cgi-bin/getconfig")
.then(x => {
@@ -34,21 +39,34 @@ function loaddata() {
.catch(onerror)
.then(() => loading(0))
}
+function saveconfig(groups) {
+ cmd("/cgi-bin/setconfig", data)
+ .catch(onerror)
+ .then(loadconfig)
+}
+
+function CErr(text) {
+ var el = div(
+ div("🗙").$cls("close").$click(errClose),
+ span("⚠ "),
+ text,
+ ).$cls("err");
+ function errClose() {
+ error = null;
+ el.remove();
+ };
+ return el;
+}
const routes = {
"/": () => div(
h2("Lorem Ipsum"),
p("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "),
p("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."),
-
- h2("Ipsum Lorem"),
- p("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."),
- p("Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
- p("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."),
- p("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "),
),
"/network": () => div(
- h1("Мрежови настройки"),
+ error && CErr(error.message),
+ h1("Network settings"),
table(
tr(
td("IP"),
@@ -62,10 +80,9 @@ const routes = {
),
)
).$cls("network"),
- input("button").$value("Съхрани")
+ input("button").$value("Save").$click(saveconfig)
),
"/config": () => {
- loaddata();
return div();
},
"/waiting": () => {
@@ -73,11 +90,11 @@ const routes = {
setTimeout(() => {
loading(0);
}, 3000);
- return div("Пуйчи");
+ return div("");
},
"": () => div(
- h1("Несъществуваща страница"),
- p("Страницата не е намерена.")
+ h1("Not Found"),
+ p("The requested page is not available.")
),
};
const onchange = () => {
@@ -86,4 +103,4 @@ const onchange = () => {
};
router(app, routes, onchange);
-loaddata();
+loadconfig();
diff --git a/index.html b/index.html
index 5332fce..7a19004 100644
--- a/index.html
+++ b/index.html
@@ -13,11 +13,10 @@
<label for="showmenu"><span>☰</span> Меню</label>
<input type="checkbox" id="showmenu" />
- <a class="active" href="#">Данни</a>
- <a href="#/network">Мрежа</a>
- <a href="#/config">Настройки</a>
- <a href="#/tools">Инструменти</a>
- <a href="#/waiting">Пуйчи</a>
+ <a class="active" href="#">Home</a>
+ <a href="#/network">Network</a>
+ <a href="#/config">Configuration</a>
+ <a href="#/tools">Tools</a>
</nav>
<section id="app"></section>
</main>
diff --git a/ka.js b/ka.js
index a73bc9f..b7f9d6a 100644
--- a/ka.js
+++ b/ka.js
@@ -34,13 +34,13 @@ elproto.$change2state = function(state, field, valgetter=getvalue) {
function tag(name, attrs, ...children) {
const el = doc.createElement(name);
el.$attrs(attrs||{});
- for (const child of children) {
+ for (const child of children.filter(x=>x)) {
el.appendChild((typeof(child) === 'string') ? doc.createTextNode(child) : child);
}
return el;
}
-const TRIVIAL = "h1,h2,h3,p,a,div,span,select,table,tr,td";
+const TRIVIAL = "h1,h2,h3,p,,div,span,select,table,tr,td";
for (let name of TRIVIAL.split(",")) {
window[name] = (...children) => tag(name, null, ...children);
}
diff --git a/style.css b/style.css
index b89d135..334a765 100644
--- a/style.css
+++ b/style.css
@@ -86,6 +86,26 @@ input[type=button]:active {
background-color: #079290;
}
+.err {
+ color: #fff;
+ background-color: #f00;
+ position: relative;
+ padding: 16px;
+ margin-bottom: 10px;
+ line-height: 1.3em;
+}
+.err span {
+ font-size: 1.5em;
+ font-weight: bold;
+}
+.err .close {
+ font-size: 1.3em;
+ position: absolute;
+ top:16px;
+ right:16px;
+ cursor: pointer;
+}
+
#loader {
position: absolute;
left: 0;