Skip to content
Snippets Groups Projects
Commit dfe2f753 authored by Burhan Akbar's avatar Burhan Akbar Committed by Burhan Akbar
Browse files

Merge branch 'ba' into 'main'

Add and delete hospital
added navigation
See merge request !75
parents 3fea89fe d45b27e6
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,10 @@ $(document).ready(function () {
<nav class="top-nav">
<div class="nav-brand">Digital Insight for Health</div>
<div class="nav-items">
<a href="/dashboard" class="nav-link">
<a href="/superAdminView.html?type=hospital" class="nav-link">
<i class="fas fa-home"></i> Home
</a>
<a href="/beds" class="nav-link active">
<a href="/beds.html" class="nav-link active">
<i class="fas fa-bed"></i> Beds
</a>
<button class="nav-link sign-out" onclick="handleSignOut()">
......@@ -95,7 +95,47 @@ $(document).ready(function () {
});
// Form Submit Handler
$("#hospitalForm").submit(handleFormSubmit);
$("#hospitalForm").submit(function(e) {
e.preventDefault();
const formData = {
name: $("#hospitalName").val(),
location: $("#hospitalLocation").val(),
address: $("#hospitalLocation").val(), // Match DB schema
phone: $("#hospitalPhone").val(),
totalBeds: parseInt($("#totalBeds").val()),
availableBeds: parseInt($("#availableBeds").val()),
type: 'hospital',
status: 1,
roleId: 3,
email: '',
password: '$2a$10$wvAZoj4V51MH/MLhVIrnG.NrY07/.Gn9Ar6JsyzRAubWtqbWzgKie'
};
if (!validateFormData(formData)) {
showError('Please fill all required fields');
return;
}
$.ajax({
url: API_BASE_URL,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(formData),
success: function(response) {
if(response && response.code === 1) {
$("#hospitalModal").fadeOut();
loadHospitals();
showSuccess('Hospital added successfully');
} else {
showError(response.msg || DEFAULT_ERROR);
}
},
error: function(xhr, status, error) {
console.error('API Error:', error);
showError(DEFAULT_ERROR);
}
});
});
// Delete Handler
$(document).on('click', '.delete-btn', function() {
......@@ -105,15 +145,16 @@ $(document).ready(function () {
url: `${API_BASE_URL}/${id}`,
method: 'DELETE',
success: function(response) {
if(response.code === 200) {
if(response && response.code === 1) {
loadHospitals();
showSuccess('Hospital deleted successfully');
} else {
alert(response.msg || 'Delete failed');
showError(response.msg || 'Delete failed');
}
},
error: function(xhr) {
alert('Delete failed');
console.error('Delete Error:', xhr);
showError('Failed to delete hospital');
}
});
}
......@@ -191,6 +232,27 @@ $(document).ready(function () {
$('#hospitalTable tbody').html(`<tr><td colspan="8" class="text-center text-danger">${message}</td></tr>`);
}
function validateFormData(data) {
return data.name &&
data.location &&
data.phone &&
data.totalBeds > 0 &&
data.availableBeds >= 0 &&
data.availableBeds <= data.totalBeds;
}
function showSuccess(message) {
const alert = `
<div class="alert alert-success">
${message}
</div>
`;
$('.table-container').before(alert);
setTimeout(() => {
$('.alert').fadeOut().remove();
}, 3000);
}
// Add CSS for new components
const styles = `
.top-nav {
......@@ -273,5 +335,5 @@ $(document).ready(function () {
function handleSignOut() {
localStorage.clear();
window.location.href = '/login';
window.location.href = '/login.html';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment