This commit is contained in:
Ross
2021-07-08 16:35:49 +01:00
parent 668b0d7824
commit fb2aa07b17
@@ -92,127 +92,126 @@
/* beautify ignore:end */ /* beautify ignore:end */
$("#toggle-normal-button").click(function () { $("#toggle-normal-button").click(function () {
$.ajax({ $.ajax({
url: "{% url 'rapid-detail' question.id %}", url: "{% url 'rapid-detail' question.id %}",
type: 'PATCH', type: 'PATCH',
headers: { headers: {
"X-CSRFToken": "{{ csrf_token }}" "X-CSRFToken": "{{ csrf_token }}"
}, },
timeout: 3000, timeout: 3000,
data: { data: {
csrfmiddlewaretoken: "{{ csrf_token }}", csrfmiddlewaretoken: "{{ csrf_token }}",
normal: n, normal: n,
} }
}) })
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
toastr.info('Answer saved') toastr.info('Answer saved')
} })
}) .fail(function () {
.fail(function () { alert('Error updating this model instance.');
alert('Error updating this model instance.'); //chk_status_field.prop('checked', !chk_status_field.prop('checked'));
//chk_status_field.prop('checked', !chk_status_field.prop('checked')); });
});
}); });
$(".suggested_answers li").each((n, el) => { $(".suggested_answers li").each((n, el) => {
$(el).append($("<span class='correct'>[Add Correct]</span>").on("click", function () { $(el).append($("<span class='correct'>[Add Correct]</span>").on("click", function () {
$.ajax({ $.ajax({
url: "{% url 'answer_submit' %}", url: "{% url 'answer_submit' %}",
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",
qid: "{{question.pk}}", qid: "{{question.pk}}",
status: 2, status: 2,
answer: el.dataset.string, answer: el.dataset.string,
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
}) })
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
if (data.success) { if (data.success) {
toastr.info('Answer saved') toastr.info('Answer saved')
$(el).find(".correct").remove() $(el).find(".correct").remove()
} }
// show some message according to the response. // show some message according to the response.
// For eg. A message box showing that the status has been changed // For eg. A message box showing that the status has been changed
}) })
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
})) }))
}); });
// 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) => {
// Add button to confirm answer is correct // Add button to confirm answer is correct
$(el).append($("<span class='confirm'>[Add Correct]</span>").on("click", function () { $(el).append($("<span class='confirm'>[Add 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, status: 2,
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
}) })
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
if (data.success) { if (data.success) {
toastr.info('Answer saved') toastr.info('Answer saved')
$(el).find(".confirm").remove() $(el).find(".confirm").remove()
$(el).removeClass("proposed-answer") $(el).removeClass("proposed-answer")
} }
// show some message according to the response. // show some message according to the response.
// For eg. A message box showing that the status has been changed // For eg. A message box showing that the status has been changed
}) })
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
})) }))
// Add button to confirm answer is incorrect // Add button to confirm answer is incorrect
$(el).append($("<span class='confirm'>[Incorrect]</span>").on("click", function () { $(el).append($("<span class='confirm'>[Incorrect]</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: 0, status: 0,
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
}) })
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
if (data.success) { if (data.success) {
toastr.info('Answer saved') toastr.info('Answer saved')
$(el).find(".confirm").remove() $(el).find(".confirm").remove()
$(el).removeClass("proposed-answer") $(el).removeClass("proposed-answer")
} }
// show some message according to the response. // show some message according to the response.
// For eg. A message box showing that the status has been changed // For eg. A message box showing that the status has been changed
}) })
.always(function () { .always(function () {
console.log('[Done]'); console.log('[Done]');
}) })
})) }))
}); });
}); });
</script> </script>
<style> <style>
@@ -220,6 +219,7 @@
font-size: x-small; font-size: x-small;
opacity: 10%; opacity: 10%;
} }
.toggle-button:hover { .toggle-button:hover {
font-size: x-small; font-size: x-small;
opacity: 100%; opacity: 100%;