function http(method, remote, callback, body) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == XMLHttpRequest.DONE) { callback(xmlhttp.responseText, xmlhttp.status) } }; xmlhttp.open(method, remote, true); if (typeof body == "undefined") { body = null } xmlhttp.send(body); } function upserts() { function cb(body, status) { console.log(status, body) } http("POST", "/upserts", cb, jsonifyForm("upserts")) } 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}))); var s = JSON.stringify(json) return s } function init() { function cb(body, status) { var jobs = JSON.parse(body) jobs.forEach(function(job) { var s = format(job) inject(s) console.log("job=", job) console.log("s=", s) }) } function format(job) { var smiley = "128522" if (job.last.status != 0) { smiley = "129324" } smiley = `${smiley};` return `
${job.cron} |
${job.language} |
${job.script} |
${job.last.run} |
${job.last.runtime} |
${job.last.output} |