diff --git a/web/static/js/interval.js b/web/static/js/interval.js new file mode 100644 index 0000000..24eb2d0 --- /dev/null +++ b/web/static/js/interval.js @@ -0,0 +1,69 @@ +function update_input(element) { + let months = element.querySelector('input[name="interval_months"]'); + let days = element.querySelector('input[name="interval_days"]'); + let hours = element.querySelector('input[name="interval_hours"]'); + let minutes = element.querySelector('input[name="interval_minutes"]'); + let seconds = element.querySelector('input[name="interval_seconds"]'); + + months.value = months.value.padStart(1, "0"); + days.value = days.value.padStart(1, "0"); + hours.value = hours.value.padStart(2, "0"); + minutes.value = minutes.value.padStart(2, "0"); + seconds.value = seconds.value.padStart(2, "0"); + + if (seconds.value >= 60) { + let quotient = Math.floor(seconds.value / 60); + let remainder = seconds.value % 60; + + seconds.value = String(remainder).padStart(2, "0"); + minutes.value = String(Number(minutes.value) + Number(quotient)).padStart(2, "0"); + } + if (minutes.value >= 60) { + let quotient = Math.floor(minutes.value / 60); + let remainder = minutes.value % 60; + + minutes.value = String(remainder).padStart(2, "0"); + hours.value = String(Number(hours.value) + Number(quotient)).padStart(2, "0"); + } + if (hours.value >= 24) { + let quotient = Math.floor(hours.value / 24); + let remainder = hours.value % 24; + + hours.value = String(remainder).padStart(2, "0"); + days.value = Number(days.value) + Number(quotient); + } +} + +let $intervalGroup = document.querySelector(".interval-group"); + +document.querySelector(".interval-group").addEventListener( + "blur", + (ev) => { + if (ev.target.nodeName !== "BUTTON") update_input($intervalGroup); + }, + true +); + +$intervalGroup.querySelector("button.clear").addEventListener("click", () => { + document + .querySelector(".interval-group") + .querySelectorAll("input") + .forEach((el) => { + el.value = ""; + }); +}); + +document.addEventListener("remindersLoaded", (event) => { + for (reminder of event.detail) { + update_input(reminder.node.querySelector(".interval-group input")); + + reminder.node.querySelector("button.clear").addEventListener("click", () => { + reminder.node + .querySelector(".interval-group") + .querySelectorAll("input") + .forEach((el) => { + el.value = ""; + }); + }); + } +}); diff --git a/web/templates/base.html.tera b/web/templates/base.html.tera index ecad959..d188b1b 100644 --- a/web/templates/base.html.tera +++ b/web/templates/base.html.tera @@ -66,7 +66,7 @@ @@ -114,7 +114,7 @@

- Add to your Server + Add to your Server

@@ -122,7 +122,7 @@

- Join Discord + Join Discord

diff --git a/web/templates/dashboard.html.tera b/web/templates/dashboard.html.tera index 116b78f..031b966 100644 --- a/web/templates/dashboard.html.tera +++ b/web/templates/dashboard.html.tera @@ -321,6 +321,7 @@ {% include "reminder_dashboard/personal_reminder" %} + diff --git a/web/templates/reminder_dashboard/guild_reminder.html.tera b/web/templates/reminder_dashboard/guild_reminder.html.tera index 0b6f114..bf27ce0 100644 --- a/web/templates/reminder_dashboard/guild_reminder.html.tera +++ b/web/templates/reminder_dashboard/guild_reminder.html.tera @@ -159,7 +159,7 @@ : - +