This commit is contained in:
Ross
2021-05-15 13:00:25 +01:00
parent 4e273717c1
commit 2deb8b8aa4
2 changed files with 38 additions and 3 deletions
+2
View File
@@ -231,6 +231,7 @@ def answer_suggestion_confirm(request):
if request.is_ajax and request.method == "POST": if request.is_ajax and request.method == "POST":
question_type = request.POST.get("question_type") question_type = request.POST.get("question_type")
aid = request.POST.get("aid") aid = request.POST.get("aid")
status = request.POST.get("status")
if question_type == "anatomy": if question_type == "anatomy":
AnswerModel = AnatomyAnswer AnswerModel = AnatomyAnswer
@@ -243,5 +244,6 @@ def answer_suggestion_confirm(request):
answer = get_object_or_404(AnswerModel, pk=aid) answer = get_object_or_404(AnswerModel, pk=aid)
answer.proposed = False answer.proposed = False
answer.status = status
answer.save() answer.save()
return JsonResponse({"success": True, "error": "Answer changed"}) return JsonResponse({"success": True, "error": "Answer changed"})
@@ -62,14 +62,16 @@
// send request to change the is_private state on customSwitches toggle // send request to change the is_private state on customSwitches toggle
$(".proposed-answer").each((n, el) => { $(".proposed-answer").each((n, el) => {
$(el).append("<span class='confirm'>[Confirm]</span>").on("click", function () { // Add button to confirm answer is correct
$(el).append(("<span class='confirm'>[Correct]</span>").on("click", function () {
$.ajax({ $.ajax({
url: "{% url 'answer_suggestion_confirm' %}", url: "{% url 'answer_suggestion_confirm' %}",
data: { data: {
csrfmiddlewaretoken: "{{ csrf_token }}", csrfmiddlewaretoken: "{{ csrf_token }}",
//active: this.checked // true if checked else false //active: this.checked // true if checked else false
question_type: "rapid", question_type: "rapid",
aid: el.dataset.aid aid: el.dataset.aid,
status: 2,
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
@@ -89,7 +91,38 @@
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
}))
// Add button to confirm answer is incorrect
$(el).append(("<span class='confirm'>[Incorrect]</span>").on("click", function () {
$.ajax({
url: "{% url 'answer_suggestion_confirm' %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
//active: this.checked // true if checked else false
question_type: "rapid",
aid: el.dataset.aid,
status: 1,
},
type: "POST",
dataType: "json",
}) })
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
if (data.success) {
toastr.info('Answer saved')
$(el).find(".confirm").remove()
$(el).removeClass("proposed-answer")
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.always(function () {
console.log('[Done]');
})
}))
}); });
}); });