From 98688c884e754fcc239c0983fa373b37d067505f Mon Sep 17 00:00:00 2001 From: rstular Date: Thu, 30 Jan 2020 00:14:02 +0100 Subject: Temporary inclusion/exclusion option, fixed zoom --- js/grades.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'js') 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 }); -- cgit v1.2.3