This commit is contained in:
Ross
2021-08-19 15:24:49 +01:00
parent b8c2926c41
commit 0d95fe3bae
@@ -41,14 +41,14 @@
<p><b>Checked by:</b> {% for verified in question.verified.all %} <a <p><b>Checked by:</b> {% for verified in question.verified.all %} <a
href="{% url 'rapids:verified_detail' pk=verified.pk %}">{{verified}}</a>, {% endfor %}</p> href="{% url 'rapids:verified_detail' pk=verified.pk %}">{{verified}}</a>, {% endfor %}</p>
<p><b>Scrapped:</b> {{ question.scrapped }} <a href="{% url 'rapids:rapid_scrap' pk=question.pk %}">(toggle)</a> <p><b>Scrapped:</b> {{ question.scrapped }} <a href="{% url 'rapids:rapid_scrap' pk=question.pk %}">(toggle)</a>
<p class="pre-whitespace"> <p class="pre-whitespace">
Answers (score): {% for answer in question.answers.all %} Answers (score): {% for answer in question.answers.all %}
<span {% if answer.proposed %}class="proposed-answer" data-aid="{{answer.pk}}" data-question-type="rapid" {% <span {% if answer.proposed %}class="proposed-answer" data-aid="{{answer.pk}}" data-question-type="rapid" {%
endif %}> endif %}>
{{ answer }} ({{answer.status}}), {{ answer }} ({{answer.status}}),
</span> </span>
{% endfor %} {% endfor %}
</p> </p>
</div> </div>
<div> <div>
@@ -104,19 +104,19 @@
console.log(json); console.log(json);
return return
$.ajax({ $.ajax({
url: "{% url 'rapids:question_save_annotation' pk=question.pk %}", url: "{% url 'rapids:question_save_annotation' pk=question.pk %}",
data: { data: {
csrfmiddlewaretoken: "{{ csrf_token }}", csrfmiddlewaretoken: "{{ csrf_token }}",
annotation: json, annotation: json,
}, },
type: "POST", type: "POST",
dataType: "json", dataType: "json",
error: function (e) { error: function (e) {
toastr.warning(`Error saving annotations`) toastr.warning(`Error saving annotations`)
console.log(e); console.log(e);
}, },
}) })
// $.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);
@@ -137,19 +137,19 @@
$("#add-to-exam").click(function (evt) { $("#add-to-exam").click(function (evt) {
var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) { var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) {
console.log(data); console.log(data);
$("#exam-options").empty(); $("#exam-options").empty();
data.forEach((obj, n) => { data.forEach((obj, n) => {
$("#exam-options").append($(document.createElement('button')).prop({ $("#exam-options").append($(document.createElement('button')).prop({
type: 'button', type: 'button',
innerHTML: obj.name, innerHTML: obj.name,
class: '', class: '',
}).data("exam-id", obj.id).click((evt) => { }).data("exam-id", obj.id).click((evt) => {
addToExam(evt) addToExam(evt)
})) }))
})
}) })
})
.done(function () { .done(function () {
//alert( "second success" ); //alert( "second success" );
}) })
@@ -178,16 +178,16 @@
let type = exam_button.dataset.type; let type = exam_button.dataset.type;
let csrf = exam_button.dataset.csrf; let csrf = exam_button.dataset.csrf;
$.ajax({ $.ajax({
url: post_url, url: post_url,
data: { data: {
csrfmiddlewaretoken: csrf, csrfmiddlewaretoken: csrf,
add_exam_questions: JSON.stringify(ids), add_exam_questions: JSON.stringify(ids),
type: type, type: type,
exam_id: $(evt.target).data("exam-id"), exam_id: $(evt.target).data("exam-id"),
}, },
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);
@@ -209,41 +209,18 @@
/* beautify ignore:end */ /* beautify ignore:end */
$("#toggle-normal-button").click(function () { $("#toggle-normal-button").click(function () {
$.ajax({
url: "{% url 'rapid-detail' question.id %}",
type: 'PATCH',
headers: {
"X-CSRFToken": "{{ csrf_token }}"
},
timeout: 3000,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
normal: n,
}
})
.done(function (data) {
console.log(data);
toastr.info('Answer updated')
})
.fail(function () {
alert('Error updating this model instance.');
});
});
$(".toggle-laterality-button").each((n, el) => {
$(el).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 }}",
laterality: el.dataset.lat, normal: n,
} }
}) })
.done(function (data) { .done(function (data) {
console.log(data); console.log(data);
toastr.info('Answer updated') toastr.info('Answer updated')
@@ -252,106 +229,129 @@
alert('Error updating this model instance.'); alert('Error updating this model instance.');
}); });
}); });
});
$(".suggested_answers li").each((n, el) => { $(".toggle-laterality-button").each((n, el) => {
$(el).append($("<span class='correct'>[Add Correct]</span>").on("click", function () { $(el).click(function () {
$.ajax({ $.ajax({
url: "{% url 'answer_submit' %}", url: "{% url 'rapid-detail' question.id %}",
data: { type: 'PATCH',
csrfmiddlewaretoken: "{{ csrf_token }}", headers: {
//active: this.checked // true if checked else false "X-CSRFToken": "{{ csrf_token }}"
question_type: "rapid", },
qid: "{{question.pk}}", timeout: 3000,
status: 2, data: {
answer: el.dataset.string, csrfmiddlewaretoken: "{{ csrf_token }}",
}, laterality: el.dataset.lat,
type: "POST", }
dataType: "json", })
}) .done(function (data) {
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly console.log(data);
.done(function (data) { toastr.info('Answer updated')
console.log(data); })
.fail(function () {
alert('Error updating this model instance.');
});
});
});
if (data.success) { $(".suggested_answers li").each((n, el) => {
toastr.info('Answer saved') $(el).append($("<span class='correct'>[Add Correct]</span>").on("click", function () {
$(el).find(".correct").remove() $.ajax({
} url: "{% url 'answer_submit' %}",
// show some message according to the response. data: {
// For eg. A message box showing that the status has been changed csrfmiddlewaretoken: "{{ csrf_token }}",
}) //active: this.checked // true if checked else false
.always(function () { question_type: "rapid",
console.log('[Done]'); qid: "{{question.pk}}",
}) status: 2,
})) answer: el.dataset.string,
},
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(".correct").remove()
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
})
.always(function () {
console.log('[Done]');
})
}))
// send request to change the is_private state on customSwitches toggle });
$(".proposed-answer").each((n, el) => {
// Add button to confirm answer is correct // send request to change the is_private state on customSwitches toggle
$(el).append($("<span class='confirm'>[Add Correct]</span>").on("click", function () { $(".proposed-answer").each((n, el) => {
$.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: 2,
},
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) { // Add button to confirm answer is correct
toastr.info('Answer saved') $(el).append($("<span class='confirm'>[Add Correct]</span>").on("click", function () {
$(el).find(".confirm").remove() $.ajax({
$(el).removeClass("proposed-answer") url: "{% url 'answer_suggestion_confirm' %}",
} data: {
// show some message according to the response. csrfmiddlewaretoken: "{{ csrf_token }}",
// For eg. A message box showing that the status has been changed //active: this.checked // true if checked else false
}) question_type: "rapid",
.always(function () { aid: el.dataset.aid,
console.log('[Done]'); status: 2,
}) },
})) type: "POST",
dataType: "json",
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
// Add button to confirm answer is incorrect if (data.success) {
$(el).append($("<span class='confirm'>[Incorrect]</span>").on("click", function () { toastr.info('Answer saved')
$.ajax({ $(el).find(".confirm").remove()
url: "{% url 'answer_suggestion_confirm' %}", $(el).removeClass("proposed-answer")
data: { }
csrfmiddlewaretoken: "{{ csrf_token }}", // show some message according to the response.
//active: this.checked // true if checked else false // For eg. A message box showing that the status has been changed
question_type: "rapid", })
aid: el.dataset.aid, .always(function () {
status: 0, console.log('[Done]');
}, })
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) { // Add button to confirm answer is incorrect
toastr.info('Answer saved') $(el).append($("<span class='confirm'>[Incorrect]</span>").on("click", function () {
$(el).find(".confirm").remove() $.ajax({
$(el).removeClass("proposed-answer") url: "{% url 'answer_suggestion_confirm' %}",
} data: {
// show some message according to the response. csrfmiddlewaretoken: "{{ csrf_token }}",
// For eg. A message box showing that the status has been changed //active: this.checked // true if checked else false
}) question_type: "rapid",
.always(function () { aid: el.dataset.aid,
console.log('[Done]'); status: 0,
}) },
})) 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]');
})
}))
});
}); });
function getJsonToolStateNoId() { function getJsonToolStateNoId() {
@@ -370,7 +370,6 @@
return json_tool_state; return json_tool_state;
} }
</script> </script>
<style> <style>
.toggle-button { .toggle-button {