Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 9d62309

Browse files
committed
enable remote storage of short answers.
1 parent e613262 commit 9d62309

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

runestone/shortanswer/js/shortanswer.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,37 @@ ShortAnswer.prototype.submitJournal = function () {
131131
function(data) {
132132
console.log(data.message);
133133
}); */
134-
this.logBookEvent({'event': 'shortanswer', 'act': JSON.stringify(value), 'div_id': directive_id});
134+
this.logBookEvent({'event': 'shortanswer', 'act': JSON.stringify(value), 'div_id': this.divid});
135135
};
136136

137137
ShortAnswer.prototype.loadJournal = function () {
138-
var len = localStorage.length;
139-
if (len > 0) {
140-
var ex = localStorage.getItem(this.divid);
141-
if (ex !== null) {
142-
var solution = $("#" + this.divid + "_solution");
143-
solution.text(localStorage.getItem(this.divid));
138+
139+
// Ask the server to send the latest
140+
var loadAnswer = function(data,status,whatever) {
141+
var len = localStorage.length;
142+
var answer = "";
143+
console.log(data);
144+
if (! jQuery.isEmptyObject(data)) {
145+
answer = data;
144146
}
145-
}
147+
console.log(answer.toString());
148+
var solution = $("#" + this.divid + "_solution");
149+
if (len > 0) {
150+
var ex = localStorage.getItem(this.divid);
151+
if (ex !== null ) {
152+
if (storage.is_new(answer.divid, new Date(answer.timestamp))) {
153+
solution.text(localStorage.getItem(this.divid));
154+
// now send the newer answer to the server...
155+
} else {
156+
solution.text(answer.answer);
157+
}
158+
} else {
159+
solution.text(answer);
160+
}
161+
}
162+
}.bind(this);
163+
var data = {'div_id' : this.divid};
164+
jQuery.get(eBookConfig.ajaxURL + 'getlastanswer', data, loadAnswer );
146165
};
147166

148167
/*

0 commit comments

Comments
 (0)