From 0d95fe3bae6379acdce98fffa753c84f303d0357 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 19 Aug 2021 15:24:49 +0100 Subject: [PATCH] . --- .../rapids/question_display_block.html | 333 +++++++++--------- 1 file changed, 166 insertions(+), 167 deletions(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 3f078b84..c72c546f 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -41,14 +41,14 @@

Checked by: {% for verified in question.verified.all %} {{verified}}, {% endfor %}

Scrapped: {{ question.scrapped }} (toggle) -

- Answers (score): {% for answer in question.answers.all %} - + Answers (score): {% for answer in question.answers.all %} + - {{ answer }} ({{answer.status}}), - - {% endfor %} -

+ {{ answer }} ({{answer.status}}), + + {% endfor %} +

@@ -104,19 +104,19 @@ console.log(json); return $.ajax({ - url: "{% url 'rapids:question_save_annotation' pk=question.pk %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - annotation: json, - }, - type: "POST", - dataType: "json", - error: function (e) { - toastr.warning(`Error saving annotations`) - console.log(e); - }, + url: "{% url 'rapids:question_save_annotation' pk=question.pk %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + annotation: json, + }, + type: "POST", + dataType: "json", + error: function (e) { + toastr.warning(`Error saving annotations`) + console.log(e); + }, - }) + }) // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly .done(function (data) { console.log(data); @@ -137,19 +137,19 @@ $("#add-to-exam").click(function (evt) { var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) { - console.log(data); - $("#exam-options").empty(); - data.forEach((obj, n) => { - $("#exam-options").append($(document.createElement('button')).prop({ - type: 'button', - innerHTML: obj.name, - class: '', + console.log(data); + $("#exam-options").empty(); + data.forEach((obj, n) => { + $("#exam-options").append($(document.createElement('button')).prop({ + type: 'button', + innerHTML: obj.name, + class: '', - }).data("exam-id", obj.id).click((evt) => { - addToExam(evt) - })) + }).data("exam-id", obj.id).click((evt) => { + addToExam(evt) + })) + }) }) - }) .done(function () { //alert( "second success" ); }) @@ -178,16 +178,16 @@ let type = exam_button.dataset.type; let csrf = exam_button.dataset.csrf; $.ajax({ - url: post_url, - data: { - csrfmiddlewaretoken: csrf, - add_exam_questions: JSON.stringify(ids), - type: type, - exam_id: $(evt.target).data("exam-id"), - }, - type: "POST", - dataType: "json", - }) + url: post_url, + data: { + csrfmiddlewaretoken: csrf, + add_exam_questions: JSON.stringify(ids), + type: type, + exam_id: $(evt.target).data("exam-id"), + }, + type: "POST", + dataType: "json", + }) // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly .done(function (data) { console.log(data); @@ -209,41 +209,18 @@ /* beautify ignore:end */ $("#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({ - url: "{% url 'rapid-detail' question.id %}", - type: 'PATCH', - headers: { - "X-CSRFToken": "{{ csrf_token }}" - }, - timeout: 3000, - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - laterality: el.dataset.lat, - } - }) + 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') @@ -252,106 +229,129 @@ alert('Error updating this model instance.'); }); }); - }); - $(".suggested_answers li").each((n, el) => { - $(el).append($("[Add Correct]").on("click", function () { - $.ajax({ - url: "{% url 'answer_submit' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - 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); + $(".toggle-laterality-button").each((n, el) => { + $(el).click(function () { + $.ajax({ + url: "{% url 'rapid-detail' question.id %}", + type: 'PATCH', + headers: { + "X-CSRFToken": "{{ csrf_token }}" + }, + timeout: 3000, + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + laterality: el.dataset.lat, + } + }) + .done(function (data) { + console.log(data); + toastr.info('Answer updated') + }) + .fail(function () { + alert('Error updating this model instance.'); + }); + }); + }); - 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]'); - }) - })) + $(".suggested_answers li").each((n, el) => { + $(el).append($("[Add Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_submit' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + 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 - $(el).append($("[Add Correct]").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: 2, - }, - type: "POST", - dataType: "json", - }) - // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly - .done(function (data) { - console.log(data); + // send request to change the is_private state on customSwitches toggle + $(".proposed-answer").each((n, el) => { - 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]'); - }) - })) + // Add button to confirm answer is correct + $(el).append($("[Add Correct]").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: 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 - $(el).append($("[Incorrect]").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: 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]'); + }) + })) - 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]'); - }) - })) - }); + // Add button to confirm answer is incorrect + $(el).append($("[Incorrect]").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: 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() { @@ -370,7 +370,6 @@ return json_tool_state; } -