83 lines
3.6 KiB
JavaScript
83 lines
3.6 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') {
|
|
// Antwort-Feld einblenden und aktivieren
|
|
answerField.closest('div').style.display = 'block';
|
|
answerField.disabled = false;
|
|
answerField.readOnly = false;
|
|
answerField.style.pointerEvents = 'auto'; // Erlaube Klicks
|
|
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 if (statusSelect.value === 'closed') {
|
|
// Antwort-Feld einblenden aber ausgegraut (readonly statt disabled)
|
|
answerField.closest('div').style.display = 'block';
|
|
answerField.disabled = false;
|
|
answerField.readOnly = true;
|
|
answerField.style.pointerEvents = 'none'; // Verhindert Klicks
|
|
answerField.classList.add('bg-gray-100', 'cursor-not-allowed');
|
|
answerField.classList.remove('bg-white');
|
|
answerField.required = false;
|
|
|
|
if (answerLabel) {
|
|
answerLabel.innerHTML = answerLabel.textContent.replace(' *', '');
|
|
}
|
|
} else {
|
|
// Antwort-Feld ausblenden
|
|
answerField.closest('div').style.display = 'none';
|
|
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);
|
|
}
|
|
}); |