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":
question_type = request.POST.get("question_type")
aid = request.POST.get("aid")
status = request.POST.get("status")
if question_type == "anatomy":
AnswerModel = AnatomyAnswer
@@ -243,5 +244,6 @@ def answer_suggestion_confirm(request):
answer = get_object_or_404(AnswerModel, pk=aid)
answer.proposed = False
answer.status = status
answer.save()
return JsonResponse({"success": True, "error": "Answer changed"})
@@ -62,14 +62,16 @@
// send request to change the is_private state on customSwitches toggle
$(".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({
url: "{% url 'answer_suggestion_confirm' %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
//active: this.checked // true if checked else false
question_type: "rapid",
aid: el.dataset.aid
aid: el.dataset.aid,
status: 2,
},
type: "POST",
dataType: "json",
@@ -89,7 +91,38 @@
.always(function () {
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]');
})
}))
});
});