164 lines
9.4 KiB
HTML
164 lines
9.4 KiB
HTML
{% extends 'base.html' %}
|
|
|
|
{% block content %}
|
|
<div class="container mx-auto px-4">
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h1 class="text-2xl font-bold">{% if question %}Frage bearbeiten{% else %}Neue Multiple Choice Frage{% endif %}</h1>
|
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
|
class="bg-gray-100 text-gray-700 px-4 py-2 rounded-md hover:bg-gray-200 transition-colors">
|
|
Zurück zum Quiz
|
|
</a>
|
|
</div>
|
|
<div class="bg-white rounded-lg shadow-md p-6 border-blue-600 border-2 rounded-xl shadow-md">
|
|
<form method="post" class="space-y-6">
|
|
{% csrf_token %}
|
|
|
|
<!-- Question Text -->
|
|
<div>
|
|
<label for="question" class="block text-sm font-medium text-gray-700">Frage</label>
|
|
<div class="mt-1">
|
|
<textarea name="question" id="question" rows="4"
|
|
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md"
|
|
required>{{ question.data.question|default:'' }}</textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Options -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Antwortmöglichkeiten</label>
|
|
<div id="options-container" class="space-y-3">
|
|
{% if question and question.data.options %}
|
|
{% for option in question.data.options %}
|
|
<div class="flex items-center space-x-3">
|
|
<textarea name="option_{{ forloop.counter }}" rows="2"
|
|
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 flex-grow sm:text-sm border-gray-300 rounded-md"
|
|
required>{{ option.value }}</textarea>
|
|
<label class="inline-flex items-center">
|
|
<input type="checkbox" name="correct_{{ forloop.counter }}" value="1"
|
|
class="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded"
|
|
{% if option.is_correct %}checked{% endif %}>
|
|
<span class="ml-2 text-sm text-gray-600">Richtig</span>
|
|
</label>
|
|
<button type="button" onclick="removeOption(this)"
|
|
class="text-red-600 hover:text-red-800 transition-colors">
|
|
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="flex items-center space-x-3">
|
|
<textarea name="option_1" rows="2"
|
|
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 flex-grow sm:text-sm border-gray-300 rounded-md"
|
|
required></textarea>
|
|
<label class="inline-flex items-center">
|
|
<input type="checkbox" name="correct_1" value="1"
|
|
class="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded">
|
|
<span class="ml-2 text-sm text-gray-600">Richtig</span>
|
|
</label>
|
|
<button type="button" onclick="removeOption(this)"
|
|
class="text-red-600 hover:text-red-800 transition-colors">
|
|
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
<div class="flex items-center space-x-3">
|
|
<textarea name="option_2" rows="2"
|
|
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 flex-grow sm:text-sm border-gray-300 rounded-md"
|
|
required></textarea>
|
|
<label class="inline-flex items-center">
|
|
<input type="checkbox" name="correct_2" value="1"
|
|
class="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded">
|
|
<span class="ml-2 text-sm text-gray-600">Richtig</span>
|
|
</label>
|
|
<button type="button" onclick="removeOption(this)"
|
|
class="text-red-600 hover:text-red-800 transition-colors">
|
|
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
<button type="button" onclick="addOption()"
|
|
class="mt-3 inline-flex items-center px-3 py-1.5 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
|
</svg>
|
|
Option hinzufügen
|
|
</button>
|
|
</div>
|
|
|
|
<div class="flex justify-end space-x-3">
|
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
|
class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
Abbrechen
|
|
</a>
|
|
<button type="submit"
|
|
class="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
{% if question %}Speichern{% else %}Erstellen{% endif %}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function addOption() {
|
|
const container = document.getElementById('options-container');
|
|
const optionCount = container.children.length + 1;
|
|
|
|
if (optionCount > 6) {
|
|
alert('Maximal 6 Optionen sind erlaubt.');
|
|
return;
|
|
}
|
|
|
|
const div = document.createElement('div');
|
|
div.className = 'flex items-center space-x-3';
|
|
div.innerHTML = `
|
|
<textarea name="option_${optionCount}" rows="2"
|
|
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 flex-grow sm:text-sm border-gray-300 rounded-md"
|
|
required></textarea>
|
|
<label class="inline-flex items-center">
|
|
<input type="checkbox" name="correct_${optionCount}" value="1"
|
|
class="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded">
|
|
<span class="ml-2 text-sm text-gray-600">Richtig</span>
|
|
</label>
|
|
<button type="button" onclick="removeOption(this)"
|
|
class="text-red-600 hover:text-red-800 transition-colors">
|
|
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
|
</svg>
|
|
</button>
|
|
`;
|
|
|
|
container.appendChild(div);
|
|
}
|
|
|
|
function removeOption(button) {
|
|
const container = document.getElementById('options-container');
|
|
if (container.children.length > 2) {
|
|
button.parentElement.remove();
|
|
updateOptionNumbers();
|
|
} else {
|
|
alert('Mindestens zwei Optionen müssen vorhanden sein.');
|
|
}
|
|
}
|
|
|
|
function updateOptionNumbers() {
|
|
const container = document.getElementById('options-container');
|
|
const options = container.children;
|
|
Array.from(options).forEach((option, index) => {
|
|
const number = index + 1;
|
|
const textInput = option.querySelector('textarea');
|
|
const checkbox = option.querySelector('input[type="checkbox"]');
|
|
|
|
textInput.name = `option_${number}`;
|
|
checkbox.name = `correct_${number}`;
|
|
});
|
|
}
|
|
</script>
|
|
{% endblock %}
|