This commit is contained in:
Ross
2021-10-17 12:10:21 +01:00
parent 53cbdf4165
commit 56522ae0ae
2 changed files with 23 additions and 166 deletions
+19 -164
View File
@@ -22,10 +22,11 @@
{% if exam.exam_mode %}
<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>
Exam active: <input type="checkbox" id="exam-active-switch" {% if exam.active %}checked{% endif %} data-posturl="{% url 'anatomy:exam_toggle_active' pk=exam.pk %}"> <span> <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 to users on this site]</span>
Publish results: <input type="checkbox" id="exam-publish-results-switch" data-posturl="{% url 'anatomy:exam_toggle_results_published' pk=exam.pk %}"
{% if exam.publish_results %}checked{% endif %}> <span class="help-text">[When checked the exam results will be available to users on this site]</span>
</div>
<p><a href="{% url 'anatomy:mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
{% endif %}
@@ -35,20 +36,20 @@
<li data-question_pk={{question.pk}}>
<span class="flex-col">
<a href="{% url 'anatomy:exam_question_detail' pk=exam.pk sk=forloop.counter0 %}">
<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" />
</a>
<a href="{% url 'anatomy:exam_question_detail' pk=exam.pk sk=forloop.counter0 %}">
<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" />
</a>
</span>
<span class="flex-col-4">
{{ question.description }}
<br />
{{ question.question_type }}: {{ question.get_primary_answer }}
<br />
Modality: {{ question.modality }},
{% if exam.exam_mode %}
<a href="{% url 'anatomy:mark' pk=exam.pk sk=forloop.counter0 %}">Mark</a>
{% endif %}
<span class="id"><a href="{% url 'anatomy:question_detail' pk=question.pk %}">[id: {{question.pk}}]</a></span>
{{ question.description }}
<br />
{{ question.question_type }}: {{ question.get_primary_answer }}
<br />
Modality: {{ question.modality }},
{% if exam.exam_mode %}
<a href="{% url 'anatomy:mark' pk=exam.pk sk=forloop.counter0 %}">Mark</a>
{% endif %}
<span class="id"><a href="{% url 'anatomy:question_detail' pk=question.pk %}">[id: {{question.pk}}]</a></span>
</span>
</li>
{% endfor %}
@@ -59,7 +60,7 @@
{% endfor %}
</div>
{% if can_edit %}
<p><button id='button-edit-order'>Edit question order / Delete questions</button></p>
<p><button id='button-edit-order' title='click and drag questions to change order' data-posturl="{% url 'anatomy:exam_json_edit' pk=exam.pk %}">Edit question order / Delete questions</button></p>
{% endif %}
<div>
JSON creation time: {{exam.json_creation_time}} ({{exam.json_creation_time|date:"c"}}),
@@ -68,156 +69,10 @@
<a href="{% url 'anatomy:exam_json' pk=exam.pk %}">JSON</a>
<a href="{% url 'anatomy:exam_json_recreate' pk=exam.pk %}">Refresh JSON cache</a>
{% if request.user.is_superuser %}
<button id='button-open-access'>Make questions open access</button>
<button id='button-closed-access'>Make questions closed access</button>
<button id='button-open-access' data-posturl="{% url 'anatomy:exam_json_edit' pk=exam.pk %}">Make questions open access</button>
<button id='button-closed-access' data-posturl="{% url 'anatomy:exam_json_edit' pk=exam.pk %}">Make questions closed access</button>
{% endif %}
</div>
<script type="text/javascript">
$(document).ready(function () {
// send request to change the is_private state on customSwitches toggle
$("#exam-active-switch").on("change", function () {
$.ajax({
url: "{% url 'anatomy:exam_toggle_active' pk=exam.pk %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
active: 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 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]');
})
})
$("#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]');
})
})
$("#button-open-access").click(function () {
$.ajax({
url: "{% url 'generic:generic_exam_json_edit' %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_open_access: true,
type: "anatomy",
exam_id: "{{exam.pk}}",
},
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('Question access state changed.')
}
})
.fail((e) => {
toastr.warning(`Error, ${e}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-closed-access").click(function () {
$.ajax({
//url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}",
url: "{% url 'generic:generic_exam_json_edit' %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_open_access: false,
type: "anatomy",
exam_id: "{{exam.pk}}",
},
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('Question access state changed.')
}
})
.fail((e) => {
toastr.warning(`Error, ${e}`);
})
.always(function () {
console.log('[Done]');
})
})
$("#button-edit-order").click(function () {
$(this).remove();
sortable('.sortable');
$("#full-question-list li").each((n, el) => {
$(el).append($(
"<span class='exam-question-delete flex-col'><button>DELETE</button></span>"
).click(() => {
el.remove();
}));
})
$("#full-question-list").append($("<button>Save exam order</button>").click(() => {
new_order = [];
$("#full-question-list li").each((n, el) => {
new_order.push(el.dataset.question_pk)
})
$.ajax({
url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
set_exam_order: JSON.stringify(new_order),
},
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 order changed.')
}
})
.always(function () {
console.log('[Done]');
})
}));
});
});
</script>
{% include 'exam_overview_js.html' %}
{% endblock %}
+4 -2
View File
@@ -72,7 +72,9 @@
{{ author }},
{% endfor %}
</div>
<p><button id='button-edit-order' title='click and drag questions to change order' data-posturl="{% url 'rapids:exam_json_edit' pk=exam.pk %}">Edit question order / Delete questions</button></p>
{% if can_edit %}
<p><button id='button-edit-order' title='click and drag questions to change order' data-posturl="{% url 'rapids:exam_json_edit' pk=exam.pk %}">Edit question order / Delete questions</button></p>
{% endif %}
<div>
JSON creation time: {{exam.json_creation_time}} ({{exam.json_creation_time|date:"c"}}),
JSON creation id: {{exam.exam_json_id}}
@@ -84,6 +86,6 @@
<button id='button-closed-access' data-posturl="{% url 'rapids:exam_json_edit' pk=exam.pk %}">Make questions closed access</button>
</div>
{% include 'exam_overview_js.html' %}
{% include 'exam_overview_js.html' %}
{% endblock %}