Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions runestone/activecode/js/activecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ActiveCode.prototype.addHistoryScrubber = function (pos_last) {
$(scrubberDiv).css("margin-right","10px");
$(scrubberDiv).width("180px");
scrubber = document.createElement("div");
var slideit = function() {
this.slideit = function() {
this.editor.setValue(this.history[$(scrubber).slider("value")]);
var curVal = this.timestamps[$(scrubber).slider("value")];
//this.scrubberTime.innerHTML = curVal;
Expand All @@ -239,12 +239,12 @@ ActiveCode.prototype.addHistoryScrubber = function (pos_last) {
setTimeout(function () {
$(scrubber).find(".sltooltip").fadeOut()
}, 4000);
}.bind(this);
};
$(scrubber).slider({
max: this.history.length-1,
value: this.history.length-1,
slide: slideit,
change: slideit
slide: this.slideit.bind(this),
change: this.slideit.bind(this)
});
scrubberDiv.appendChild(scrubber);

Expand Down
8 changes: 8 additions & 0 deletions runestone/activecode/js/timed_activecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ TimedActiveCode.prototype.reinitializeListeners = function () {
// re-attach the run button listener
$(this.runButton).click(this.runProg.bind(this));
$(this.histButton).click(this.addHistoryScrubber.bind(this));
if (this.historyScrubber !== null) {
$(this.historyScrubber).slider({
max: this.history.length-1,
value: this.history.length-1,
slide: this.slideit.bind(this),
change: this.slideit.bind(this)
});
}
};
77 changes: 18 additions & 59 deletions runestone/assess/js/fitb.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ FITB.prototype.init = function (opts) {
}
this.populateFeedbackArray();
this.createFITBElement();
this.checkServer();
this.checkServer("fillb");
};

/*====================================
Expand Down Expand Up @@ -199,35 +199,11 @@ FITB.prototype.renderFITBFeedbackDiv = function () {
=== Checking/loading from storage ===
===================================*/

FITB.prototype.checkServer = function () {
// Check if the server has stored answer
if (this.useRunestoneServices) {
var data = {};
data.div_id = this.divid;
data.course = eBookConfig.course;
data.event = "fillb";
jQuery.getJSON(eBookConfig.ajaxURL + "getAssessResults", data, this.repopulateFromStorage.bind(this)).error(this.checkLocalStorage.bind(this));
} else {
this.checkLocalStorage();
}

};

FITB.prototype.repopulateFromStorage = function (data, status, whatever) {
// decide whether to use the server's answer (if there is one) or to load from storage
if (data !== null) {
if (this.shouldUseServer(data)) {
var arr = data.answer.split(",");
for (var i = 0; i < this.blankArray.length; i++) {
$(this.blankArray[i]).attr("value", arr[i]);
}
this.setLocalStorage(data.correct); // We don't want to set this.correct here because that would interfere with timed grading functionality
} else {
this.checkLocalStorage();
}
this.enableCompareButton();
} else {
this.checkLocalStorage();
FITB.prototype.restoreAnswers = function (data) {
// Restore answers from storage retrieval done in RunestoneBase
var arr = data.answer.split(",");
for (var i = 0; i < this.blankArray.length; i++) {
$(this.blankArray[i]).attr("value", arr[i]);
}
};

Expand All @@ -238,47 +214,27 @@ FITB.prototype.checkLocalStorage = function () {
var ex = localStorage.getItem(eBookConfig.email + ":" + this.divid + "-given");
if (ex !== null) {
var storedData = JSON.parse(ex);
var arr = storedData.givenArr;
var arr = storedData.answer;
for (var i = 0; i < this.blankArray.length; i++) {
$(this.blankArray[i]).attr("value", arr[i]);
}
if (this.useRunestoneServices) {
var answerInfo = "answer:" + storedData.givenArr+ ":" + (storedData.correct ? "correct" : "no");
this.logBookEvent({"event": "fillb", "act": answerInfo, "div_id": this.divid});
this.logBookEvent({"event": "fillb", "act": "submitFITB", "answer": storedData.answer.join(","), "correct": storedData.correct, "div_id": this.divid});
this.enableCompareButton();
}
}
}
};

FITB.prototype.shouldUseServer = function (data) {
// returns true if server data is more recent than local storage or if server storage is correct
if (data.correct == "T" || localStorage.length === 0)
return true;
var ex = localStorage.getItem(eBookConfig.email + ":" + this.divid + "-given");
if (ex === null)
return true;
var storedData = JSON.parse(ex);
if (data.answer == storedData.givenArr)
return true;
var storageDate = new Date(storedData.timestamp);
var serverDate = new Date(data.timestamp);
if (serverDate < storageDate)
return false;
return true;
};

FITB.prototype.enableCompareButton = function () {
this.compareButton.disabled = false;
};

FITB.prototype.setLocalStorage = function (correct) {
FITB.prototype.setLocalStorage = function (data) {
// logs answer to local storage
this.given_arr = [];
for (var i = 0; i < this.blankArray.length; i++)
this.given_arr.push(this.blankArray[i].value);

var now = new Date();
var storageObject = {"givenArr": this.given_arr, "correct": correct, "timestamp": now};
var correct = data.correct;
var storageObject = {"answer": this.given_arr, "correct": correct, "timestamp": now};
localStorage.setItem(eBookConfig.email + ":" + this.divid + "-given", JSON.stringify(storageObject));
};

Expand All @@ -294,8 +250,7 @@ FITB.prototype.startEvaluation = function (logFlag) {
this.evaluateAnswers();
this.renderFITBFeedback();
if (logFlag) { // Sometimes we don't want to log the answer--for example, when timed exam questions are re-loaded
var answerInfo = "answer:" + this.given_arr + ":" + (this.correct ? "correct" : "no");
this.logBookEvent({"event": "fillb", "act": answerInfo, "div_id": this.divid});
this.logBookEvent({"event": "fillb", "act": "submitFITB", "answer": this.given_arr.join(","), "correct": (this.correct ? "T" : "F"), "div_id": this.divid});
}
if (this.useRunestoneServices) {
this.enableCompareButton();
Expand Down Expand Up @@ -328,7 +283,7 @@ FITB.prototype.evaluateAnswers = function () {
} else {
this.correct = false;
}
this.setLocalStorage(this.correct);
this.setLocalStorage({"correct": (this.correct ? "T" : "F")});
};

FITB.prototype.isCompletelyBlank = function () {
Expand Down Expand Up @@ -385,6 +340,10 @@ FITB.prototype.renderFITBFeedback = function () {
=== Functions for compare button ===
==================================*/

FITB.prototype.enableCompareButton = function () {
this.compareButton.disabled = false;
};

FITB.prototype.compareFITBAnswers = function () {
var data = {};
data.div_id = this.divid;
Expand Down
105 changes: 30 additions & 75 deletions runestone/assess/js/mchoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ MultipleChoice.prototype.init = function (opts) {
this.findFeedbacks();
this.createCorrectList();
this.createMCForm();
this.checkServer();
this.checkServer("mChoice");
};

/*====================================
Expand Down Expand Up @@ -277,78 +277,28 @@ MultipleChoice.prototype.randomizeAnswers = function () {
=== Checking/loading from storage ===
===================================*/

MultipleChoice.prototype.checkServer = function () {
// Check if the server has stored answer
if (this.useRunestoneServices) {
var data = {};
data.div_id = this.divid;
data.course = eBookConfig.course;
data.event = "mChoice";
jQuery.getJSON(eBookConfig.ajaxURL + "getAssessResults", data, this.repopulateFromStorage.bind(this)).error(this.checkLocalStorage.bind(this));
} else {
this.checkLocalStorage(); // just go right to local storage
}

};

MultipleChoice.prototype.repopulateFromStorage = function (data, status, whatever) {
if (data !== null) {
if (this.shouldUseServer(data)) {
var answers;
if (this.multipleanswers) {
answers = data.answer.split(",");
} else {
answers = [data.answer.charCodeAt(0) - 97]; // Get index for lowercase letter
}
for (var a = 0; a < answers.length; a++) {
var index = answers[a];
for (var b = 0; b < this.optionArray.length; b++) {
if (this.optionArray[b].input.value == index) {
$(this.optionArray[b].input).attr("checked", "true");
}
}
MultipleChoice.prototype.restoreAnswers = function (data) {
// Restore answers from storage retrieval done in RunestoneBase
var answers = data.answer.split(",");
for (var a = 0; a < answers.length; a++) {
var index = answers[a];
for (var b = 0; b < this.optionArray.length; b++) {
if (this.optionArray[b].input.value == index) {
$(this.optionArray[b].input).attr("checked", "true");
}
this.setLocalStorage();
} else {
this.checkLocalStorage();
}
this.enableMCComparison();
} else {
this.checkLocalStorage();
}
};

MultipleChoice.prototype.shouldUseServer = function (data) {
// returns true if server data is more recent than local storage or if server storage is correct
if (data.correct == "T" || localStorage.length === 0)
return true;
var ex = localStorage.getItem(eBookConfig.email + ":" + this.divid);
if (ex === null)
return true;
var storedData = JSON.parse(ex);
if (this.multipleanswers) {
if (data.answer == storedData.answer)
return true;
} else {
if ((data.answer.charCodeAt(0) - 97).toString() == storedData.answer[0])
return true;
}
var storageDate = new Date(storedData.timestamp);
var serverDate = new Date(data.timestamp);
if (serverDate < storageDate)
return false;
return true;
};

MultipleChoice.prototype.checkLocalStorage = function () {
// Repopulates MCMA questions with a user's previous answers,
// which were stored into local storage.
var len = localStorage.length;
if (len > 0) {
var ex = localStorage.getItem(eBookConfig.email + ":" + this.divid);
var ex = localStorage.getItem(eBookConfig.email + ":" + this.divid + "-given");
if (ex !== null) {
var storedData = JSON.parse(ex);
var answers = storedData.answer;
var answers = storedData.answer.split(",");
for (var a = 0; a < answers.length; a++) {
var index = answers[a];
for (var b = 0; b < this.optionArray.length; b++) {
Expand All @@ -361,20 +311,19 @@ MultipleChoice.prototype.checkLocalStorage = function () {
this.enableMCComparison();
this.getSubmittedOpts(); // to populate givenlog for logging
if (this.multipleanswers) {
this.logMCMAsubmission();
this.logMCMAsubmission(storedData);
} else {
this.logMCMFsubmission();
this.logMCMFsubmission(storedData);
}
}
}
}
};

MultipleChoice.prototype.setLocalStorage = function () {
this.getSubmittedOpts(); // make sure this.givenarray is populateDisplayFeed
MultipleChoice.prototype.setLocalStorage = function (data) {
var timeStamp = new Date();
var storageObj = {"answer": this.givenArray, "timestamp": timeStamp};
localStorage.setItem(eBookConfig.email + ":" + this.divid, JSON.stringify(storageObj));
var storageObj = {"answer": data.answer, "timestamp": timeStamp, "correct": data.correct};
localStorage.setItem(eBookConfig.email + ":" + this.divid + "-given", JSON.stringify(storageObj));
};

/*===============================
Expand All @@ -383,10 +332,12 @@ MultipleChoice.prototype.setLocalStorage = function () {

MultipleChoice.prototype.processMCMASubmission = function (logFlag) {
// Called when the submit button is clicked
this.setLocalStorage();
this.getSubmittedOpts(); // make sure this.givenArray is populated
this.scoreMCMASubmission();
this.setLocalStorage({"correct": (this.correct ? "T" : "F"), "answer": this.givenArray.join(",")});
if (logFlag) {
this.logMCMAsubmission();
var answer = this.givenArray.join(",");
this.logMCMAsubmission({"answer": answer, "correct": this.correct});
}
this.renderMCMAFeedBack();
if (this.useRunestoneServices) {
Expand Down Expand Up @@ -428,13 +379,15 @@ MultipleChoice.prototype.scoreMCMASubmission = function () {
correctIndex++;
}
}
this.correct = (this.correctCount == this.correctList.length);
};



MultipleChoice.prototype.logMCMAsubmission = function () {
var answerInfo = "answer:" + this.givenlog.substring(0, this.givenlog.length - 1) + ":" + (this.correctCount == this.correctList.length ? "correct" : "no");
this.logBookEvent({"event": "mChoice", "act": answerInfo, "div_id": this.divid});
MultipleChoice.prototype.logMCMAsubmission = function (data) {
var answer = data.answer;
var correct = data.correct;
this.logBookEvent({"event": "mChoice", "act": "submitMC", "answer": answer, "correct": correct, "div_id": this.divid});
};


Expand All @@ -461,8 +414,9 @@ MultipleChoice.prototype.renderMCMAFeedBack = function () {

MultipleChoice.prototype.processMCMFSubmission = function (logFlag) {
// Called when the submit button is clicked
this.setLocalStorage();
this.getSubmittedOpts(); // make sure this.givenArray is populated
this.scoreMCMFSubmission();
this.setLocalStorage({"correct": (this.correct ? "T" : "F"), "answer": this.givenArray.join(",")});
if (logFlag) {
this.logMCMFsubmission();
}
Expand All @@ -483,8 +437,9 @@ MultipleChoice.prototype.scoreMCMFSubmission = function () {


MultipleChoice.prototype.logMCMFsubmission = function () {
var answerInfo = "answer:" + this.givenArray[0] + ":" + (this.givenArray[0] == this.correctIndexList[0] ? "correct" : "no");
this.logBookEvent({"event": "mChoice", "act": answerInfo, "div_id": this.divid});
var answer = this.givenArray[0];
var correct = (this.givenArray[0] == this.correctIndexList[0] ? "T" : "F");
this.logBookEvent({"event": "mChoice", "act": "submitMC", "answer": answer, "correct": correct, "div_id": this.divid});
};

MultipleChoice.prototype.renderMCMFFeedback = function (correct, feedbackText) {
Expand Down
Loading