68 lines
2.7 KiB
JavaScript
68 lines
2.7 KiB
JavaScript
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 + ' <span class="text-red-500">*</span>';
|
|
}
|
|
} 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);
|
|
}
|
|
}); |