huge update

This commit is contained in:
sankalp committed 2025-04-20 17:46:30 +05:45
1 parent dbc0a7d695
commit a5d938b3b0
123 files changed
+25119 -4984

No files matched your search

+332
View File
@@ -0,0 +1,332 @@
import { showToast } from '../utils/notifications.js';
// Meeting status badge helper
function getStatusBadgeClass(status) {
switch (status) {
case 'scheduled':
return 'bg-primary';
case 'completed':
return 'bg-success';
case 'cancelled':
return 'bg-danger';
case 'rescheduled':
return 'bg-warning';
default:
return 'bg-secondary';
}
}
// Meeting Modal Functions
function openAddMeetingModal() {
document.getElementById('addMeetingModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeAddMeetingModal() {
document.getElementById('addMeetingModal').style.display = 'none';
document.body.style.overflow = '';
document.getElementById('addMeetingForm').reset();
}
function openEditMeetingModal(meetingId) {
fetch(`/app/api/hod/meetings/${meetingId}/`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.json();
})
.then(data => {
document.getElementById('editMeetingId').value = meetingId;
document.getElementById('editMeetingDate').value = data.meeting_date;
document.getElementById('editMeetingTime').value = data.meeting_time;
document.getElementById('editDuration').value = data.duration;
document.getElementById('editAgenda').value = data.agenda || '';
document.getElementById('editIsOnline').checked = data.is_online;
document.getElementById('editMeetingLink').value = data.meeting_link || '';
document.getElementById('editNotes').value = data.notes || '';
if (data.is_online) {
document.getElementById('editMeetingLinkContainer').style.display = 'block';
} else {
document.getElementById('editMeetingLinkContainer').style.display = 'none';
}
// Show modal using direct style manipulation
document.getElementById('editMeetingModal').style.display = 'block';
document.body.style.overflow = 'hidden';
})
.catch(error => {
console.error('Error fetching meeting details:', error);
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Error', 'Failed to load meeting details');
} else if (typeof showToast === 'function') {
showToast('error', 'Failed to load meeting details');
} else {
alert('Failed to load meeting details');
}
});
}
function closeEditMeetingModal() {
document.getElementById('editMeetingModal').style.display = 'none';
document.body.style.overflow = '';
document.getElementById('editMeetingForm').reset();
}
function openCancelMeetingModal(meetingId) {
document.getElementById('cancelMeetingId').value = meetingId;
document.getElementById('cancellationReason').value = '';
document.getElementById('cancelMeetingModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeCancelMeetingModal() {
document.getElementById('cancelMeetingModal').style.display = 'none';
document.body.style.overflow = '';
document.getElementById('cancelMeetingForm').reset();
}
function viewMeetingDetails(meetingId) {
fetch(`/app/api/hod/meetings/${meetingId}/`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.json();
})
.then(data => {
document.getElementById('viewMeetingDate').textContent = new Date(data.meeting_date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
document.getElementById('viewMeetingTime').textContent = new Date('1970-01-01T' + data.meeting_time).toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' });
document.getElementById('viewMeetingDuration').textContent = `${data.duration} minutes`;
document.getElementById('viewMeetingStatus').innerHTML = `<span class="badge ${getStatusBadgeClass(data.status)}">${data.status_display}</span>`;
document.getElementById('viewMeetingAgenda').textContent = data.agenda || 'No agenda available';
document.getElementById('viewMeetingNotes').textContent = data.notes || 'No notes available';
document.getElementById('viewMeetingType').textContent = data.is_online ? 'Online Meeting' : 'In-Person Meeting';
if (data.is_online && data.meeting_link) {
document.getElementById('viewMeetingLinkContainer').style.display = 'block';
document.getElementById('viewMeetingLink').innerHTML = `<a href="${data.meeting_link}" target="_blank">${data.meeting_link}</a>`;
} else {
document.getElementById('viewMeetingLinkContainer').style.display = 'none';
}
// Handle cancellation reason
const cancellationContainer = document.getElementById('viewCancellationReasonContainer');
const cancellationReason = document.getElementById('viewCancellationReason');
if (data.status === 'cancelled' && data.cancellation_reason) {
cancellationContainer.style.display = 'block';
cancellationReason.textContent = data.cancellation_reason;
} else {
cancellationContainer.style.display = 'none';
}
// Set up edit button
const editBtn = document.getElementById('editMeetingBtn');
if (editBtn) {
editBtn.onclick = () => {
closeViewMeetingModal();
openEditMeetingModal(meetingId);
};
}
// Show modal using direct style manipulation
const modal = document.getElementById('viewMeetingModal');
if (modal) {
modal.style.display = 'block';
document.body.style.overflow = 'hidden';
} else {
console.error('Modal element not found!');
alert('Error: Modal element not found in the page.');
}
})
.catch(error => {
console.error('Error fetching meeting details:', error);
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Error', 'Failed to load meeting details');
} else if (typeof showToast === 'function') {
showToast('error', 'Failed to load meeting details');
} else {
alert('Failed to load meeting details');
}
});
}
function closeViewMeetingModal() {
document.getElementById('viewMeetingModal').style.display = 'none';
document.body.style.overflow = '';
}
function submitAddMeetingForm() {
const form = document.getElementById('addMeetingForm');
const formData = new FormData(form);
// IMPORTANT: Ensure meeting_link is always sent and not null
if (!formData.has('meeting_link') || formData.get('meeting_link') === null) {
formData.set('meeting_link', '');
}
fetch('/app/api/hod/meetings/', {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.json();
})
.then(data => {
closeAddMeetingModal();
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Success', 'Meeting scheduled successfully');
} else if (typeof showToast === 'function') {
showToast('success', 'Meeting scheduled successfully');
} else {
alert('Meeting scheduled successfully');
}
setTimeout(() => {
location.reload();
}, 1500);
})
.catch(error => {
console.error('Error scheduling meeting:', error);
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Error', 'Failed to schedule meeting. Please try again.');
} else if (typeof showToast === 'function') {
showToast('error', 'Failed to schedule meeting. Please try again.');
} else {
alert('Failed to schedule meeting. Please try again.');
}
});
}
function submitEditMeetingForm() {
const form = document.getElementById('editMeetingForm');
const formData = new FormData(form);
const meetingId = document.getElementById('editMeetingId').value;
// Update is_online to be a string
formData.set('is_online', document.getElementById('editIsOnline').checked ? 'true' : 'false');
// IMPORTANT: Always include meeting_link (empty string if not online) to satisfy NOT NULL constraint
if (!formData.has('meeting_link') || formData.get('meeting_link') === null) {
formData.set('meeting_link', '');
}
// Ensure notes field is included
if (document.getElementById('editNotes')) {
formData.set('notes', document.getElementById('editNotes').value || '');
}
console.log("Submitting edit meeting form for meeting ID:", meetingId);
fetch(`/app/api/hod/meetings/${meetingId}/edit/`, {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => {
if (!response.ok) {
return response.text().then(text => {
console.error("Server response:", text);
throw new Error('Server error: ' + response.status);
});
}
return response.json();
})
.then(data => {
// Close modal using direct style manipulation (not Bootstrap)
document.getElementById('editMeetingModal').style.display = 'none';
document.body.style.overflow = '';
document.getElementById('editMeetingForm').reset();
// Show success message
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Success', 'Meeting updated successfully');
} else if (typeof showToast === 'function') {
showToast('success', 'Meeting updated successfully');
} else {
alert('Meeting updated successfully');
}
// Reload the page after a short delay
setTimeout(() => {
location.reload();
}, 1500);
})
.catch(error => {
console.error('Error updating meeting:', error);
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Error', 'Failed to update meeting. Please try again.');
} else if (typeof showToast === 'function') {
showToast('error', 'Failed to update meeting. Please try again.');
} else {
alert('Failed to update meeting. Please try again.');
}
});
}
function submitCancelMeetingForm() {
const form = document.getElementById('cancelMeetingForm');
const formData = new FormData(form);
const meetingId = document.getElementById('cancelMeetingId').value;
fetch(`/app/api/hod/meetings/${meetingId}/cancel/`, {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.json();
})
.then(data => {
closeCancelMeetingModal();
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Success', 'Meeting cancelled successfully');
} else if (typeof showToast === 'function') {
showToast('success', 'Meeting cancelled successfully');
} else {
alert('Meeting cancelled successfully');
}
setTimeout(() => {
location.reload();
}, 1500);
})
.catch(error => {
console.error('Error cancelling meeting:', error);
if (typeof window.showMessageModal === 'function') {
window.showMessageModal('Error', 'Failed to cancel meeting. Please try again.');
} else if (typeof showToast === 'function') {
showToast('error', 'Failed to cancel meeting. Please try again.');
} else {
alert('Failed to cancel meeting. Please try again.');
}
});
}
// Export functions
export {
getStatusBadgeClass,
openAddMeetingModal,
closeAddMeetingModal,
openEditMeetingModal,
closeEditMeetingModal,
openCancelMeetingModal,
closeCancelMeetingModal,
viewMeetingDetails,
closeViewMeetingModal,
submitAddMeetingForm,
submitEditMeetingForm,
submitCancelMeetingForm
};
+247
View File
@@ -0,0 +1,247 @@
import { showToast, showMessageModal } from '../utils/notifications.js';
// Staff Modal Functions
function openAddStaffModal() {
document.getElementById('addStaffModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeAddStaffModal() {
document.getElementById('addStaffModal').style.display = 'none';
document.getElementById('addStaffForm').reset();
document.body.style.overflow = '';
}
function openViewStaffModal(staffId) {
fetch(`/app/staff/${staffId}/`)
.then(response => response.json())
.then(data => {
if (data.success) {
const staff = data.staff;
const profilePicture = document.getElementById('staffProfilePicture');
profilePicture.src = staff.image || "/static/img/user.png";
// Basic Information
document.getElementById('staffName').textContent = staff.name || '-';
document.getElementById('staffDesignation').textContent = staff.designation || '-';
document.getElementById('staffEmail').textContent = staff.email || '-';
document.getElementById('staffPhone').textContent = staff.phone || '-';
document.getElementById('staffGender').textContent = staff.gender || '-';
document.getElementById('staffBirthDate').textContent = staff.birth_date || '-';
document.getElementById('staffMaritalStatus').textContent = staff.marital_status || '-';
// Additional Information
document.getElementById('staffJoiningDate').textContent = staff.joining_date || '-';
document.getElementById('staffStatus').textContent = staff.is_active ? 'Active' : 'Inactive';
document.getElementById('staffParentName').textContent = staff.parent_name || '-';
document.getElementById('staffParentPhone').textContent = staff.parent_phone || '-';
document.getElementById('staffCitizenshipNo').textContent = staff.citizenship_no || '-';
document.getElementById('staffPassport').textContent = staff.passport || '-';
// Address Information
document.getElementById('staffTemporaryAddress').textContent = staff.temporary_address || '-';
document.getElementById('staffPermanentAddress').textContent = staff.permanent_address || '-';
// Assigned Subjects
const subjectsContainer = document.getElementById('staffSubjects');
subjectsContainer.innerHTML = '';
if (staff.subjects && staff.subjects.length > 0) {
staff.subjects.forEach(subject => {
const badge = document.createElement('span');
badge.className = 'badge bg-primary';
badge.textContent = subject.name;
subjectsContainer.appendChild(badge);
});
} else {
subjectsContainer.innerHTML = '<span class="text-muted">No subjects assigned</span>';
}
document.getElementById('viewStaffModal').style.display = 'block';
document.body.style.overflow = 'hidden';
} else {
showMessageModal('Error', data.message);
}
})
.catch(error => {
showMessageModal('Error', 'Failed to fetch staff details.');
});
}
function closeViewStaffModal() {
document.getElementById('viewStaffModal').style.display = 'none';
document.body.style.overflow = '';
}
function openEditStaffModal(staffId) {
fetch(`/app/staff/${staffId}/`)
.then(response => response.json())
.then(data => {
if (data.success) {
const staff = data.staff;
document.getElementById('editStaffId').value = staff.id;
document.getElementById('editStaffName').value = staff.name;
document.getElementById('editStaffEmail').value = staff.email;
document.getElementById('editStaffPhone').value = staff.phone;
document.getElementById('editStaffStatus').value = staff.is_active;
document.getElementById('editStaffProfilePicture').src = staff.image || "/static/img/user.png";
// Set selected subjects
const subjectsSelect = document.getElementById('editStaffSubjects');
if (staff.subjects && staff.subjects.length > 0) {
Array.from(subjectsSelect.options).forEach(option => {
option.selected = staff.subjects.some(subject => subject.id === parseInt(option.value));
});
}
document.getElementById('editStaffModal').style.display = 'block';
document.body.style.overflow = 'hidden';
} else {
showMessageModal('Error', data.message);
}
})
.catch(error => {
showMessageModal('Error', 'Failed to fetch staff details.');
});
}
function closeEditStaffModal() {
document.getElementById('editStaffModal').style.display = 'none';
document.getElementById('editStaffForm').reset();
document.body.style.overflow = '';
}
function submitAddStaffForm() {
const form = document.getElementById('addStaffForm');
const formData = new FormData(form);
fetch('/app/add-staff/', {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => response.json())
.then(data => {
closeAddStaffModal();
showMessageModal('Success', data.message);
// Refresh the staff table
location.reload();
})
.catch(error => {
showMessageModal('Error', 'Failed to add staff member.');
});
}
function submitEditStaffForm() {
const form = document.getElementById('editStaffForm');
const formData = new FormData(form);
const staffId = document.getElementById('editStaffId').value;
fetch(`/app/staff/${staffId}/edit/`, {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => response.json())
.then(data => {
closeEditStaffModal();
showMessageModal('Success', data.message);
// Refresh the staff table
location.reload();
})
.catch(error => {
showMessageModal('Error', 'Failed to update staff member.');
});
}
function confirmDeleteStaff(staffId) {
// Display the confirmation modal
const confirmationModal = document.getElementById('confirmationModal');
const confirmDeleteBtn = document.getElementById('confirmDeleteBtn');
// Update confirmation message
const messageElement = confirmationModal.querySelector('div p');
messageElement.textContent = 'Are you sure you want to delete this staff member? This action cannot be undone.';
// Show the modal
confirmationModal.style.display = 'block';
document.body.style.overflow = 'hidden';
// Set up the delete button action
confirmDeleteBtn.onclick = function() {
// Get CSRF token
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
// Send DELETE request
fetch(`/app/delete-staff/${staffId}/`, {
method: 'DELETE',
headers: {
'X-CSRFToken': csrfToken,
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Show success message
showToast('success', data.message);
// Reload the page after successful deletion
setTimeout(() => window.location.reload(), 1500);
} else {
// Show error message
showToast('error', data.message || 'Error deleting staff member');
}
})
.catch(error => {
console.error('Error:', error);
showToast('error', 'An error occurred while deleting the staff member');
})
.finally(() => {
// Close the modal
closeConfirmationModal();
});
};
}
// Helper function to close the confirmation modal
function closeConfirmationModal() {
document.getElementById('confirmationModal').style.display = 'none';
document.body.style.overflow = '';
}
// Helper function to show toast messages
function showToast(type, message) {
// Assuming you have a toast notification system
// If not, you can implement one or use browser's alert
if (typeof Toastify === 'function') {
Toastify({
text: message,
duration: 3000,
gravity: "top",
position: 'right',
backgroundColor: type === 'success' ? '#4caf50' : '#f44336'
}).showToast();
} else {
alert(message);
}
}
// Make functions available globally
window.closeConfirmationModal = closeConfirmationModal;
window.confirmDeleteStaff = confirmDeleteStaff;
// Export functions
export {
openAddStaffModal,
closeAddStaffModal,
openViewStaffModal,
closeViewStaffModal,
openEditStaffModal,
closeEditStaffModal,
submitAddStaffForm,
submitEditStaffForm,
confirmDeleteStaff
};
+141
View File
@@ -0,0 +1,141 @@
import { showToast, showMessageModal } from '../utils/notifications.js';
// Student Modal Functions
function openAddStudentModal() {
document.getElementById('addStudentModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeAddStudentModal() {
document.getElementById('addStudentModal').style.display = 'none';
document.body.style.overflow = '';
document.getElementById('addStudentForm').reset();
}
function openEditStudentModal(studentId) {
loadStudentData(studentId);
document.getElementById('editStudentModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeEditStudentModal() {
document.getElementById('editStudentModal').style.display = 'none';
document.body.style.overflow = '';
document.getElementById('editStudentForm').reset();
}
function openViewStudentModal(studentId) {
loadStudentViewData(studentId);
document.getElementById('viewStudentModal').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeViewStudentModal() {
document.getElementById('viewStudentModal').style.display = 'none';
document.body.style.overflow = '';
}
// Function to load student data for edit modal
function loadStudentData(studentId) {
fetch(`/app/get-student/${studentId}/`)
.then(response => response.json())
.then(data => {
if (data.success) {
const student = data.student;
document.getElementById('edit_student_id').value = student.id;
document.getElementById('edit_name').value = student.name;
document.getElementById('edit_email').value = student.email;
document.getElementById('edit_phone').value = student.phone;
document.getElementById('edit_gender').value = student.gender;
document.getElementById('edit_birth_date').value = student.birth_date;
document.getElementById('edit_admission_date').value = student.admission_date;
document.getElementById('edit_temporary_address').value = student.temporary_address;
document.getElementById('edit_permanent_address').value = student.permanent_address;
document.getElementById('edit_parent_name').value = student.parent_name;
document.getElementById('edit_parent_phone').value = student.parent_phone;
document.getElementById('edit_citizenship_no').value = student.citizenship_no;
if (student.image) {
document.getElementById('current_profile_picture').innerHTML = `
<img src="${student.image}" alt="Current Profile Picture" class="img-thumbnail" style="max-height: 100px;">
`;
}
} else {
showToast('error', data.message || 'Error loading student data');
}
})
.catch(error => {
console.error('Error:', error);
showToast('error', 'An error occurred while loading student data');
});
}
// Function to load student data for view modal
function loadStudentViewData(studentId) {
fetch(`/app/get-student/${studentId}/`)
.then(response => response.json())
.then(data => {
if (data.success) {
const student = data.student;
// Set profile picture
const profilePic = document.getElementById('view_profile_picture');
if (student.image) {
profilePic.src = student.image;
} else {
profilePic.src = '/static/img/user.png';
}
// Set basic information
document.getElementById('view_name').textContent = student.name;
document.getElementById('view_email').textContent = student.email;
document.getElementById('view_phone').textContent = student.phone;
document.getElementById('view_gender').textContent = student.gender === 'M' ? 'Male' : (student.gender === 'F' ? 'Female' : 'Other');
// Set personal information
document.getElementById('view_birth_date').textContent = student.birth_date;
document.getElementById('view_admission_date').textContent = student.admission_date;
document.getElementById('view_citizenship_no').textContent = student.citizenship_no;
// Set address information
document.getElementById('view_temporary_address').textContent = student.temporary_address;
document.getElementById('view_permanent_address').textContent = student.permanent_address;
// Set parent information
document.getElementById('view_parent_name').textContent = student.parent_name;
document.getElementById('view_parent_phone').textContent = student.parent_phone;
// Set academic information
document.getElementById('view_course').textContent = student.course_name;
document.getElementById('view_current_semester').textContent = student.current_semester;
document.getElementById('view_status').textContent = student.is_active ? 'Active' : 'Inactive';
} else {
showToast('error', data.message || 'Error loading student data');
}
})
.catch(error => {
console.error('Error:', error);
showToast('error', 'An error occurred while loading student data');
});
}
// Function to confirm and handle student deletion
function confirmDeleteStudent(studentId) {
if (confirm("Are you sure you want to delete this student? This action cannot be undone.")) {
// If confirmed, redirect to the delete URL
window.location.href = `/app/api/hod/students/${studentId}/delete/`;
}
}
// Export functions
export {
openAddStudentModal,
closeAddStudentModal,
openEditStudentModal,
closeEditStudentModal,
openViewStudentModal,
closeViewStudentModal,
loadStudentData,
loadStudentViewData,
confirmDeleteStudent
};