pannenkoekenwachtrij/templates/home.html

86 lines
2.8 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html>
<html lang="en">
2019-12-17 06:03:47 +01:00
<head>
<meta charset="UTF-8">
<title>Pannenkoekenwachtrij</title>
</head>
2019-12-17 06:03:47 +01:00
<body>
2019-12-17 06:03:47 +01:00
<header>
<h1>Welkom bij de pannenkoekenwachtrij</h1>
<form id="addPersonForm">
2019-12-17 15:40:50 +01:00
<p>Naam van de volgende <input type="text" name="name" maxlength=30></p>
<p>Specifieke opmerkingen <input type="text" name="remark" maxlength=50></p>
2019-12-17 06:03:47 +01:00
<p><input type="submit" value="Persoon toevoegen" id="addPersonButton"></p>
</form>
<h2>Zie hieronder de lijst van personen die een pannenkoek willen</h2>
2019-12-17 15:14:46 +01:00
<table id="orderTable">
2019-12-17 06:03:47 +01:00
</table>
</header>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
2019-12-17 15:14:46 +01:00
function executeQuery(query, callback) {
$.ajax({
type: "POST",
url: '/execute',
contentType: "application/json",
data: JSON.stringify({
"lecode": query
}),
success: callback,
error: function(e) {
console.log("ERROR : ", e);
}
});
}
function start_bakken(id) {
executeQuery(`UPDATE orders SET status = 'aan_het_bakken' where id=${id}`, function(ign) {
updateTable();
});
}
function klaar(id) {
executeQuery(`UPDATE orders SET status = 'klaar' where id=${id}`, function(ign) {
updateTable();
});
}
function dismiss(id) {
executeQuery(`UPDATE orders SET status = 'dismissed' where id=${id}`, function(ign) {
updateTable();
});
}
function updateTable() {
executeQuery(`SELECT id, name, remark, status from orders where status != 'dismissed'`, function(x) {
$('#orderTable').empty();
console.log(x);
for (row of x) {
console.log(row);
$('#orderTable').append(`<tr><td><button onclick="start_bakken(${row[0]})">Aan het bakken</button></td><td><button onclick="klaar(${row[0]})">Klaar</button></td><td><button onclick="dismiss(${row[0]})">Dismiss</button></td><th>${row[1] + " (" + row[2] + ")"}</th><td>${row[3]}</td></tr>`);
}
});
}
2019-12-17 06:03:47 +01:00
$(document).ready(function() {
2019-12-17 15:14:46 +01:00
updateTable();
2019-12-17 06:03:47 +01:00
$("#addPersonButton").click(function(event) {
event.preventDefault();
var form = $("#addPersonForm").serializeArray();
var name = form[0]["value"];
var remark = form[1]["value"];
2019-12-17 15:14:46 +01:00
executeQuery(`INSERT INTO orders (name, remark) VALUES ('${name}', '${remark}')`, function(ign) {
updateTable();
2019-12-17 06:03:47 +01:00
});
});
})
</script>
</body>
2019-12-17 06:03:47 +01:00
</html>