From 922e3e27fa9a90d62d139f3f6ff8fa291c3cd5b2 Mon Sep 17 00:00:00 2001 From: Jonathan Senecal Date: Thu, 17 Aug 2023 23:47:47 -0400 Subject: [PATCH] Use document.querySelectorAll() Co-authored-by: kkthxbye <400797+kkthxbye-code@users.noreply.github.com> --- netbox/project-static/src/dashboard.ts | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/netbox/project-static/src/dashboard.ts b/netbox/project-static/src/dashboard.ts index be96e701a..1c6f20562 100644 --- a/netbox/project-static/src/dashboard.ts +++ b/netbox/project-static/src/dashboard.ts @@ -4,36 +4,19 @@ import { apiPatch, hasError } from './util'; function lockDashboard(): void { const dashboard = document.getElementById('dashboard') as any; - const gridUnlockButton = document.getElementById('unlock_dashboard') as HTMLButtonElement; - const gridLockButton = document.getElementById('lock_dashboard') as HTMLButtonElement; - if (dashboard) { dashboard.gridstack.disable(); // Hide the grid stack items buttons - Array.from(document.getElementsByClassName("grid-stack-item-button")).forEach(function (element) { - element.classList.add('invisible'); - }); - } - if (gridUnlockButton && gridLockButton) { - gridUnlockButton.classList.remove('invisible'); - gridLockButton.classList.add('invisible'); + document.querySelectorAll(".grid-stack-item-button, #unlock_dashboard, #lock_dashboard").forEach(el => el.classList.toggle('invisible')); } } function unlockDashboard(): void { const dashboard = document.getElementById('dashboard') as any; - const gridUnlockButton = document.getElementById('unlock_dashboard') as HTMLButtonElement; - const gridLockButton = document.getElementById('lock_dashboard') as HTMLButtonElement; if (dashboard) { dashboard.gridstack.enable(); // Show the grid stack items buttons - Array.from(document.getElementsByClassName("grid-stack-item-button")).forEach(function (element) { - element.classList.remove('invisible'); - }); - } - if (gridUnlockButton && gridLockButton) { - gridUnlockButton.classList.add('invisible'); - gridLockButton.classList.remove('invisible'); + document.querySelectorAll(".grid-stack-item-button, #unlock_dashboard, #lock_dashboard").forEach(el => el.classList.toggle('invisible')); } }