var Activity_subtype = Activity_manuscript_type.extend({
submit_question: function (question_index) {
//safe_log("submit_question");
// the arg may be a number or an event object; in the latter case...
if (typeof question_index == "object") {
// extract the question_index from the object
question_index = question_index.data.question_index;
}
//force all queries to be answered before doing anything.
var allQueriesAnswered = true;
for (var i = 0; i < player.activity.questions[question_index].queries.length; i++) {
var x = player.activity.questions[question_index].queries[i].user_has_answered();
if (!x) {
allQueriesAnswered = false;
}
}
if (!allQueriesAnswered) {
$("
Please answer all of the questions before submitting.
").dialog({
modal: true,
buttons: [{
text: "OK",
click: function () {
$(this).dialog("close");
}
}]
});
return false;
}
this._super(question_index);
return false;
}, // end submit_question
show_question_feedback: function(question, is_correct, try_again) {
safe_log("show_question_feedback");
//safe_log(question);
// remove prior feedback if there
$("#question_feedback_" + question.index).remove();
// if we don't have any feedback at all, return
if (question.md.feedback == null && question.md.feedback_correct == null && question.md.feedback_incorrect == null && question.md.feedback_hint == null) {
return;
}
var feedback = question.md.feedback_correct;
//safe_log("feedback: " + feedback);
var fb_array = feedback.split("::");
var $ques = question.jq.find("table tbody");
var fb_array_length = fb_array.length;
for (var i = 1; i < fb_array_length; i++) {
//var tr_num = parseInt(RegExp.$1, 10) + 1;
var tr_num = i + 1;
//safe_log("iteration: " + tr_num);
// correct_answer will be 0 for checked and 1 for unchecked
var correct_answer = question.queries[(tr_num - 2)].correct_answer_index;
//safe_log("correct_answer: " + correct_answer);
// grade will be 0 if they got it wrong, 100 if they got it right
var grade = question.queries[(tr_num - 2)].grade;
//safe_log("grade: " + grade);
// set pre text for feedback based on whether the answer should have been checked
var pre_text;
// should be checked but wasn't
if (correct_answer == 0 && grade == 0) {
pre_text = "Sorry, this should have been checked. ";
}
// should be checked and was
if (correct_answer == 0 && grade == 100) {
pre_text = "Correct. ";
}
// shouldn't be checked and wasn't
if (correct_answer == 1 && grade == 100) {
pre_text = "Correct. ";
}
// shouldn't be checked and was
if (correct_answer == 1 && grade == 0) {
pre_text = "Sorry, this shouldn't have been checked. ";
}
//safe_log("Test matches for i:" + tr_num);
var td = $ques.find("tr:nth-child(" + tr_num + ") td:nth-child(2)");
//safe_log(td);
var fb_str = fb_array[i];
fb_str = fb_str.replace(/([^:]+): /, "");
td.append("" + pre_text + fb_str + "");
}
} // end show_question_feedback
}); // end Activity_subtype
FB_Query = FB_Query.extend({
user_has_answered: function () {
var ch_num = $("#manuscript").data("chapter-number");
if (ch_num === 4 || ch_num === 11 || ch_num === 12 || ch_num === 6 || ch_num === 7 || ch_num === 8 || ch_num === 9) {
return true;
} else {
var x = jQuery.trim($("#query_answer_" + this.query_index).val());
if (jQuery.trim($("#query_answer_" + this.query_index).val()) != "") {
return true;
} else {
return false;
}
}
}
});
DD_Query = DD_Query.extend({
user_has_answered: function () {
var x = $('#query_answer_' + this.query_index).val();
if ($('#query_answer_' + this.query_index).val() != -1) {
return true;
} else {
return false;
}
}
});
MA_Query = MA_Query.extend({
// this won't be called until all matches have been made
// so we can just return true
user_has_answered: function () {
return true;
}
});
MC_Query = MC_Query.extend({
user_has_answered: function () {
if (typeof $('input:radio[name=query_answer_' + this.query_index + ']:checked').val() != "undefined") {
return true;
}
else {
return false;
}
}
});
Essay_Query = Essay_Query.extend({
user_has_answered: function () {
if ($.trim($("#query_answer_" + this.query_index).val() != "")) {
return true;
} else {
return false;
}
}
});
CB_Query = CB_Query.extend({
user_has_answered: function () {
return true;
}
});
var Player_subtype = Player_manuscript_type.extend({
//cfg_removeRawHtmlDivs: "on",
//cfg_showAnswer: "on",
//cfg_showAnswerAutoWrapThis: "off",
//cfg_Box_moveTitle: "all",
//cfg_Box_moveTitleExclude: "",
//cfg_Figures_targetDefault: "_blank",
//cfg_Figures_resizeDivWidth: "off",
cfg_Figures_autoHtml: "on",
cfg_LH_autoHtml: "on",
//cfg_LH_externalTargetDefault: "_pop",
cfg_LH_internalTargetDefault: "_pop",
cfg_LH_ebookTargetDefault: "_pop",
//cfg_LH_imageTargetDefault: "_blank",
//cfg_LH_useOpenContent: "on",
//cfg_LH_useLinksFile: "on",
//cfg_Glossary_hoverTerms: "on",
//cfg_Glossary_useStickyDiv: "on",
//cfg_Glossary_hoverTermsNoClick: "",
initialize: function() {
this._super();
// enable additional functionality
this.xrefs = new XRefs_manuscript_subtype();
this.glossary = new Glossary_manuscript_subtype();
this.figures = new Figures_manuscript_subtype();
// after we call this.super, re-initialize the activity to the custom
// activity type for this subtype
this.activity = new Activity_subtype();
},
initialize2: function() {
this._super();
// enable link handler
var link_handler = new LinkHandler();
}
});
player = new Player_subtype();