summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/changelog.js24
-rw-r--r--js/grades.js21
2 files changed, 40 insertions, 5 deletions
diff --git a/js/changelog.js b/js/changelog.js
new file mode 100644
index 0000000..9fb9a84
--- /dev/null
+++ b/js/changelog.js
@@ -0,0 +1,24 @@
+async function checkLogin() {
+ localforage.getItem("logged_in").then(function (value) {
+ // This code runs once the value has been loaded
+ // from the offline store.
+ if (value !== true) {
+ window.location.replace("/index.html");
+ }
+ }).catch(function (err) {
+ // This code runs if there were any errors
+ console.log(err);
+ });
+}
+
+document.addEventListener("DOMContentLoaded", () => {
+ checkLogin();
+
+ // Setup back button
+ $("#nav-back-button").click(function () {
+ window.location.replace("/pages/about.html");
+ });
+
+ var elems = document.querySelectorAll(".collapsible");
+ var instances = M.Collapsible.init(elems, {});
+}); \ No newline at end of file
diff --git a/js/grades.js b/js/grades.js
index 1768fb0..5c544fb 100644
--- a/js/grades.js
+++ b/js/grades.js
@@ -1,6 +1,8 @@
const API_ENDPOINT = "https://gimb.tk/test.php";
// const API_ENDPOINT = "http://localhost:5000/test.php";
+let checkbox_state = false;
+
async function checkLogin() {
localforage.getItem("logged_in").then((value) => {
// This code runs once the value has been loaded
@@ -167,8 +169,8 @@ function displayGrades() {
grade_node.appendChild(grade_node_div);
- // Count the grade only if it's not temprary
- if (!grade["temporary"]) {
+ // Count the grade only if it's not temporary or explicitly enabled
+ if (!grade["temporary"] || !checkbox_state) {
grade_sum += grade["grade"];
grade_tot += 1;
}
@@ -205,9 +207,9 @@ function clearGrades() {
}
}
-function refreshGrades() {
+function refreshGrades(force) {
clearGrades();
- loadGrades(true);
+ loadGrades(force);
}
function refreshClickHandlers() {
@@ -252,9 +254,18 @@ document.addEventListener("DOMContentLoaded", async () => {
// Setup refresh handler
$("#refresh-icon").click(function () {
- refreshGrades();
+ refreshGrades(true);
+ });
+
+ // Setup checkbox handler
+ $("#permanent-grades-checkbox").change(function () {
+ checkbox_state = this.checked;
+ refreshGrades(false);
});
+ let elems = document.querySelectorAll('.modal');
+ let instances = M.Modal.init(elems, {});
+
// Setup side menu
const menus = document.querySelectorAll('.side-menu');
M.Sidenav.init(menus, { edge: 'right', draggable: true });