Filter bleibt offen wenn man auf filtern drückt

This commit is contained in:
Juhn-Vitus Saß
2025-04-22 11:46:44 +02:00
parent 97e4fa9505
commit b1e438229a

View File

@@ -51,28 +51,29 @@
<div id="filterPanel" class="container mx-auto px-4"> <div id="filterPanel" class="container mx-auto px-4">
<div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200"> <div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200">
<form method="get" class="grid grid-cols-1 md:grid-cols-3 gap-6"> <form action="{% url 'library:overview_quiz' %}" method="get" class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="space-y-2"> <input type="hidden" name="filter" value="1">
<label class="block text-sm font-medium text-gray-700">minimale Anzahl an Fragen</label> <div class="space-y-2">
{{ form.min_amout_questions }} <label class="block text-sm font-medium text-gray-700">minimale Anzahl an Fragen</label>
</div> <input type="number" name="min_amout_questions" class="border-2 border-gray-300 rounded-lg p-2 w-full" min="1" id="id_min_amout_questions">
<div class="space-y-2"> </div>
<label class="block text-sm font-medium text-gray-700">maximale Anzahl an Fragen</label> <div class="space-y-2">
{{ form.max_amout_questions }} <label class="block text-sm font-medium text-gray-700">maximale Anzahl an Fragen</label>
</div> <input type="number" name="max_amout_questions" class="border-2 border-gray-300 rounded-lg p-2 w-full" min="1" id="id_max_amout_questions">
<div class="space-y-2"> </div>
<label class="block text-sm font-medium text-gray-700">veröffentlicht von User</label> <div class="space-y-2">
{{ form.user }} <label class="block text-sm font-medium text-gray-700">veröffentlicht von User</label>
</div> <input type="text" name="user" class="border-2 border-gray-300 rounded-lg p-2 w-full" id="id_user">
<div class="md:col-span-3 flex justify-end"> </div>
<button type="submit" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors duration-200"> <div class="md:col-span-3 flex justify-end">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <button type="submit" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors duration-200">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" /> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
</svg> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"></path>
Filtern </svg>
</button> Filtern
</div> </button>
</form> </div>
</form>
</div> </div>
</div> </div>
@@ -633,11 +634,26 @@
{% endif %} {% endif %}
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('filter') === '1') {
document.getElementById('filterPanel').classList.add('show');
}
document.getElementById('filterButton').addEventListener('click', function() { document.getElementById('filterButton').addEventListener('click', function() {
document.getElementById('filterPanel').classList.toggle('show'); document.getElementById('filterPanel').classList.toggle('show');
// URL beim Öffnen aktualisieren
const params = new URLSearchParams(window.location.search);
if (document.getElementById('filterPanel').classList.contains('show')) {
params.set('filter', '1');
} else {
params.delete('filter');
}
history.replaceState(null, '', `${location.pathname}?${params}`);
}); });
}); });
if (window.location.pathname === "/library/") { if (window.location.pathname === "/library/") {
window.addEventListener("beforeunload", function () { window.addEventListener("beforeunload", function () {
localStorage.setItem("meine_seite_scroll", window.scrollY); localStorage.setItem("meine_seite_scroll", window.scrollY);