Files
stl/server/templates/index.hbs

49 lines
1.3 KiB
Handlebars

<!DOCTYPE html>
<html lang="en">
{{> head}}
<body>
{{> header}}
<ul class="striped_list">
{{#each categories}}
{{>category_entry}}
{{/each}}
</ul>
<script>
function toggle_category(id) {
// Find out whether the button is in active (play) or inactive (paused) state
let toggled_class = "category_button_toggled";
let cl = document.getElementById("toggle-button-" + id).classList;
let active = cl.contains(toggled_class);
// Get the corresponding route to activate/inactivate the category
let url;
if(active) {
url = "/api/category/" + id + "/end_session";
cl.remove(toggled_class);
} else {
url = "/api/category/" + id + "/start_session";
cl.add(toggled_class);
}
//var params = "lorem=ipsum&name=alpha";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState === XMLHttpRequest.DONE) {
console.log(xhr.status, xhr.responseText);
document.location.reload(false /* don't reset scroll position */);
}
};
xhr.send();
}
</script>
</body>
</html>