Skip to content

Commit

Permalink
Merge pull request #18 from potsui/cache-answer
Browse files Browse the repository at this point in the history
Add cache to display answer after submit or save
  • Loading branch information
caesar2164 authored Jul 25, 2017
2 parents 66c9d59 + 1155d57 commit ef941f6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = function (grunt) {
options: {
ignores: [
],
reporterOutput: '',
},
dist: [
gruntFile,
Expand Down
18 changes: 18 additions & 0 deletions freetextresponse/private/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function FreeTextResponseView(runtime, element) {
var url = runtime.handlerUrl(element, 'submit');
var urlSave = runtime.handlerUrl(element, 'save_reponse');

var xblockId = $element.attr('data-usage-id');
var cachedAnswerId = xblockId + '_cached_answer';
var problemProgressId = xblockId + '_problem_progress';
var usedAttemptsFeedbackId = xblockId + '_used_attempts_feedback';
if ($('body').data(cachedAnswerId) !== undefined) {
textareaStudentAnswer.text($('body').data(cachedAnswerId));
problemProgress.text($('body').data(problemProgressId));
usedAttemptsFeedback.text($('body').data(usedAttemptsFeedbackId));
}

// POLYFILL notify if it does not exist. Like in the xblock workbench.
runtime.notify = runtime.notify || function () {
console.log('POLYFILL runtime.notify', arguments);
Expand Down Expand Up @@ -47,6 +57,10 @@ function FreeTextResponseView(runtime, element) {
userAlertMessage.text(response.user_alert);
buttonSave.addClass(response.nodisplay_class);
setClassForTextAreaParent(response.indicator_class);

$('body').data(cachedAnswerId, $element.find('.student_answer').val());
$('body').data(problemProgressId, response.problem_progress);
$('body').data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('submit', {
state: 'end'
Expand Down Expand Up @@ -79,6 +93,10 @@ function FreeTextResponseView(runtime, element) {
buttonSave.text(buttonSave[0].dataset.value);
userAlertMessage.text(response.user_alert);

$('body').data(cachedAnswerId, $element.find('.student_answer').val());
$('body').data(problemProgressId, response.problem_progress);
$('body').data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('save', {
state: 'end'
});
Expand Down
18 changes: 18 additions & 0 deletions freetextresponse/public/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function FreeTextResponseView(runtime, element) {
var url = runtime.handlerUrl(element, 'submit');
var urlSave = runtime.handlerUrl(element, 'save_reponse');

var xblockId = $element.attr('data-usage-id');
var cachedAnswerId = xblockId + '_cached_answer';
var problemProgressId = xblockId + '_problem_progress';
var usedAttemptsFeedbackId = xblockId + '_used_attempts_feedback';
if ($('body').data(cachedAnswerId) !== undefined) {
textareaStudentAnswer.text($('body').data(cachedAnswerId));
problemProgress.text($('body').data(problemProgressId));
usedAttemptsFeedback.text($('body').data(usedAttemptsFeedbackId));
}

// POLYFILL notify if it does not exist. Like in the xblock workbench.
runtime.notify = runtime.notify || function () {
console.log('POLYFILL runtime.notify', arguments);
Expand Down Expand Up @@ -47,6 +57,10 @@ function FreeTextResponseView(runtime, element) {
userAlertMessage.text(response.user_alert);
buttonSave.addClass(response.nodisplay_class);
setClassForTextAreaParent(response.indicator_class);

$('body').data(cachedAnswerId, $element.find('.student_answer').val());
$('body').data(problemProgressId, response.problem_progress);
$('body').data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('submit', {
state: 'end'
Expand Down Expand Up @@ -79,6 +93,10 @@ function FreeTextResponseView(runtime, element) {
buttonSave.text(buttonSave[0].dataset.value);
userAlertMessage.text(response.user_alert);

$('body').data(cachedAnswerId, $element.find('.student_answer').val());
$('body').data(problemProgressId, response.problem_progress);
$('body').data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('save', {
state: 'end'
});
Expand Down
2 changes: 1 addition & 1 deletion freetextresponse/public/view.js.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion freetextresponse/public/view.js.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef941f6

Please sign in to comment.