This commit is contained in:
Ross
2022-08-11 21:41:54 +01:00
parent 74a7de7944
commit 96ae0b9b39
5 changed files with 79 additions and 3 deletions
+1
View File
@@ -1336,6 +1336,7 @@ def collection_case_view_take(request, pk, case_number, cid, passcode):
redirect_url, case_number=case_number - 1, **kwargs
)
elif "finish" in request.POST:
redirect_url = "atlas:collection_take"
return redirect(redirect_url, **kwargs)
elif "goto" in request.POST:
return redirect(
+5
View File
@@ -200,6 +200,11 @@ def generic_exam_urls(generic_exam_view):
generic_exam_view.exam_toggle_results_published,
name="exam_toggle_results_published",
),
path(
"exam/<int:pk>/toggle_archived",
generic_exam_view.exam_toggle_archived,
name="exam_toggle_archived",
),
path(
"exam/submit",
generic_exam_view.postExamAnswers,
+27
View File
@@ -459,6 +459,33 @@ class ExamViews(View, LoginRequiredMixin):
return False
return True
@method_decorator(login_required)
def exam_toggle_archived(self, request, pk):
print("TOGGLE ARCHIVED", request.POST)
if request.is_ajax() and request.method == "POST":
if not self.check_user_edit_access(request.user):
data = {"status": "error, insufficient permission"}
return JsonResponse(data, status=400)
exam = get_object_or_404(self.Exam, pk=pk)
exam.archive = (
True if request.POST.get("archive") == "true" else False
)
print(f"{exam.archive=}")
exam.save()
data = {
"status": "success",
"archive": exam.archive,
"name": exam.name,
"id": exam.id,
}
return JsonResponse(data, status=200)
else:
data = {"status": "error"}
return JsonResponse(data, status=400)
@method_decorator(login_required)
def exam_toggle_results_published(self, request, pk):
if request.is_ajax() and request.method == "POST":
+18 -3
View File
@@ -16,6 +16,10 @@
<label for="active-{{exam.pk}}" class="flex-col icon-container active-icon" title="Click to toggle active state">Exam Active</label>
<input type="checkbox" id="published-{{exam.pk}}" class="exam-publish-results-switch" data-posturl="{% url app_name|add:':exam_toggle_results_published' pk=exam.pk %}" {% if exam.publish_results %}checked{% endif %}>
<label for="published-{{exam.pk}}" class="flex-col icon-container published-icon" title="Click to toggle published state">Results Published</label>
{% if view_all %}
<input type="checkbox" id="archived-{{exam.pk}}" class="exam-archived-switch" data-posturl="{% url app_name|add:':exam_toggle_archived' pk=exam.pk %}" {% if exam.archive %}checked{% endif %}>
<label for="archived-{{exam.pk}}" class="flex-col icon-archive archived-icon" title="Click to toggle archived state">Archived</label>
{% endif %}
</li>
{% endif %}
{% endfor %}
@@ -34,6 +38,10 @@
<label for="active-{{exam.pk}}" class="flex-col icon-container active-icon" title="Click to toggle active state">Exam Active</label>
<input type="checkbox" id="{{exam.pk}}-pub" class="exam-publish-results-switch" data-posturl="{% url app_name|add:':exam_toggle_results_published' pk=exam.pk %}" {% if exam.publish_results %}checked{% endif %}>
<label for="{{exam.pk}}-pub" class="flex-col icon-container published-icon">Results Published</label>
{% if view_all %}
<input type="checkbox" id="archived-{{exam.pk}}" class="exam-archived-switch" data-posturl="{% url app_name|add:':exam_toggle_archived' pk=exam.pk %}" {% if exam.archive %}checked{% endif %}>
<label for="archived-{{exam.pk}}" class="flex-col icon-archive archived-icon" title="Click to toggle archived state">Archived</label>
{% endif %}
</li>
{% endif %}
{% endfor %}
@@ -50,7 +58,7 @@
<style>
.published-icon, .active-icon {
.published-icon, .active-icon, .archived-icon {
border: 1px dotted gray;
opacity: 20%;
border-radius: 4px;
@@ -61,7 +69,7 @@
text-align: center;
}
.published-icon:hover, .active-icon:hover {
.published-icon:hover, .active-icon:hover, .archived-icon:hover {
opacity: 100%;
}
@@ -79,7 +87,14 @@
display: inline-block;
}
.exam-publish-results-switch, .exam-active-switch {
.exam-archived-switch:checked + .archived-icon {
border: 1px solid purple;
color: purple;
opacity: 100%;
display: inline-block;
}
.exam-publish-results-switch, .exam-active-switch, .exam-archived-switch {
display: none;
}
</style>
+28
View File
@@ -58,6 +58,34 @@
console.log('[Done]');
})
})
$(".exam-archived-switch").on("change", function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
archive: this.checked // true if checked else false
},
type: "POST",
dataType: "json",
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
if (data.status == "success") {
toastr.info(`Exam: ${data.name} [${data.id}]
Archived state changed to: ${data.archive}.`)
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.fail(function (data) {
toastr.error(`Failed to change state`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-open-access").click(function (evt) {
$.ajax({
url: evt.currentTarget.dataset.posturl,