-
Notifications
You must be signed in to change notification settings - Fork 284
/
manage.html
348 lines (311 loc) · 15.6 KB
/
manage.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Status</title>
<link rel="stylesheet" href="src/css/manage.css">
<link rel="stylesheet" href="src/css/hospital.css">
<link rel="shortcut icon" href="ambulance.png" type="image/x-icon"><!-- Ensures consistent styling -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKR3agIMLtauzDhz4fCu3heww0BV_81H4" async defer></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<header>
<nav class="navbar">
<div class="navbar-logo">
<a href="./index.html" target="_self"><img src="./images/manageLogo.png"></img></a>
<a href="./index.html"><h2 style="display: flex;">ambu<p style="color: #3DBDEC;">Flow</p></h2></a>
</div>
<ul class="navbar-links">
<li><a href="hospital.html">Dashboard</a></li>
<li><a href="manage.html">Manage Status</a></li>
<li><a href="driver.html">Manage Driver</a></li>
<li><a href="ambtracker.html">Manage Ambulance</a></li>
<li id="logout"><a href="#"><i class="fa-solid fa-right-from-bracket"></i></a></li>
</ul>
<div class="resp">
<button id="dropdown"><i class="fa-solid fa-bars"></i></button>
<li id="logout" onclick="logout1()"><a href="#"><i class="fa-solid fa-right-from-bracket" style="color: white;"></i></a></li>
</div>
</nav>
</header>
<!-- Dropdown -->
<div class="dropdown-menu">
<ul class="navbar-links2">
<li><a href="hospital.html">Dashboard</a></li>
<li><a href="manage.html">Manage Status</a></li>
<li><a href="driver.html">Manage Driver</a></li>
<li><a href="ambtracker.html">Manage Ambulance</a></li>
</ul>
</div>
<main>
<div class="manage-container">
<h1>Manage Status</h1>
<div class="manage-options">
<button class="manage-btn" id="addDriverBtn">Add Driver</button>
<button class="manage-btn" id="addAmbulanceBtn">Add Ambulance</button>
</div>
<!-- Manage Driver Section -->
<section id="manageDriverSection" class="manage-section">
<h2 id="driverFormTitle" style="margin-bottom: 20px;">Add Driver</h2>
<form id="driverForm">
<input type="text" id="driverIndex" name="driverIndex" hidden>
<div class="form-group">
<label for="driverName">Driver Name:</label>
<input type="text" id="driverName" name="driverName" required placeholder="Enter driver name">
</div>
<div class="form-group">
<label for="driverStatus">Status:</label>
<select id="driverStatusSelect" name="driverStatus" required>
<option value="" disabled selected>Select status</option>
<option value="Available">Available</option>
<option value="Offline">Offline</option>
</select>
</div>
<div class="form-group">
<label for="driverContact">Contact Number:</label>
<input type="tel" id="driverContact" name="driverContact" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" placeholder="123-456-7890" required>
</div>
<div class="form-group">
<label for="driverLocation">Location:</label>
<input type="text" id="driverLocation" name="driverLocation" placeholder="e.g., Location XYZ" required>
</div>
<p class="button-container">
<button type="submit" class="submit-btn save" style="padding: 20px; font-weight: 600;">Save Driver</button>
<button type="button" class="submit-btn cancel" id="cancelDriverBtn" style="padding: 20px; font-weight: 600;">Cancel</button>
</p>
</form>
</section>
<!-- Manage Ambulance Section -->
<section id="manageAmbulanceSection" class="manage-section hidden">
<h2 id="ambulanceFormTitle" style="margin-bottom: 20px;">Add Ambulance</h2>
<form id="ambulanceForm">
<input type="hidden" id="ambulanceIndex" name="ambulanceIndex">
<div class="form-group">
<label for="ambulanceID">Ambulance ID:</label>
<input type="text" id="ambulanceID" name="ambulanceID" required placeholder="Enter ambulance ID">
</div>
<div class="form-group">
<label for="ambulanceStatus">Status:</label>
<select id="ambulanceStatusSelect" name="ambulanceStatus" required>
<option value="" disabled selected>Select status</option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
<div class="form-group">
<label for="ambulanceLocation">Location:</label>
<input type="text" id="ambulanceLocation" name="ambulanceLocation" placeholder="e.g., Location ABC" required>
</div>
<p class="button-container">
<button type="submit" class="submit-btn save" style="padding: 20px; font-weight: 600;">Save Ambulance</button>
<button type="button" class="submit-btn cancel" id="cancelAmbulanceBtn" style="padding: 20px; font-weight: 600;">Cancel</button>
</p>
</form>
</section>
</div>
</main>
<script>
// Elements
const addDriverBtn = document.getElementById('addDriverBtn');
const addAmbulanceBtn = document.getElementById('addAmbulanceBtn');
const manageDriverSection = document.getElementById('manageDriverSection');
const manageAmbulanceSection = document.getElementById('manageAmbulanceSection');
const driverForm = document.getElementById('driverForm');
const ambulanceForm = document.getElementById('ambulanceForm');
const cancelDriverBtn = document.getElementById('cancelDriverBtn');
const cancelAmbulanceBtn = document.getElementById('cancelAmbulanceBtn');
const driverFormTitle = document.getElementById('driverFormTitle');
const ambulanceFormTitle = document.getElementById('ambulanceFormTitle');
// Function to show a section
function showSection(section) {
section.classList.remove('hidden');
section.classList.add('active');
}
// Dropdown
let flag = false
document.getElementById('dropdown').addEventListener('click', () => {
const dropdown = document.querySelector('.dropdown-menu');
if (flag) {
dropdown.style.display = 'none';
flag = false;
} else {
dropdown.style.display = 'block';
flag = true;
}
});
// Function to hide a section
function hideSection(section) {
section.classList.add('hidden');
section.classList.remove('active');
}
// Event Listeners for Add Buttons
addDriverBtn.addEventListener('click', () => {
driverForm.reset();
document.getElementById('driverIndex').value = '';
driverFormTitle.textContent = 'Add Driver';
showSection(manageDriverSection);
hideSection(manageAmbulanceSection); // Hide ambulance section
});
addAmbulanceBtn.addEventListener('click', () => {
ambulanceForm.reset();
document.getElementById('ambulanceIndex').value = '';
ambulanceFormTitle.textContent = 'Add Ambulance';
showSection(manageAmbulanceSection);
hideSection(manageDriverSection); // Hide driver section
});
// Event Listeners for Cancel Buttons
cancelDriverBtn.addEventListener('click', () => {
hideSection(manageDriverSection);
});
cancelAmbulanceBtn.addEventListener('click', () => {
hideSection(manageAmbulanceSection);
});
// Handle Driver Form Submission
// Handle Driver Form Submission
driverForm.addEventListener('submit', (e) => {
e.preventDefault();
const driverName = document.getElementById('driverName').value.trim();
const driverStatus = document.getElementById('driverStatusSelect').value;
const driverContact = document.getElementById('driverContact').value;
const driverLocation = document.getElementById('driverLocation').value.trim();
const driverIndex = document.getElementById('driverIndex').value;
let drivers = JSON.parse(localStorage.getItem('drivers')) || [];
// Function to check if driver already exists
const driverExists = (name, contact, location) => {
return drivers.some(driver =>
driver.name.toLowerCase() === name.toLowerCase() &&
driver.contact === contact &&
driver.location.toLowerCase() === location.toLowerCase()
);
};
if (driverIndex === '') {
// Check for duplicate when adding a new driver
if (driverExists(driverName, driverContact, driverLocation)) {
alert(`A driver with the name "${driverName}", contact "${driverContact}", and location "${driverLocation}" already exists.`);
return; // Exit the function without adding the driver
}
// Add New Driver
drivers.push({
name: driverName,
status: driverStatus,
contact: driverContact,
location: driverLocation
});
alert(`Driver ${driverName} has been added.`);
} else {
// Edit Existing Driver
const originalDriver = drivers[driverIndex];
if (
originalDriver.name !== driverName ||
originalDriver.contact !== driverContact ||
originalDriver.location !== driverLocation
) {
// Check for duplicate only if name, contact, or location has changed
if (driverExists(driverName, driverContact, driverLocation)) {
alert(`A driver with the name "${driverName}", contact "${driverContact}", and location "${driverLocation}" already exists.`);
return; // Exit the function without updating the driver
}
}
drivers[driverIndex] = {
name: driverName,
status: driverStatus,
contact: driverContact,
location: driverLocation
};
alert(`Driver ${driverName} has been updated.`);
}
localStorage.setItem('drivers', JSON.stringify(drivers));
hideSection(manageDriverSection);
});
// Handle Ambulance Form Submission
ambulanceForm.addEventListener('submit', (e) => {
e.preventDefault();
const ambulanceID = document.getElementById('ambulanceID').value.trim();
const ambulanceStatus = document.getElementById('ambulanceStatusSelect').value;
const ambulanceLocation = document.getElementById('ambulanceLocation').value.trim();
const ambulanceIndex = document.getElementById('ambulanceIndex').value;
let ambulances = JSON.parse(localStorage.getItem('ambulances')) || [];
if (ambulanceIndex === '') {
// Add New Ambulance
ambulances.push({
id: ambulanceID,
status: ambulanceStatus,
location: ambulanceLocation
});
alert(`Ambulance ${ambulanceID} has been added.`);
} else {
// Edit Existing Ambulance
ambulances[ambulanceIndex] = {
id: ambulanceID,
status: ambulanceStatus,
location: ambulanceLocation
};
alert(`Ambulance ${ambulanceID} has been updated.`);
}
localStorage.setItem('ambulances', JSON.stringify(ambulances));
hideSection(manageAmbulanceSection);
});
// Function to populate form for editing Driver
function populateDriverForm(index) {
const drivers = JSON.parse(localStorage.getItem('drivers')) || [];
const driver = drivers[index];
if (driver) {
document.getElementById('driverName').value = driver.name;
document.getElementById('driverStatusSelect').value = driver.status;
document.getElementById('driverContact').value = driver.contact;
document.getElementById('driverLocation').value = driver.location;
document.getElementById('driverIndex').value = index;
driverFormTitle.textContent = `Edit Driver: ${driver.name}`;
showSection(manageDriverSection);
}
}
// Function to populate form for editing Ambulance
function populateAmbulanceForm(index) {
const ambulances = JSON.parse(localStorage.getItem('ambulances')) || [];
const ambulance = ambulances[index];
if (ambulance) {
document.getElementById('ambulanceID').value = ambulance.id;
document.getElementById('ambulanceStatusSelect').value = ambulance.status;
document.getElementById('ambulanceLocation').value = ambulance.location;
document.getElementById('ambulanceIndex').value = index;
ambulanceFormTitle.textContent = `Edit Ambulance: ${ambulance.id}`;
showSection(manageAmbulanceSection);
}
}
// Populate forms if accessed via query parameters for editing
window.onload = () => {
const params = new URLSearchParams(window.location.search);
const type = params.get('type');
const index = params.get('index');
if (type && index !== null) {
if (type === 'driver') {
populateDriverForm(index);
} else if (type === 'ambulance') {
populateAmbulanceForm(index);
}
}
};
document.getElementById('logout').addEventListener('click', () => {
cf = confirm('Are you sure you want to logout?');
if (cf) {
localStorage.removeItem('userID');
localStorage.removeItem('JWTtoken');
window.location.href = 'index.html';
alert("Logged out successfully!");
} else return
});
// Logout (for small screens)
function logout1(){
cf = confirm('Are you sure you want to logout?');
if (cf) {
localStorage.removeItem('userID');
localStorage.removeItem('JWTtoken');
window.location.href = 'index.html';
alert("Logged out successfully!");
} else return
}
</script>
</body>
</html>