diff --git a/ticketsystem/static/js/ticket_detail.js b/ticketsystem/static/js/ticket_detail.js new file mode 100644 index 0000000..10be506 --- /dev/null +++ b/ticketsystem/static/js/ticket_detail.js @@ -0,0 +1,68 @@ +function initializeTicketDetail(config) { + // Course-Tutor Mapping + if (config.canEdit) { + const courseSelect = document.getElementById('id_course'); + const tutorText = document.getElementById('tutor_text'); + const tutorDisplay = document.getElementById('tutor_display'); + + if (courseSelect && config.courseTutorMap) { + courseSelect.addEventListener('change', function() { + const selectedCourseId = this.value; + + if (selectedCourseId && config.courseTutorMap[selectedCourseId]) { + tutorText.textContent = config.courseTutorMap[selectedCourseId]; + tutorDisplay.classList.remove('bg-gray-100'); + tutorDisplay.classList.add('bg-blue-50'); + } else if (selectedCourseId) { + tutorText.textContent = 'Kein Tutor zugewiesen'; + tutorDisplay.classList.remove('bg-blue-50'); + tutorDisplay.classList.add('bg-gray-100'); + } + }); + } + } + + // Answer Field Toggle (nur für Tutoren) + if (config.canEdit && !config.isCreator) { + const statusSelect = document.querySelector('select[name="status"]'); + const answerField = document.querySelector('textarea[name="answer"]'); + const answerLabel = answerField?.previousElementSibling; + + function toggleAnswerField() { + if (!answerField) return; + + if (statusSelect.value === 'resolved') { + answerField.disabled = false; + answerField.classList.remove('bg-gray-100', 'cursor-not-allowed'); + answerField.classList.add('bg-white'); + answerField.required = true; + + if (answerLabel && !answerLabel.querySelector('.text-red-500')) { + answerLabel.innerHTML = answerLabel.textContent + ' *'; + } + } else { + answerField.disabled = true; + answerField.classList.add('bg-gray-100', 'cursor-not-allowed'); + answerField.classList.remove('bg-white'); + answerField.required = false; + + if (answerLabel) { + answerLabel.innerHTML = answerLabel.textContent.replace(' *', ''); + } + } + } + + if (statusSelect && answerField) { + toggleAnswerField(); + statusSelect.addEventListener('change', toggleAnswerField); + } + } +} + +// Initialisierung wenn DOM geladen +document.addEventListener('DOMContentLoaded', function() { + // Config wird vom Template bereitgestellt + if (window.ticketDetailConfig) { + initializeTicketDetail(window.ticketDetailConfig); + } +}); \ No newline at end of file diff --git a/ticketsystem/templates/ticketsystem/detail.html b/ticketsystem/templates/ticketsystem/detail.html index 16cc9b2..48dc781 100644 --- a/ticketsystem/templates/ticketsystem/detail.html +++ b/ticketsystem/templates/ticketsystem/detail.html @@ -1,4 +1,5 @@ {% extends "ticketsystem/base.html" %} +{% load static %} {% block content %} {% if messages %} @@ -75,7 +76,7 @@ {% if form.status.errors %}
+ Keine Tickets gefunden für die Suche „{{ search_query }}" +
+ Alle Tickets anzeigen + {% else %} +Erstelle dein erstes Ticket um loszulegen.
+ + Erstes Ticket erstellen + + {% endif %}- Keine Tickets gefunden für die Suche „{{ search_query }}" -
- Alle Tickets anzeigen - {% else %} -Erstelle dein erstes Ticket um loszulegen.
- - Erstes Ticket erstellen - - {% endif %} -