Dashboard Fach hinzufügen funktioniert in swe-b1-a-dev
This commit is contained in:
committed by
Matthias Grief
parent
a04936f59e
commit
77e91ae393
116
swe-b1-a-dev/webseite/dashboard/js/main.js
Normal file
116
swe-b1-a-dev/webseite/dashboard/js/main.js
Normal file
@@ -0,0 +1,116 @@
|
||||
// Modal management
|
||||
export function openSubjectModal() {
|
||||
fetch('components/modals/subject-modal.php')
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
document.getElementById('modalContainer').innerHTML = html;
|
||||
document.querySelector('.modal-overlay').classList.remove('hidden');
|
||||
document.querySelector('.modal').classList.add('active');
|
||||
});
|
||||
}
|
||||
|
||||
export function openTopicModal() {
|
||||
console.log('Opening topic modal...'); // Debug log
|
||||
fetch('components/modals/topic-modal.php')
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
document.getElementById('modalContainer').innerHTML = html;
|
||||
document.querySelector('.modal-overlay').classList.remove('hidden');
|
||||
document.querySelector('.modal').classList.add('active');
|
||||
// Initialize topic manager after modal is loaded
|
||||
const event = new CustomEvent('openTopicModal');
|
||||
document.dispatchEvent(event);
|
||||
})
|
||||
.catch(error => console.error('Error loading topic modal:', error));
|
||||
}
|
||||
|
||||
export function openTopicEditorModal() {
|
||||
fetch('components/modals/topic-editor-modal.php')
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
document.getElementById('modalContainer').innerHTML = html;
|
||||
document.querySelector('.modal-overlay').classList.remove('hidden');
|
||||
document.querySelector('.modal').classList.add('active');
|
||||
// Initialize topic editor
|
||||
const event = new CustomEvent('openTopicEditorModal');
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function closeModal() {
|
||||
document.querySelector('.modal-overlay').classList.add('hidden');
|
||||
document.querySelector('.modal').classList.remove('active');
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadRecentActivity();
|
||||
});
|
||||
|
||||
async function loadRecentActivity() {
|
||||
try {
|
||||
const response = await fetch('api/get-recent-activity.php');
|
||||
const activities = await response.json();
|
||||
displayActivities(activities);
|
||||
} catch (error) {
|
||||
console.error('Error loading recent activities:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function displayActivities(activities) {
|
||||
const container = document.getElementById('recentActivity');
|
||||
container.innerHTML = activities.map(activity => `
|
||||
<div class="flex items-center gap-4 p-4 bg-gray-50 rounded-lg">
|
||||
<i class="fas ${activity.icon} text-blue-500"></i>
|
||||
<div>
|
||||
<p class="font-medium">${activity.title}</p>
|
||||
<p class="text-sm text-gray-600">${activity.timestamp}</p>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function handleSubjectSubmit(event) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Ensure icon is included
|
||||
/*
|
||||
const selectedIcon = document.getElementById('selectedIcon').value;
|
||||
if (!selectedIcon) {
|
||||
alert('Bitte wählen Sie ein Icon aus');
|
||||
return;
|
||||
}
|
||||
formData.set('icon', selectedIcon);
|
||||
*/
|
||||
|
||||
try {
|
||||
console.log('Form data before submit:', Object.fromEntries(formData));
|
||||
|
||||
const response = await fetch('api/create-subject.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('Server response:', result);
|
||||
|
||||
if (result.success) {
|
||||
closeModal();
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('Fehler beim Erstellen des Fachs: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating subject:', error);
|
||||
alert('Ein Fehler ist aufgetreten: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Make functions available globally
|
||||
window.openSubjectModal = openSubjectModal;
|
||||
window.openTopicModal = openTopicModal;
|
||||
window.closeModal = closeModal;
|
||||
window.handleSubjectSubmit = handleSubjectSubmit;
|
||||
window.openTopicEditorModal = openTopicEditorModal;
|
||||
Reference in New Issue
Block a user