|
184 | 184 | response_selector: '.exercise-response', |
185 | 185 | navigation_selector: 'ul.nav a[class!="dropdown-toggle"]', |
186 | 186 | dropdown_selector: 'ul.nav .dropdown-toggle', |
187 | | - last_submission_selector: 'ul.nav ul.dropdown-menu li:first-child a', |
| 187 | + last_submission_selector: 'ul.navbar-nav ul.dropdown-menu li:first-child a', |
188 | 188 | // For active elements: |
189 | 189 | active_element_attr: "data-aplus-active-element", |
190 | 190 | interactive_code_attr: "data-aplus-interactive-code", |
|
377 | 377 | .done(function(data) { |
378 | 378 | exercise.hideLoader(); |
379 | 379 | exercise.update($(data)); |
| 380 | + const hasTextarea = exercise.element.find('textarea').length > 0; |
| 381 | + const hasFieldset = exercise.element.find('fieldset').length > 0; |
380 | 382 | if (exercise.active_element) { |
381 | 383 | exercise.loadLastSubmission($(data)); |
| 384 | + } else if (hasTextarea && !hasFieldset) { // Identify acceptPost exercises |
| 385 | + exercise.loadLastSubmission($(data), true); |
382 | 386 | } else { |
383 | 387 | exercise.renderMath(); |
384 | 388 | if (!onlyThis) exercise.chapter.nextExercise(); |
|
849 | 853 | } |
850 | 854 | }, |
851 | 855 |
|
852 | | - loadLastSubmission: function(input) { |
| 856 | + loadLastSubmission: function(input, fillInputs = false) { |
853 | 857 | var link = input.find(this.settings.last_submission_selector); |
854 | 858 | var exercise = this; |
855 | 859 | if (link.length > 0) { |
856 | 860 | var url = link.attr("href"); |
857 | 861 |
|
858 | 862 | if (url && url !== "#") { |
859 | 863 | var data_type = "html"; |
860 | | - if (exercise.active_element) { |
| 864 | + if (exercise.active_element || fillInputs) { |
861 | 865 | // Active element input values are retrieved from the API, so |
862 | 866 | // we must extract the submission number from the submission url |
863 | 867 | var submission = url.match(/submissions\/\d+/)[0].split('/')[1]; |
|
875 | 879 |
|
876 | 880 | if (!exercise.active_element) { |
877 | 881 | const responseElement = exercise.element.find(exercise.settings.response_selector); |
878 | | - // Remove only the exercise content, not the alerts above it |
879 | | - responseElement.children().not('.alert').remove(); |
880 | | - responseElement.append( |
881 | | - $(data).filter(exercise.settings.exercise_selector).contents() |
882 | | - ); |
883 | | - exercise.dom_element.dispatchEvent( |
884 | | - new CustomEvent("aplus:exercise-loaded", |
885 | | - {bubbles: true, detail: {type: exercise.exercise_type}})); |
886 | | - // TODO: remove magic constant (variable defined in group.js) |
887 | | - responseElement.removeClass('group-augmented'); |
888 | | - exercise.bindFormEvents(exercise.element); |
889 | | - exercise.dom_element.dispatchEvent( |
890 | | - new CustomEvent("aplus:exercise-ready", |
891 | | - {bubbles: true, detail: {type: exercise.exercise_type}})); |
| 882 | + if (!fillInputs) { |
| 883 | + // Remove only the exercise content, not the alerts above it |
| 884 | + responseElement.children().not('.alert').remove(); |
| 885 | + responseElement.append( |
| 886 | + $(data).filter(exercise.settings.exercise_selector).contents() |
| 887 | + ); |
| 888 | + exercise.dom_element.dispatchEvent( |
| 889 | + new CustomEvent("aplus:exercise-loaded", |
| 890 | + {bubbles: true, detail: {type: exercise.exercise_type}})); |
| 891 | + // TODO: remove magic constant (variable defined in group.js) |
| 892 | + responseElement.removeClass('group-augmented'); |
| 893 | + exercise.bindFormEvents(exercise.element); |
| 894 | + exercise.dom_element.dispatchEvent( |
| 895 | + new CustomEvent("aplus:exercise-ready", |
| 896 | + {bubbles: true, detail: {type: exercise.exercise_type}})); |
| 897 | + } else { |
| 898 | + // Fill textareas with last submission inputs |
| 899 | + const lastInputs = data.submission_data.map((x) => x[1]); |
| 900 | + const textareas = responseElement.find('textarea'); |
| 901 | + textareas.each(function(index) { |
| 902 | + $(this).val(lastInputs[index]); |
| 903 | + }); |
| 904 | + } |
| 905 | + |
892 | 906 | } else { |
893 | 907 | // Update the output box values |
894 | 908 | exercise.updateOutput(data.feedback); |
|
0 commit comments