Recount-Server/web/static/index.js

64 lines
1.7 KiB
JavaScript

import {fill_chart} from "./chart_functions.js";
import {register_dropdowns} from "./dropdowns.js";
function debounce(func, delay) {
let timeoutId;
return function (...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
function switch_nav(event) {
var active_anchor = document.querySelector("nav a.active");
active_anchor.classList.remove("active");
var clicked = event.target;
clicked.classList.add("active");
}
function open_drafts() {
console.log("Opening drafts panel");
}
function register_nav_links() {
var navAnchors = document.querySelectorAll("nav a");
navAnchors.forEach(function (a_el) {
a_el.removeEventListener("click", switch_nav);
a_el.addEventListener("click", switch_nav);
});
}
function register_handlers() {
register_nav_links();
//fill_charts();
register_dropdowns();
document.querySelector("#open-draft").addEventListener("click", open_drafts);
}
function load_in_table() {
var rows = Array.from(document.querySelectorAll(".row_awaiting_processing"));
rows.sort((a, b) => b.dataset.rcntTransactionRowPos - a.dataset.rcntTransactionRowPos);
const processElement = (element, index) => {
element.classList.remove('row_awaiting_processing');
setTimeout(() => {
if (index < rows.length - 1) {
processElement(rows[index + 1], index + 1);
}
}, 25);
};
processElement(rows[0], 0);
}
const trigger_table_animation = debounce(load_in_table, 100);
const trigger_reset_handlers = debounce(register_handlers, 200);
export {trigger_reset_handlers, trigger_table_animation, fill_chart};