Files
John Ahlroos 0ffeb914c3
All checks were successful
Compile Java Backend / Compile Backend Code (push) Successful in 1m32s
Lint Java Backend / Checkstyle Java Linting (push) Successful in 54s
Lint Dockerfiles / Lint Dockerfiles (push) Successful in 11s
Lint Frontend / Lint HTML, CSS, and JS (push) Successful in 39s
Fixed bug with unresponsive button
2025-11-10 20:59:17 +01:00

88 lines
3.1 KiB
JavaScript

function renderHeader() {
const headerDiv = document.getElementById("header");
if (window.location.pathname.endsWith("/")) {
localStorage.removeItem("userRole");
headerDiv.innerHTML = `
<header class="header">
<div class="logo-section">
<img src="../assets/images/logo/logo.png" alt="Hospital CRM Logo" class="logo-img">
<span class="logo-title">Hospital CMS</span>
</div>
</header>`;
return;
}
const role = localStorage.getItem("userRole");
const token = localStorage.getItem("token");
let headerContent = `<header class="header">
<div class="logo-section">
<img src="../assets/images/logo/logo.png" alt="Hospital CRM Logo" class="logo-img">
<span class="logo-title">Hospital CMS</span>
</div>
<nav>`;
if ((role === "loggedPatient" || role === "admin" || role === "doctor") && !token) {
localStorage.removeItem("userRole");
alert("Session expired or invalid login. Please log in again.");
window.location.href = "/";
return;
} else if (role === "admin") {
headerContent += `
<button id="addDocBtn" class="adminBtn">Add Doctor</button>
<a href="#" onclick="logout()">Logout</a>`;
} else if (role === "doctor") {
headerContent += `
<button class="adminBtn" onclick="selectRole('doctor')">Home</button>
<a href="#" onclick="logout()">Logout</a>`;
} else if (role === "patient") {
headerContent += `
<button id="patientLogin" class="adminBtn">Login</button>
<button id="patientSignup" class="adminBtn">Sign Up</button>`;
} else if (role === "loggedPatient") {
headerContent += `
<button id="home" class="adminBtn" onclick="window.location.href='/pages/loggedPatientDashboard.html'">Home</button>
<button id="patientAppointments" class="adminBtn" onclick="window.location.href='/pages/patientAppointments.html'">Appointments</button>
<a href="#" onclick="logoutPatient()">Logout</a>`;
}
headerContent += '</nav>';
headerDiv.innerHTML = headerContent;
attachHeaderButtonListeners();
}
function attachHeaderButtonListeners() {
const login = document.getElementById("patientLogin");
if (login) {
login.addEventListener('click', () => { openModal('patientLogin'); });
}
const signup = document.getElementById("patientSignup");
if (signup) {
signup.addEventListener('click', () => { openModal('patientSignup'); });
}
const addDoctor = document.getElementById("addDocBtn");
if (addDoctor) {
addDoctor.addEventListener('click', () => { openModal('addDoctor'); });
}
}
function logout() {
localStorage.removeItem("userRole");
localStorage.removeItem("token");
window.location.href = "/";
}
function logoutPatient() {
localStorage.removeItem("userRole");
localStorage.removeItem("token");
setRole('patient')
window.location.href='/pages/patientDashboard.html';
}
renderHeader();