Toggle bump buttona via JS
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -2166,7 +2166,7 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stl"
|
name = "stl"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -2190,7 +2190,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stl_cli"
|
name = "stl_cli"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"futures",
|
"futures",
|
||||||
@ -2209,7 +2209,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stl_lib"
|
name = "stl_lib"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "stl_cli"
|
name = "stl_cli"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "stl_lib"
|
name = "stl_lib"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "stl"
|
name = "stl"
|
||||||
description = "studielogg aka scuffed toggl"
|
description = "studielogg aka scuffed toggl"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
authors = ["Joakim Hulthe <joakim@hulthe.net>"]
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@ -231,3 +231,6 @@ ul.striped_list > li:nth-child(odd) ul li:nth-child(odd) { background-color:#30
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.display_none {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|||||||
@ -5,16 +5,19 @@
|
|||||||
></div>
|
></div>
|
||||||
<span class="category_name">{{this.category.name}}</span>
|
<span class="category_name">{{this.category.name}}</span>
|
||||||
<div class="category_button_container">
|
<div class="category_button_container">
|
||||||
{{#if this.category.started}}
|
|
||||||
<form
|
<form
|
||||||
action="/category/{{@key}}/bump_session/minutes/5"
|
action="/category/{{@key}}/bump_session/minutes/5"
|
||||||
id="bump-form-{{@key}}"
|
id="bump-form-{{@key}}"
|
||||||
method="post"></form>
|
method="post"></form>
|
||||||
<button
|
<button
|
||||||
|
{{#if this.category.started}}
|
||||||
class="category_bump_button"
|
class="category_bump_button"
|
||||||
|
{{else}}
|
||||||
|
class="category_bump_button display_none"
|
||||||
|
{{/if}}
|
||||||
|
id="bump-button-{{@key}}"
|
||||||
form="bump-form-{{@key}}"
|
form="bump-form-{{@key}}"
|
||||||
type="submit">+5m</button>
|
type="submit">+5m</button>
|
||||||
{{/if}}
|
|
||||||
<!-- without this extra tag, every even noscript tag seems to not trigger -->
|
<!-- without this extra tag, every even noscript tag seems to not trigger -->
|
||||||
<!-- what is even happening help -->
|
<!-- what is even happening help -->
|
||||||
<noscript></noscript>
|
<noscript></noscript>
|
||||||
|
|||||||
@ -14,17 +14,21 @@
|
|||||||
function toggle_category(id) {
|
function toggle_category(id) {
|
||||||
// Find out whether the button is in active (play) or inactive (paused) state
|
// Find out whether the button is in active (play) or inactive (paused) state
|
||||||
let toggled_class = "category_button_toggled";
|
let toggled_class = "category_button_toggled";
|
||||||
let cl = document.getElementById("toggle-button-" + id).classList;
|
let display_none_class = "display_none";
|
||||||
let active = cl.contains(toggled_class);
|
let toggle_cl = document.getElementById("toggle-button-" + id).classList;
|
||||||
|
let bump_cl = document.getElementById("bump-button-" + id).classList;
|
||||||
|
let active = toggle_cl.contains(toggled_class);
|
||||||
|
|
||||||
// Get the corresponding route to activate/inactivate the category
|
// Get the corresponding route to activate/inactivate the category
|
||||||
let url;
|
let url;
|
||||||
if(active) {
|
if(active) {
|
||||||
url = "/api/category/" + id + "/end_session";
|
url = "/api/category/" + id + "/end_session";
|
||||||
cl.remove(toggled_class);
|
toggle_cl.remove(toggled_class);
|
||||||
|
bump_cl.add(display_none_class);
|
||||||
} else {
|
} else {
|
||||||
url = "/api/category/" + id + "/start_session";
|
url = "/api/category/" + id + "/start_session";
|
||||||
cl.add(toggled_class);
|
toggle_cl.add(toggled_class);
|
||||||
|
bump_cl.remove(display_none_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
//var params = "lorem=ipsum&name=alpha";
|
//var params = "lorem=ipsum&name=alpha";
|
||||||
@ -36,9 +40,11 @@
|
|||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if(xhr.readyState === XMLHttpRequest.DONE) {
|
if(xhr.readyState === XMLHttpRequest.DONE) {
|
||||||
console.log(xhr.status, xhr.responseText);
|
if(xhr.status != 200) {
|
||||||
|
console.error("xhr error", xhr.status, xhr.responseText);
|
||||||
document.location.reload(false /* don't reset scroll position */);
|
document.location.reload(false /* don't reset scroll position */);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
|||||||
Reference in New Issue
Block a user