Files
Inventory-Manager/public/javascripts/header.js
T

45 lines
1.5 KiB
JavaScript

"use strict";
document.addEventListener('DOMContentLoaded', () => {
const brandNav = document.querySelector('#brandNav');
if (brandNav) {
brandNav.addEventListener('click', () => {
window.location.href = '/';
});
}
const homeNav = document.querySelector('#homeNav');
if (homeNav) {
homeNav.addEventListener('click', () => {
window.location.href = '/';
});
}
const inventoryNav = document.querySelector('#inventoryNav');
if (inventoryNav) {
inventoryNav.addEventListener('click', () => {
window.location.href = '/inventory';
});
}
const loginNav = document.querySelector('#loginNav');
if (loginNav) {
loginNav.addEventListener('click', () => {
window.location.href = '/login';
});
}
const settingsNav = document.querySelector('#settingsNav');
if (settingsNav) {
settingsNav.addEventListener('click', () => {
window.location.href = '/settings';
});
}
const logoutNav = document.querySelector('#logoutNav');
if (logoutNav) {
logoutNav.addEventListener('click', (event) => {
event.preventDefault(); // Prevent default link behavior
$.get('/auth/logout', function (data) {
window.location.href = '/login';
}).fail((jqXHR) => {
alert('Logout failed: ' + jqXHR.responseText);
});
});
}
});