add publish results feature

This commit is contained in:
Ross
2020-12-10 23:26:44 +00:00
parent cdd466ecb5
commit 75516f38e5
8 changed files with 79 additions and 4 deletions
+29 -2
View File
@@ -7,8 +7,11 @@
<h1>Exam: {{ exam.name }}</h1>
This exam has {{question_number}} questions.
<div title="Click to enable / disable the exam">
Exam active: <input type="checkbox" id="exam-active-switch" {% if exam.active %}checked{% endif %}>
<div class="parent-help" title="Click to enable / disable the exam">
Exam active: <input type="checkbox" id="exam-active-switch" {% if exam.active %}checked{% endif %}> <span class="help-text">[When checked the exam will be available to take in the test system]</span>
</div>
<div class="parent-help" title="Click to enable / disable the exam results">
Publish results: <input type="checkbox" id="exam-publish-results-switch" {% if exam.publish_results %}checked{% endif %}> <span class="help-text">[When checked the exam results will be available on this site]</span>
</div>
<p><a href="{% url 'anatomy:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
<!--<p><button><a href="{% url 'anatomy:exam_take' pk=exam.pk sk=0 %}">Click here to start</a></button></p>-->
@@ -57,6 +60,30 @@
console.log('[Done]');
})
})
$("#exam-publish-results-switch").on("change", function () {
$.ajax({
url: "{% url 'anatomy:exam_toggle_results_published' pk=exam.pk %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
publish_results: 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('Publish results state changed.')
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.always(function () {
console.log('[Done]');
})
})
});
</script>
{% endblock %}