aboutsummaryrefslogtreecommitdiff
path: root/static/script.js
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-05-03 00:27:36 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-05-03 00:27:36 +0200
commite0950b6c7463653c7049de196dc6448bf5e03fdb (patch)
treebd4de7e235c8571d90d3ca4d4a5fa23d0364e279 /static/script.js
parentTranslate 'monthly' and 'weekly' buttons. (diff)
downloadcalp-e0950b6c7463653c7049de196dc6448bf5e03fdb.tar.gz
calp-e0950b6c7463653c7049de196dc6448bf5e03fdb.tar.xz
Add [today] and [jump to] button in frontend.
Currently the JavaScript updates these buttons to work, but they by default reference backend endpoints which are not yet written.
Diffstat (limited to '')
-rw-r--r--static/script.js37
1 files changed, 32 insertions, 5 deletions
diff --git a/static/script.js b/static/script.js
index b9b6a5ba..579f4980 100644
--- a/static/script.js
+++ b/static/script.js
@@ -138,6 +138,11 @@ function update_current_time_bar () {
current_cell = document.querySelector(
".small-calendar time[datetime='" + time_to_date(now) + "']");
current_cell.style.border = "1px solid black";
+
+ /* Update [today] button */
+
+ document.getElementById("today-button").href
+ = time_to_date(new Date) + ".html";
}
function min(a, b) {
@@ -181,13 +186,35 @@ window.onload = function () {
}
}
- document.onkeydown = function (evt) {
- evt = evt || window.event;
- if (evt.key.startsWith("Esc")) {
- close_all_popups();
- }
+ document.onkeydown = function (evt) {
+ evt = evt || window.event;
+ if (! evt.key) return;
+ if (evt.key.startsWith("Esc")) {
+ close_all_popups();
}
+ }
+
+ /* Replace backend-driven [today] link with frontend, with one that gets
+ correctly set in the frontend.
+ Similarly, update the go to specific date button into a link which updates
+ wheneven the date form updates.
+ */
+
+ let jumpto = document.getElementsByClassName("jump-to")[0];
+ let gotodatebtn = jumpto.getElementsByTagName("button")[0];
+ let golink = document.createElement("a");
+ golink.classList.add("btn");
+ let target_href = time_to_date(new Date) + ".html";
+ document.getElementById("today-button").href = target_href;
+ golink.href = target_href;
+ golink.innerHTML = gotodatebtn.innerHTML;
+ gotodatebtn.replaceWith(golink);
+
+ jumpto.getElementsByTagName("input")[0].onchange = function () {
+ let date = time_to_date(this.valueAsDate)
+ golink.href = date + ".html";
+ }
}
$(document).ready(function() {