huge update
This commit is contained in:
123 files changed
+25119
-4984
No files matched your search
@@ -0,0 +1,256 @@
|
||||
import { showToast, showMessageModal, closeMessageModal } from './utils/notifications.js';
|
||||
import * as meetingModals from './modals/meeting.js';
|
||||
import * as studentModals from './modals/student.js';
|
||||
import * as staffModals from './modals/staff.js';
|
||||
|
||||
// Make functions available globally
|
||||
window.showToast = showToast;
|
||||
window.showMessageModal = showMessageModal;
|
||||
window.closeMessageModal = closeMessageModal;
|
||||
|
||||
// Meeting functions
|
||||
window.openAddMeetingModal = meetingModals.openAddMeetingModal;
|
||||
window.closeAddMeetingModal = meetingModals.closeAddMeetingModal;
|
||||
window.openEditMeetingModal = meetingModals.openEditMeetingModal;
|
||||
window.closeEditMeetingModal = meetingModals.closeEditMeetingModal;
|
||||
window.openCancelMeetingModal = meetingModals.openCancelMeetingModal;
|
||||
window.closeCancelMeetingModal = meetingModals.closeCancelMeetingModal;
|
||||
window.viewMeetingDetails = meetingModals.viewMeetingDetails;
|
||||
window.closeViewMeetingModal = meetingModals.closeViewMeetingModal;
|
||||
window.submitAddMeetingForm = meetingModals.submitAddMeetingForm;
|
||||
window.submitEditMeetingForm = meetingModals.submitEditMeetingForm;
|
||||
window.submitCancelMeetingForm = meetingModals.submitCancelMeetingForm;
|
||||
|
||||
// Student functions
|
||||
window.openAddStudentModal = studentModals.openAddStudentModal;
|
||||
window.closeAddStudentModal = studentModals.closeAddStudentModal;
|
||||
window.openEditStudentModal = studentModals.openEditStudentModal;
|
||||
window.closeEditStudentModal = studentModals.closeEditStudentModal;
|
||||
window.openViewStudentModal = studentModals.openViewStudentModal;
|
||||
window.closeViewStudentModal = studentModals.closeViewStudentModal;
|
||||
window.submitAddStudentForm = studentModals.submitAddStudentForm;
|
||||
window.submitEditStudentForm = studentModals.submitEditStudentForm;
|
||||
|
||||
// Staff functions
|
||||
window.openAddStaffModal = staffModals.openAddStaffModal;
|
||||
window.closeAddStaffModal = staffModals.closeAddStaffModal;
|
||||
window.openEditStaffModal = staffModals.openEditStaffModal;
|
||||
window.closeEditStaffModal = staffModals.closeEditStaffModal;
|
||||
window.openViewStaffModal = staffModals.openViewStaffModal;
|
||||
window.closeViewStaffModal = staffModals.closeViewStaffModal;
|
||||
window.submitAddStaffForm = staffModals.submitAddStaffForm;
|
||||
window.submitEditStaffForm = staffModals.submitEditStaffForm;
|
||||
|
||||
// Initialize event listeners when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Initialize duration filter for subjects
|
||||
const durationButtons = document.querySelectorAll('#durationFilter button');
|
||||
const subjectRows = document.querySelectorAll('#subjectsTableBody tr[data-period]');
|
||||
|
||||
durationButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
// Remove active class from all buttons
|
||||
durationButtons.forEach(btn => btn.classList.remove('active'));
|
||||
// Add active class to clicked button
|
||||
this.classList.add('active');
|
||||
|
||||
const selectedDuration = this.dataset.duration;
|
||||
|
||||
// Show/hide rows based on selected duration
|
||||
subjectRows.forEach(row => {
|
||||
if (selectedDuration === 'all' || row.dataset.period === selectedDuration) {
|
||||
row.style.display = '';
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
// Show/hide "no subjects" message
|
||||
const noSubjectsRow = document.querySelector('#subjectsTableBody tr:not([data-period])');
|
||||
if (noSubjectsRow) {
|
||||
const visibleRows = Array.from(subjectRows).filter(row => row.style.display !== 'none');
|
||||
noSubjectsRow.style.display = visibleRows.length === 0 ? '' : 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Initialize online meeting toggle listeners
|
||||
const isOnlineCheckbox = document.getElementById('isOnline');
|
||||
const meetingLinkContainer = document.getElementById('meetingLinkContainer');
|
||||
|
||||
if (isOnlineCheckbox) {
|
||||
isOnlineCheckbox.addEventListener('change', function() {
|
||||
meetingLinkContainer.style.display = this.checked ? 'block' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
const editIsOnlineCheckbox = document.getElementById('editIsOnline');
|
||||
const editMeetingLinkContainer = document.getElementById('editMeetingLinkContainer');
|
||||
|
||||
if (editIsOnlineCheckbox) {
|
||||
editIsOnlineCheckbox.addEventListener('change', function() {
|
||||
editMeetingLinkContainer.style.display = this.checked ? 'block' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
// Add event listeners for closing modals with Escape key
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (event.key === 'Escape') {
|
||||
const meetingNotesModal = document.getElementById('meetingNotesModal');
|
||||
const meetingAgendaModal = document.getElementById('meetingAgendaModal');
|
||||
const cancellationReasonModal = document.getElementById('cancellationReasonModal');
|
||||
const addMeetingModal = document.getElementById('addMeetingModal');
|
||||
const editMeetingModal = document.getElementById('editMeetingModal');
|
||||
const cancelMeetingModal = document.getElementById('cancelMeetingModal');
|
||||
const viewMeetingModal = document.getElementById('viewMeetingModal');
|
||||
|
||||
if (meetingNotesModal && meetingNotesModal.classList.contains('show')) {
|
||||
meetingModals.closeMeetingNotesModal();
|
||||
}
|
||||
if (meetingAgendaModal && meetingAgendaModal.classList.contains('show')) {
|
||||
meetingModals.closeMeetingAgendaModal();
|
||||
}
|
||||
if (cancellationReasonModal && cancellationReasonModal.classList.contains('show')) {
|
||||
meetingModals.closeCancellationReasonModal();
|
||||
}
|
||||
if (addMeetingModal && addMeetingModal.classList.contains('show')) {
|
||||
meetingModals.closeAddMeetingModal();
|
||||
}
|
||||
if (editMeetingModal && editMeetingModal.classList.contains('show')) {
|
||||
meetingModals.closeEditMeetingModal();
|
||||
}
|
||||
if (cancelMeetingModal && cancelMeetingModal.classList.contains('show')) {
|
||||
meetingModals.closeCancelMeetingModal();
|
||||
}
|
||||
if (viewMeetingModal && viewMeetingModal.classList.contains('show')) {
|
||||
meetingModals.closeViewMeetingModal();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize search functionality for progress section
|
||||
const progressSearchInput = document.getElementById('progressSearchInput');
|
||||
const progressSearchButton = document.getElementById('progressSearchButton');
|
||||
|
||||
if (progressSearchInput && progressSearchButton) {
|
||||
// Function to perform search
|
||||
const performSearch = () => {
|
||||
const searchTerm = progressSearchInput.value.toLowerCase().trim();
|
||||
const progressRows = document.querySelectorAll('#progressTable tbody tr');
|
||||
let visibleRowCount = 0;
|
||||
|
||||
progressRows.forEach(row => {
|
||||
// Skip the "No progress data available" row if it exists
|
||||
if (!row.querySelector('td[colspan]')) {
|
||||
// Get text content from student name and batch columns
|
||||
const studentNameCell = row.querySelector('td:nth-child(1)');
|
||||
const batchCell = row.querySelector('td:nth-child(2)');
|
||||
|
||||
const studentText = studentNameCell ? studentNameCell.textContent.toLowerCase() : '';
|
||||
const batchText = batchCell ? batchCell.textContent.toLowerCase() : '';
|
||||
|
||||
// Show row if search term is found in student name or batch
|
||||
if (searchTerm === '' ||
|
||||
studentText.includes(searchTerm) ||
|
||||
batchText.includes(searchTerm)) {
|
||||
row.style.display = '';
|
||||
visibleRowCount++;
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Show/hide "no data" message
|
||||
const noProgressDataMessage = document.getElementById('noProgressDataMessage');
|
||||
if (noProgressDataMessage) {
|
||||
noProgressDataMessage.style.display = (visibleRowCount === 0 && searchTerm !== '') ? 'block' : 'none';
|
||||
}
|
||||
|
||||
// Update summary cards with filtered data
|
||||
updateProgressSummary(progressRows, searchTerm);
|
||||
};
|
||||
|
||||
// Button click event listener
|
||||
progressSearchButton.addEventListener('click', performSearch);
|
||||
|
||||
// Enter key press event listener
|
||||
progressSearchInput.addEventListener('keyup', function(event) {
|
||||
if (event.key === 'Enter') {
|
||||
performSearch();
|
||||
}
|
||||
});
|
||||
|
||||
// Add input event listener for real-time filtering (optional)
|
||||
progressSearchInput.addEventListener('input', function() {
|
||||
// Only perform search if the input has at least 3 characters or is empty
|
||||
if (this.value.length >= 3 || this.value.length === 0) {
|
||||
performSearch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Function to update progress summary based on visible rows
|
||||
function updateProgressSummary(rows, searchTerm) {
|
||||
if (!searchTerm || searchTerm === '') {
|
||||
// If no search is applied, revert to original values
|
||||
if (document.getElementById('avgCompletion')) {
|
||||
document.getElementById('avgCompletion').textContent = originalAvgCompletion + '%';
|
||||
}
|
||||
if (document.getElementById('studentsOnTrack')) {
|
||||
document.getElementById('studentsOnTrack').textContent = originalStudentsOnTrack;
|
||||
}
|
||||
if (document.getElementById('studentsAtRisk')) {
|
||||
document.getElementById('studentsAtRisk').textContent = originalStudentsAtRisk;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let totalCompletion = 0;
|
||||
let studentsOnTrack = 0;
|
||||
let studentsAtRisk = 0;
|
||||
let visibleStudents = 0;
|
||||
|
||||
rows.forEach(row => {
|
||||
if (row.style.display !== 'none' && !row.querySelector('td[colspan]')) {
|
||||
visibleStudents++;
|
||||
|
||||
// Get completion percentage from the progress bar
|
||||
const progressCell = row.querySelector('td:nth-child(4)');
|
||||
if (progressCell) {
|
||||
const percentText = progressCell.querySelector('.small')?.textContent || '0%';
|
||||
const completionPercentage = parseFloat(percentText);
|
||||
|
||||
if (!isNaN(completionPercentage)) {
|
||||
totalCompletion += completionPercentage;
|
||||
|
||||
// Count students on track and at risk
|
||||
if (completionPercentage >= 75) {
|
||||
studentsOnTrack++;
|
||||
} else if (completionPercentage < 40) {
|
||||
studentsAtRisk++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Update summary cards with filtered data
|
||||
const avgCompletion = visibleStudents > 0 ? Math.round(totalCompletion / visibleStudents) : 0;
|
||||
|
||||
if (document.getElementById('avgCompletion')) {
|
||||
document.getElementById('avgCompletion').textContent = avgCompletion + '%';
|
||||
}
|
||||
if (document.getElementById('studentsOnTrack')) {
|
||||
document.getElementById('studentsOnTrack').textContent = studentsOnTrack;
|
||||
}
|
||||
if (document.getElementById('studentsAtRisk')) {
|
||||
document.getElementById('studentsAtRisk').textContent = studentsAtRisk;
|
||||
}
|
||||
}
|
||||
|
||||
// Store original summary values
|
||||
const originalAvgCompletion = document.getElementById('avgCompletion') ? document.getElementById('avgCompletion').textContent.replace('%', '') : '0';
|
||||
const originalStudentsOnTrack = document.getElementById('studentsOnTrack') ? document.getElementById('studentsOnTrack').textContent : '0';
|
||||
const originalStudentsAtRisk = document.getElementById('studentsAtRisk') ? document.getElementById('studentsAtRisk').textContent : '0';
|
||||
});
|
||||
@@ -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
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
* Routine management functionality for HOD dashboard
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Initialize period filter
|
||||
initPeriodFilter();
|
||||
|
||||
// Initialize action buttons for existing routines
|
||||
initRoutineActionButtons();
|
||||
});
|
||||
|
||||
/**
|
||||
* Initialize period filter buttons
|
||||
*/
|
||||
function initPeriodFilter() {
|
||||
const periodFilterButtons = document.querySelectorAll('#periodFilterButtons button');
|
||||
|
||||
periodFilterButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
// Remove active class from all buttons
|
||||
periodFilterButtons.forEach(btn => btn.classList.remove('active'));
|
||||
// Add active class to clicked button
|
||||
this.classList.add('active');
|
||||
|
||||
// Filter routines based on selected period
|
||||
const selectedPeriod = this.dataset.period;
|
||||
filterRoutineByPeriod(selectedPeriod);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize action buttons for routine rows
|
||||
*/
|
||||
function initRoutineActionButtons() {
|
||||
// Edit buttons
|
||||
document.querySelectorAll('.edit-routine-btn').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
const routineId = this.getAttribute('data-routine-id');
|
||||
openEditRoutineModal(routineId);
|
||||
});
|
||||
});
|
||||
|
||||
// Delete buttons
|
||||
document.querySelectorAll('.delete-routine-btn').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
const routineId = this.getAttribute('data-routine-id');
|
||||
openDeleteRoutineModal(routineId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter routine table based on selected period/year
|
||||
*/
|
||||
function filterRoutineByPeriod(selectedPeriod) {
|
||||
const routineRows = document.querySelectorAll('#routineTableBody tr.routine-row');
|
||||
let visibleRows = 0;
|
||||
|
||||
routineRows.forEach(row => {
|
||||
if (selectedPeriod === 'all' || row.dataset.period === selectedPeriod) {
|
||||
row.style.display = '';
|
||||
visibleRows++;
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
// Show or hide "no classes" message
|
||||
const noClassesMessage = document.getElementById('noClassesMessage');
|
||||
if (noClassesMessage) {
|
||||
noClassesMessage.style.display = visibleRows === 0 ? 'block' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open add routine modal
|
||||
*/
|
||||
function openAddRoutineModal() {
|
||||
const modal = document.getElementById('addRoutineModal');
|
||||
if (modal) {
|
||||
// Reset form
|
||||
document.getElementById('addRoutineForm').reset();
|
||||
|
||||
// Set default period/year based on subject selection
|
||||
const subjectSelect = document.getElementById('subjectId');
|
||||
if (subjectSelect) {
|
||||
subjectSelect.addEventListener('change', function() {
|
||||
const selectedOption = this.options[this.selectedIndex];
|
||||
const periodOrYear = selectedOption.textContent.match(/\((?:Semester|Year) (\d+)\)/);
|
||||
if (periodOrYear && periodOrYear[1]) {
|
||||
document.getElementById('periodOrYear').value = periodOrYear[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Show modal
|
||||
modal.style.display = 'block';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close add routine modal
|
||||
*/
|
||||
function closeAddRoutineModal() {
|
||||
const modal = document.getElementById('addRoutineModal');
|
||||
if (modal) {
|
||||
modal.style.display = 'none';
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit add routine form
|
||||
*/
|
||||
function submitAddRoutineForm() {
|
||||
const form = document.getElementById('addRoutineForm');
|
||||
if (!form) return;
|
||||
|
||||
// Create form data
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Add course_id from the page
|
||||
const courseId = document.querySelector('#routineSection').getAttribute('data-course-id');
|
||||
if (courseId) {
|
||||
formData.append('course_id', courseId);
|
||||
} else {
|
||||
// If no explicit course ID, use the current course ID from the URL
|
||||
const urlPath = window.location.pathname;
|
||||
const urlMatch = urlPath.match(/\/hod\/(\d+)/);
|
||||
if (urlMatch && urlMatch[1]) {
|
||||
formData.append('course_id', urlMatch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate form
|
||||
const subjectId = formData.get('subject_id');
|
||||
const teacherId = formData.get('teacher_id');
|
||||
const startTime = formData.get('start_time');
|
||||
const endTime = formData.get('end_time');
|
||||
|
||||
if (!subjectId || !teacherId || !startTime || !endTime) {
|
||||
showToast('error', 'Please fill in all required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
// Send request to server
|
||||
fetch('/app/api/hod/routines/', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: {
|
||||
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(data => {
|
||||
throw new Error(data.message || 'Failed to add routine');
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
showToast('success', 'Routine added successfully');
|
||||
closeAddRoutineModal();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error adding routine:', error);
|
||||
showToast('error', error.message || 'Failed to add routine');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open edit routine modal
|
||||
*/
|
||||
function openEditRoutineModal(routineId) {
|
||||
const modal = document.getElementById('editRoutineModal');
|
||||
if (!modal || !routineId) return;
|
||||
|
||||
// Fetch routine data
|
||||
fetch(`/app/api/hod/routines/${routineId}/`)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch routine data');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
// Populate form fields
|
||||
document.getElementById('editRoutineId').value = routineId;
|
||||
document.getElementById('editSubjectId').value = data.subject_id;
|
||||
document.getElementById('editTeacherId').value = data.teacher_id;
|
||||
document.getElementById('editStartTime').value = data.start_time;
|
||||
document.getElementById('editEndTime').value = data.end_time;
|
||||
document.getElementById('editPeriodOrYear').value = data.period_or_year;
|
||||
|
||||
// Show modal
|
||||
modal.style.display = 'block';
|
||||
document.body.style.overflow = 'hidden';
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching routine data:', error);
|
||||
showToast('error', error.message || 'Failed to fetch routine data');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Close edit routine modal
|
||||
*/
|
||||
function closeEditRoutineModal() {
|
||||
const modal = document.getElementById('editRoutineModal');
|
||||
if (modal) {
|
||||
modal.style.display = 'none';
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit edit routine form
|
||||
*/
|
||||
function submitEditRoutineForm() {
|
||||
const form = document.getElementById('editRoutineForm');
|
||||
if (!form) return;
|
||||
|
||||
// Get routine ID
|
||||
const routineId = document.getElementById('editRoutineId').value;
|
||||
if (!routineId) {
|
||||
showToast('error', 'Routine ID is missing');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create form data
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Validate form
|
||||
const subjectId = formData.get('subject_id');
|
||||
const teacherId = formData.get('teacher_id');
|
||||
const startTime = formData.get('start_time');
|
||||
const endTime = formData.get('end_time');
|
||||
|
||||
if (!subjectId || !teacherId || !startTime || !endTime) {
|
||||
showToast('error', 'Please fill in all required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
// Send request to server
|
||||
fetch(`/app/api/hod/routines/${routineId}/`, {
|
||||
method: 'PUT',
|
||||
body: formData,
|
||||
headers: {
|
||||
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(data => {
|
||||
throw new Error(data.message || 'Failed to update routine');
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
showToast('success', 'Routine updated successfully');
|
||||
closeEditRoutineModal();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error updating routine:', error);
|
||||
showToast('error', error.message || 'Failed to update routine');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open delete routine modal
|
||||
*/
|
||||
function openDeleteRoutineModal(routineId) {
|
||||
const modal = document.getElementById('deleteRoutineModal');
|
||||
if (!modal || !routineId) return;
|
||||
|
||||
// Set routine ID in the form
|
||||
document.getElementById('deleteRoutineId').value = routineId;
|
||||
|
||||
// Show modal
|
||||
modal.style.display = 'block';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
/**
|
||||
* Close delete routine modal
|
||||
*/
|
||||
function closeDeleteRoutineModal() {
|
||||
const modal = document.getElementById('deleteRoutineModal');
|
||||
if (modal) {
|
||||
modal.style.display = 'none';
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit delete routine form
|
||||
*/
|
||||
function submitDeleteRoutineForm() {
|
||||
const routineId = document.getElementById('deleteRoutineId').value;
|
||||
if (!routineId) {
|
||||
showToast('error', 'Routine ID is missing');
|
||||
return;
|
||||
}
|
||||
|
||||
// Send request to server
|
||||
fetch(`/app/api/hod/routines/${routineId}/`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete routine');
|
||||
}
|
||||
showToast('success', 'Routine deleted successfully');
|
||||
closeDeleteRoutineModal();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error deleting routine:', error);
|
||||
showToast('error', error.message || 'Failed to delete routine');
|
||||
});
|
||||
}
|
||||
|
||||
// Export functions for use in other files
|
||||
export {
|
||||
filterRoutineByPeriod,
|
||||
openAddRoutineModal,
|
||||
closeAddRoutineModal,
|
||||
submitAddRoutineForm,
|
||||
openEditRoutineModal,
|
||||
closeEditRoutineModal,
|
||||
submitEditRoutineForm,
|
||||
openDeleteRoutineModal,
|
||||
closeDeleteRoutineModal,
|
||||
submitDeleteRoutineForm
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
// Function to show a specific section
|
||||
function showSection(sectionId) {
|
||||
// Hide all sections
|
||||
document.querySelectorAll('.content-section').forEach(section => {
|
||||
section.style.display = 'none';
|
||||
});
|
||||
|
||||
// Show selected section
|
||||
const targetSection = document.getElementById(sectionId);
|
||||
if (targetSection) {
|
||||
targetSection.style.display = 'block';
|
||||
}
|
||||
|
||||
// Update active nav item
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
item.classList.remove('active');
|
||||
if (item.getAttribute('data-section') === sectionId.replace('Section', '')) {
|
||||
item.classList.add('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Export functions
|
||||
export { showSection };
|
||||
@@ -0,0 +1,42 @@
|
||||
// Toast notification function
|
||||
export function showToast(type, message) {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast align-items-center text-white bg-${type} border-0`;
|
||||
toast.setAttribute('role', 'alert');
|
||||
toast.setAttribute('aria-live', 'assertive');
|
||||
toast.setAttribute('aria-atomic', 'true');
|
||||
|
||||
toast.innerHTML = `
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
${message}
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const toastContainer = document.createElement('div');
|
||||
toastContainer.className = 'toast-container position-fixed bottom-0 end-0 p-3';
|
||||
toastContainer.appendChild(toast);
|
||||
document.body.appendChild(toastContainer);
|
||||
|
||||
const bsToast = new bootstrap.Toast(toast);
|
||||
bsToast.show();
|
||||
|
||||
toast.addEventListener('hidden.bs.toast', function () {
|
||||
toastContainer.remove();
|
||||
});
|
||||
}
|
||||
|
||||
// Message modal functions
|
||||
export function showMessageModal(title, message) {
|
||||
document.getElementById('messageModalTitle').textContent = title;
|
||||
document.getElementById('messageModalContent').textContent = message;
|
||||
document.getElementById('messageModal').style.display = 'block';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
export function closeMessageModal() {
|
||||
document.getElementById('messageModal').style.display = 'none';
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
Reference in new issue
Block a user