Skip to content

Commit

Permalink
Merge pull request #21 from potsui/cache-answer-seq-content
Browse files Browse the repository at this point in the history
Move cached data from body to seq_content
  • Loading branch information
caesar2164 authored Aug 4, 2017
2 parents c915fba + fd3c0ab commit ce29dae
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
21 changes: 11 additions & 10 deletions freetextresponse/private/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function FreeTextResponseView(runtime, element) {

var $ = window.jQuery;
var $element = $(element);
var $xblocksContainer = $('#seq_content');
var buttonSubmit = $element.find('.check.Submit');
var buttonSave = $element.find('.save');
var usedAttemptsFeedback = $element.find('.action .used-attempts-feedback');
Expand All @@ -19,10 +20,10 @@ function FreeTextResponseView(runtime, element) {
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));
if ($xblocksContainer.data(cachedAnswerId) !== undefined) {
textareaStudentAnswer.text($xblocksContainer.data(cachedAnswerId));
problemProgress.text($xblocksContainer.data(problemProgressId));
usedAttemptsFeedback.text($xblocksContainer.data(usedAttemptsFeedbackId));
}

// POLYFILL notify if it does not exist. Like in the xblock workbench.
Expand Down Expand Up @@ -58,9 +59,9 @@ function FreeTextResponseView(runtime, element) {
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);
$xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val());
$xblocksContainer.data(problemProgressId, response.problem_progress);
$xblocksContainer.data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('submit', {
state: 'end'
Expand Down Expand Up @@ -93,9 +94,9 @@ 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);
$xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val());
$xblocksContainer.data(problemProgressId, response.problem_progress);
$xblocksContainer.data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('save', {
state: 'end'
Expand Down
21 changes: 11 additions & 10 deletions freetextresponse/public/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function FreeTextResponseView(runtime, element) {

var $ = window.jQuery;
var $element = $(element);
var $xblocksContainer = $('#seq_content');
var buttonSubmit = $element.find('.check.Submit');
var buttonSave = $element.find('.save');
var usedAttemptsFeedback = $element.find('.action .used-attempts-feedback');
Expand All @@ -19,10 +20,10 @@ function FreeTextResponseView(runtime, element) {
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));
if ($xblocksContainer.data(cachedAnswerId) !== undefined) {
textareaStudentAnswer.text($xblocksContainer.data(cachedAnswerId));
problemProgress.text($xblocksContainer.data(problemProgressId));
usedAttemptsFeedback.text($xblocksContainer.data(usedAttemptsFeedbackId));
}

// POLYFILL notify if it does not exist. Like in the xblock workbench.
Expand Down Expand Up @@ -58,9 +59,9 @@ function FreeTextResponseView(runtime, element) {
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);
$xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val());
$xblocksContainer.data(problemProgressId, response.problem_progress);
$xblocksContainer.data(usedAttemptsFeedbackId, response.used_attempts_feedback);

runtime.notify('submit', {
state: 'end'
Expand Down Expand Up @@ -93,9 +94,9 @@ 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);
$xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val());
$xblocksContainer.data(problemProgressId, response.problem_progress);
$xblocksContainer.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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xblock-free-text-response",
"title": "FreeTextResponse XBlock",
"description": "Enables instructors to create questions with free-text responses.",
"version": "0.1.6",
"version": "0.1.7",
"homepage": "https://github.com/Stanford-Online/xblock-free-text-response",
"author": {
"name": "Azim Pradhan",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_tests(self):

setup(
name="xblock-free-text-response",
version="0.1.6",
version="0.1.7",
description="Enables instructors to create questions with free-text responses.",
license='AGPL-3.0',
packages=[
Expand Down

0 comments on commit ce29dae

Please sign in to comment.