"use strict"; /* Search related functions */ let submitTimer, submitInterval, intervals = 1; let queryElement = document.getElementById("query"); let autoSearchEnabled = "<%= Sail.configuration.enable_search_auto_submit %>"; let progress = document.getElementById("search-submit-progress"); let sortMenu = document.getElementById("sort-menu"); let orderButton = document.getElementById("btn-order"); let profilesMenu = document.getElementById("profiles-modal"); let profilesButton = document.getElementById("btn-profiles"); let dashboardBody = document.getElementById("settings-dashboard"); function submitSearch() { document.getElementById("search-form").submit(); } function advanceProgress() { progress.value = intervals; intervals += 1; } function clearTimer() { clearTimeout(submitTimer); clearTimeout(submitInterval); intervals = 1; } function afterTypingQuery() { progress.style.display = "inline-block"; clearTimer(); submitTimer = setTimeout(submitSearch, 2000); submitInterval = setInterval(advanceProgress, 20); } function toggleSortMenu() { if (sortMenu.style.display === "none") { sortMenu.style.display = "block"; } else { sortMenu.style.display = "none"; } } function toggleProfilesMenu() { if (profilesMenu.style.display === "none") { dashboardBody.style.filter = "opacity(70%) blur(2px)"; document.body.style.filter = "alpha(opacity=60)"; profilesMenu.style.display = "block"; } else { profilesMenu.style.display = "none"; dashboardBody.style.filter = "none"; } } function handleGenericClick(event) { let target = event.target; if (target === sortMenu || sortMenu.contains(target) || target === orderButton || orderButton.contains(target) || target === profilesMenu || profilesMenu.contains(target) || target === profilesButton || profilesButton.contains(target)) { return; } sortMenu.style.display = "none"; profilesMenu.style.display = "none"; dashboardBody.style.filter = "none"; } function closeAllModals(event) { if (event.key === "Escape") { sortMenu.style.display = "none"; profilesMenu.style.display = "none"; dashboardBody.style.filter = "none"; } } if (autoSearchEnabled === "true") { queryElement.addEventListener("keyup", afterTypingQuery); queryElement.addEventListener("keydown", clearTimer); } orderButton.addEventListener("click", toggleSortMenu); profilesButton.addEventListener("click", toggleProfilesMenu); document.body.addEventListener("click", handleGenericClick); document.addEventListener("keydown", closeAllModals); /* Refresh related functions */ let refreshButtons = document.getElementsByClassName("refresh-button"); function refreshClick() { let button = this; if (!button.className.includes("active")) { button.classList.add("active"); setTimeout(function() { button.classList.remove("active"); }, 500); } } for(var i = 0; i < refreshButtons.length; i++) refreshButtons[i].addEventListener("click", refreshClick);