|
453 | 453 | }, |
454 | 454 |
|
455 | 455 | // Submit the formData to given url and then execute the callback. |
456 | | - submitAjax: function(url, formData, callback) { |
| 456 | + submitAjax: function(url, formData, ajaxParams, callback) { |
| 457 | + ajaxParams = ajaxParams ?? {}; |
| 458 | + ajaxParams.dataType = ajaxParams.dataType ?? "html"; |
457 | 459 | var exercise = this; |
458 | 460 | $.ajax(url, { |
459 | 461 | type: "POST", |
460 | 462 | data: formData, |
461 | 463 | contentType: false, |
462 | 464 | processData: false, |
463 | | - dataType: "html" |
| 465 | + ...ajaxParams, |
464 | 466 | }).fail(function(xhr, textStatus, errorThrown) { |
465 | 467 | //$(form_element).find(":input").prop("disabled", false); |
466 | 468 | //exercise.showLoader("error"); |
|
596 | 598 | out_content.html("<p>Evaluating</p>"); |
597 | 599 |
|
598 | 600 | var url = exercise.url; |
599 | | - exercise.submitAjax(url, formData, function(data) { |
600 | | - const content = $(data); |
601 | | - // Look for error alerts in the feedback, but skip the hidden element |
602 | | - // that is always included: <div class="quiz-submit-error alert alert-danger hide"> |
| 601 | + exercise.submitAjax(url, formData, {dataType: "json"}, function(data) { |
| 602 | + output.find(data.messages.selector).replaceWith(data.messages.html); |
| 603 | + |
| 604 | + // Look for error alerts in the feedback |
| 605 | + const content = $(data.page.content); |
603 | 606 | const alerts = content.find('.alert-danger:not(.hide)'); |
604 | | - if (!alerts.length) { |
605 | | - var poll_url = content.find(".exercise-wait").attr("data-poll-url"); |
606 | | - output.attr('data-poll-url', poll_url); |
607 | | - |
608 | | - exercise.updateSubmission(content); |
609 | | - } else if (alerts.contents().text() |
610 | | - .indexOf("The grading queue is not configured.") >= 0) { |
611 | | - output.find(exercise.settings.ae_result_selector) |
612 | | - .html(content.find(".alert:not(.hide)").text()); |
613 | | - output.find(exercise.settings.ae_result_selector).append(content.find(".grading-task").text()); |
| 607 | + output.find(data.messages.selector).append(alerts); |
| 608 | + |
| 609 | + if (data.submission) { |
| 610 | + output.attr('data-poll-url', data.submission.poll_url); |
| 611 | + output.attr('data-ready-url', data.submission.ready_url); |
| 612 | + |
| 613 | + exercise.updateSubmission(); |
614 | 614 | } else { |
615 | | - output.find(exercise.settings.ae_result_selector) |
616 | | - .html(alerts.contents()); |
| 615 | + out_content.html("<p>Failed to submit:</p>") |
| 616 | + for(const err of data.errors) { |
| 617 | + out_content.append("<p>" + err + "</p>") |
| 618 | + } |
617 | 619 | } |
618 | 620 | }); |
619 | 621 | }); |
|
636 | 638 | } else { |
637 | 639 | formData.set('__aplus__', JSON.stringify({hash: hash})); |
638 | 640 | } |
639 | | - exercise.submitAjax(url, formData, function(data) { |
| 641 | + exercise.submitAjax(url, formData, {}, function(data) { |
640 | 642 | //$(form_element).find(":input").prop("disabled", false); |
641 | 643 | //exercise.hideLoader(); |
642 | 644 | var input = $(data); |
|
0 commit comments