From 63a66f6d3edd237da24ea736aaf7e4dd6880a860 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 4 Jun 2025 22:35:01 +0200 Subject: [PATCH] fix: stored js in static folder --- ticketsystem/static/js/ticket_detail.js | 68 +++++++++++ .../templates/ticketsystem/detail.html | 75 ++---------- .../templates/ticketsystem/index.html | 111 +++++++++--------- 3 files changed, 135 insertions(+), 119 deletions(-) create mode 100644 ticketsystem/static/js/ticket_detail.js 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 %}
{{ form.status.errors }}
{% endif %}
- + + class="w-full p-2 border border-gray-300 rounded shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 placeholder:text-gray-900 {% if not view.can_edit or ticket.status != 'resolved' or form.answer.field.disabled %}bg-gray-100 cursor-not-allowed{% endif %}">{{ ticket.answer|default:'' }} {% if form.answer.errors %}
{{ form.answer.errors }}
{% endif %}

- {% if ticket.status != 'resolved' or ticket.status != 'closed' %} + {% if ticket.status != 'resolved' %} Eine Antwort ist erforderlich beim Setzen des Status auf "Gelöst" {% endif %}

@@ -197,70 +198,16 @@
+ {% endblock %} diff --git a/ticketsystem/templates/ticketsystem/index.html b/ticketsystem/templates/ticketsystem/index.html index e74012a..16075fa 100644 --- a/ticketsystem/templates/ticketsystem/index.html +++ b/ticketsystem/templates/ticketsystem/index.html @@ -161,61 +161,62 @@ {% elif ticket.status == 'closed' %} {{ ticket.get_status_display }} {% endif %} - - - {{ ticket.get_mistake_display }} - - - {% if ticket.assigned_to %} - {{ ticket.assigned_to.username }} - {% else %} - Nicht zugewiesen - {% endif %} - - -
{{ ticket.created_at|date:"d.m.Y" }}
-
{{ ticket.created_at|date:"H:i" }}
- - - {% endfor %} - - - - - {% if is_paginated %} -
-
Seite {{ page_obj.number }} von {{ page_obj.paginator.num_pages }}
-
- {% if page_obj.has_previous %} - Zurück - {% endif %} - {% if page_obj.has_next %} - Weiter - {% endif %} + + + {{ ticket.get_mistake_display }} + + + + {% if ticket.assigned_to %} + {{ ticket.assigned_to.username }} + {% else %} + Nicht zugewiesen + {% endif %} + + +
{{ ticket.created_at|date:"d.m.Y" }}
+
{{ ticket.created_at|date:"H:i" }}
+ + + {% endfor %} + + +
+ + {% if is_paginated %} +
+
Seite {{ page_obj.number }} von {{ page_obj.paginator.num_pages }}
+
+ {% if page_obj.has_previous %} + Zurück + {% endif %} + {% if page_obj.has_next %} + Weiter + {% endif %} +
+ {% endif %} + {% else %} + +
+
📋
+ {% if search_query %} +

Keine Tickets gefunden

+

+ Keine Tickets gefunden für die Suche „{{ search_query }}" +

+ Alle Tickets anzeigen + {% else %} +

Noch keine Tickets vorhanden

+

Erstelle dein erstes Ticket um loszulegen.

+ + Erstes Ticket erstellen + + {% endif %}
{% endif %} - {% else %} - -
-
📋
- {% if search_query %} -

Keine Tickets gefunden

-

- Keine Tickets gefunden für die Suche „{{ search_query }}" -

- Alle Tickets anzeigen - {% else %} -

Noch keine Tickets vorhanden

-

Erstelle dein erstes Ticket um loszulegen.

- - Erstes Ticket erstellen - - {% endif %} -
- {% endif %} -
-{% endblock %} + + {% endblock %}