implement enable disable with client side display and mod

This commit is contained in:
bel
2020-03-16 02:10:31 +00:00
parent bdfdb41bba
commit 9ec88a5ce8
6 changed files with 119 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ function upsert() {
console.log("error upserting:", status, body)
}
}
console.log("to upsert", jsonifyForm("upsert"))
http("POST", "/api/job/upsert", cb, jsonifyForm("upsert"))
}
@@ -27,6 +28,7 @@ function jsonifyForm(id) {
var form = document.getElementById(id)
var entries = new FormData(form).entries();
var json = Object.assign(...Array.from(entries, ([x,y]) => ({[x]:y})));
json.disabled = json.disabled == "false"
var s = JSON.stringify(json)
return s
}
@@ -67,15 +69,19 @@ function format(job) {
</span>
`
})
var strikethrough = "initial"
if (job.disabled)
strikethrough = "line-through"
strikethrough = "text-decoration: "+strikethrough
return `<tr><td><details>
<summary name="${job.id}">
<span>${job.title}</span>
<span style="${strikethrough}">${job.title}</span>
<span>${passing}</span>
${buttons}
</summary>
<table>
<tr><td>
<code>${job.cron}</code>
<code style="${strikethrough}">${job.cron}</code>
<code>${job.language}</code>
</td></tr>
<tr><td>
@@ -126,7 +132,14 @@ function jobmodify(input) {
}
function jobdelete(input) {
http("DELETE", "/api/job/delete", cb, null)
var job = jobFromInput(input)
if (!confirm(`Delete the job "${job.title}"?`))
return
function cb(body, status) {
var tr = getJobElement(job.id)
tr.parentNode.removeChild(tr)
}
http("DELETE", "/api/job/delete/"+job.id, cb, null)
}
function jobrefresh(input) {
@@ -154,6 +167,20 @@ function jobrefresh(input) {
http("GET", "/api/job/get/"+job.id, cb, null)
}
function getJobElement(id) {
var table = getJobsTable()
var summaries = Array.from(table.getElementsByTagName("summary"))
var target = null
summaries.forEach(function(e) {
if (e.getAttribute("name") == id) {
e = e.parentElement
e = e.parentElement.parentElement
target = e
}
})
return target
}
function jobFromInput(input) {
var b64 = input.getAttribute("job")
var json = atob(b64)