var Activity_subtype = Activity_manuscript_type.extend({
submit_question: function (question_index) {
// 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({
buttons: [{
text: "OK",
click: function () {
$(this).dialog("close");
}
}]
});
//alert("answer all questions!");
return false;
}
var answer;
var key;
player.model["score"] = 0;
player.model["val0"] = 0;
player.model["val1"] = 0;
player.model["val2"] = 0;
player.model["val3"] = 0;
player.model["val4"] = 0;
for (var i = 0; i < player.activity.questions[question_index].queries.length; i++) {
answer = $("#query_answer_" + i).val();
if (answer !== "-1") {
player.model["val" + answer]++;
console.log("val" + answer + ": " + player.model["val" + answer]);
}
}
//console.log("computed score: " + player.model["score"]);
this._super(question_index);
// 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;
}
player.activity.questions[question_index].checkModelUpdateConditionals(question_index);
//var executedNextStep = player.activity.questions[question_index].checkNextStepConditionals(question_index);
//player.sendModelToServer();
//check if we need to show the next button
//safe_log(player.get_current_section_jq().find(".next_section_button").attr("role"));
player.get_current_section_jq().find(".next_section_button").show();
//STG set focus on continue butotn, so 'continue' button shows up in the window, not below
$('button.next_section_button').focus();
//insert any variables that may be newly displayed in the question feedback
player.show_variables();
//move the feedback into a nice popup
$("[data-question_index=" + question_index + "]").find(".query_mc_feedback_correct_incorrect").dialog({
buttons: [{
text: "OK",
click: function () {
$(this).dialog("close");
}
}]
});
//look for any advanced answer choice feedback and show it as a dialog
// player.process_question_feedback_conditional_display();
//$("#next_button2").show();
//player.show_section(1);
// $("#navItem_1").show();
// $("#next_button2").show();
//$("#navItem_1").show();
$("#next_button2").show();
player.show_section(1);
//return false;
return false;
},
show_grade_saved_message: function() {
// if the user has answered all queries AND the user hasn't been told this already,
// tell them now
if (player.activity.answered_all_queries && !player.user_has_received_completion_alert) {
setTimeout('Standard_Dialog.alert("You have completed the activity, and your grade has been submitted.");', 20);
player.user_has_received_completion_alert = true;
}
},
restore_saved_answers: function() {
// skip page queries (questions[0])
for (var i = 1; i < this.questions.length; ++i) {
var question = this.questions[i];
// prepare for question_report_text questions
var query_responses;
if (question.md_set("question_report_text")) {
query_responses = "" + Get_ARGA_QuestionData(this.get_question_number(question))
query_responses = query_responses.split(this.query_responses_separator);
}
var restored_all_answers = true;
var all_answers_correct = true;
for (var j = 0; j < question.queries.length; ++j) {
var query = question.queries[j];
var saved_answer, saved_grade;
// get saved answer and grade out of the questionData for question_report_text questions
if (question.md_set("question_report_text")) {
if (query_responses[j] != null) {
var arr = query_responses[j].split(this.query_responses_grade_separator);
saved_answer = arr[0];
saved_grade = arr[1];
} else {
saved_grade = saved_answer = "";
}
// or out of learnerResponse / questionData for single-query questions
} else {
var ARGA_question_number = this.get_query_number(question, j);
saved_answer = Get_ARGA_LearnerResponse(ARGA_question_number);
// we stored the original grade in questionData
saved_grade = Get_ARGA_QuestionData(ARGA_question_number)
}
// if we found a grade...
if (saved_grade !== "" && saved_grade >= 0) {
// restore the answer
query.restoreAnswerFromARGA(saved_answer);
query.setGrade(saved_grade);
// then re-render the query in review mode
query.jq.html(query.getHTML("review"));
if (query.isCorrect() == false) {
all_answers_correct = false;
}
} else {
restored_all_answers = false;
}
}
if (restored_all_answers) {
// update the submit div for the question
this.update_question_action_div(i);
// Show appropriate feedback. If the question responses were submitted,
// the student must have finished the question, so we don't have to worry
// about hints.
this.show_question_feedback(question, all_answers_correct, false);
// if the item is in a sequence, show the next question
this.show_next_question(question);
// NEED TO CHECK TO MAKE SURE THIS IS WORKING PROPERLY
// If the question is in a sequence and the sequence is complete, call show_closing_material
var qs = question.question_sequence;
if (qs != null && qs.sequence_complete == "partial") {
this.show_closing_material(qs.index);
}
// update section status
player.update_section_status();
player.activity.calculate_score();
}
}
},
ARGA_initialization_alert: function() {
// This overrides the standard ARGA initialization message, which doesn't
// tell the user he/she can resubmit (or tell him his grade)
var grade = Get_ARGA_Grade();
var due_date_passed = (Get_ARGA_Data("due_date_has_passed") == "1");
var msg = "";
var buttons;
due_date_passed = false;
if (grade != "" && grade != null && grade >= 0) {
// if resubmissions are allowed...
if (player.md.allow_resubmission == "true") {
// if due date has not passed, give the student the option of resubmitting or reviewing
if (!due_date_passed) {
msg = "You have completed this activity, and your grade (" + grade + "%) has been submitted. Would you like to:
"
+ "- Keep your current grade and review your previous answers
"
+ "- Or reset your submission and try the activity again?
"
+ "
"
;
buttons = [ {text:"Keep current grade", click: player.activity.ARGA_initialization_final}
, {text: "Try Activity Again", click: function() {player.activity.ARGA_initialization_final("reset")}}
];
} else {
msg = "You have completed this activity, and your grade (" + grade + "%) has been submitted. Since the due date for the activity has now passed, you cannot re-submit answers to the activity questions.
"
buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
}
// resubmissions are not allowed
} else {
msg = "You have completed the activity, and your grade has been submitted.
"
;
buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
}
// grade has not been submitted
} else {
// if due date has passed, tell the user "tough luck". Otherwise show nothing.
if (due_date_passed) {
msg = "The due date for this activity has passed. You can still review the activity, but no answers will be submitted and no grade will be recorded.
"
;
buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
}
}
// if we need a message, show it in a jquery UI dialog
if (msg != "") {
msg = "" + msg + "
";
$("body").append(msg);
$("#arga_init_dialog").dialog({title:"Please Note", width:450, modal:true, buttons: buttons});
} else {
player.activity.ARGA_initialization_final();
}
},
calculate_score: function () {
var question_index = $('[data-type="question"]').attr('data-question_index');
var answer;
var key;
player.model["score"] = 0;
player.model["val0"] = 0;
player.model["val1"] = 0;
player.model["val2"] = 0;
player.model["val3"] = 0;
player.model["val4"] = 0;
for (var i = 0; i < player.activity.questions[question_index].queries.length; i++) {
answer = $("#query_answer_" + i).val();
if (answer !== "-1") {
player.model["val" + answer]++;
console.log("val" + answer + ": " + player.model["val" + answer]);
}
}
console.log("computed score: " + player.model["score"]);
player.show_variables();
}
});
var Player_custom = Player_subtype.extend({
show_variables: function () {
//look through all the p nodes
var section = this.get_current_section_jq();
var regex = new RegExp("{(.+?)}", "gmi");
$(section).find("p, label, option, table").each(function (index, element) {
var text = $(element).html();
text = text.replace(regex, function (a, b) {
return eval("player." + b);
});
$(element).html(text);
});
var div_score = 0;
// display the appropriate results
// first, we need to know how many questions are on the page
var num_q = $('[data-type="query"]').length;
//All of the activities have 9 questions
if (num_q == 9) {
var i = 0;
//if any answer has five or more, we show it
for (i=0; i<5; i++) {
var key = "val" + i;
if (key in player.model && player.model[key] !== undefined) {
if (player.model[key] > 4) {
var result = "[data-block_type='results_" + key + "']";
var result_title = "[data-block_type='results_" + key + "_title']";
$(result).addClass('show_result');
$(result_title).addClass('show_result');
$('[data-block_type="results_val_mixed"]').removeClass('show_result');
$('[data-block_type="results_val_mixed_title"]').removeClass('show_result');
return;
}
}
}
// otherwise we have at least one of every answer
$('[data-block_type="results_val_mixed"]').addClass('show_result');
$('[data-block_type="results_val_mixed_title"]').addClass('show_result');
} // end num_q == 9
else if (num_q == 5) {
var i;
var big_key = undefined;
for (i=0; i<3; i++) {
var key = "val" + i;
if (key in player.model && player.model[key] !== undefined) {
if (player.model[key] > 2) {
var result;
if (player.model[key] == 5) {
result = "[data-block_type='results_" + key + "_5']";
}
else {
result = "[data-block_type='results_" + key + "_3']";
}
safe_log("setting big_key to " + key);
big_key = key;
$(result).addClass('show_result');
$('[data-block_type="results_val_mixed"]').removeClass('show_result');
$('[data-block_type="summary"]').show();
}
}
}
// If we get here then they have chosen at least one of each type
// and we will give them a generic response
if (big_key === undefined) {
safe_log("big_key: " + big_key);
$('[data-block_type="results_val_mixed"]').addClass('show_result');
$('[data-block_type="summary"]').hide();
}
} // end num_q == 5
}, // end show_variables function
});
player = new Player_custom()