// create empty array for max scores index positions
var max_scores = [];
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["a_score"] = 0;
player.model["ac_score"] = 0;
player.model["c_score"] = 0;
player.model["r_score"] = 0;
player.model["co_score"] = 0;
for (var i = 0; i < player.activity.questions[question_index].queries.length; i++) {
answer = $("#query_answer_" + i).val();
if (i >= 16) {
if (answer == "0") {
player.model["co_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["co_score"]);
}
}
else if (i >= 12) {
if (answer == "0") {
player.model["r_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["r_score"]);
}
}
else if (i >= 8) {
if (answer == "0") {
player.model["c_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["c_score"]);
}
}
else if (i >= 4) {
if (answer == "0") {
player.model["ac_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["ac_score"]);
}
}
else if (i >= 0) {
if (answer == "0") {
player.model["a_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["a_score"]);
}
}
}
console.log("computed a_score: " + player.model["a_score"]);
console.log("computed ac_score: " + player.model["ac_score"]);
console.log("computed c_score: " + player.model["c_score"]);
console.log("computed r_score: " + player.model["r_score"]);
console.log("computed co_score: " + player.model["co_score"]);
// put all scores in an array
var all_scores = new Array (player.model["a_score"], player.model["ac_score"], player.model["c_score"], player.model["r_score"], player.model["co_score"]);
// find max value
var max = all_scores[0];
var maxIndex = 0;
for (var i = 1; i < all_scores.length; i++) {
if (all_scores[i] > max) {
maxIndex = i;
max = all_scores[i];
}
}
console.log("the max score is " + max);
// add first max score to array depending on it's index in the all_scores array
if (maxIndex == 0) {
max_scores.push('Avoidance');
}
if (maxIndex == 1) {
max_scores.push('Accommodation');
}
if (maxIndex == 2) {
max_scores.push('Competion');
}
if (maxIndex == 3) {
max_scores.push('Reactivity');
}
if (maxIndex == 4) {
max_scores.push('Collaboration');
}
// compare max score will all other variables in the all_scores
// array and add them to the max_scores array if they are equal
for (i=0; i < all_scores.length; i++) {
if (max == all_scores[i]) {
if (i !== maxIndex) {
if (i == 1) {
max_scores.push('Accommodation');
}
if (i == 2) {
max_scores.push('Competion');
}
if (i == 3) {
max_scores.push('Reactivity');
}
if (i == 4) {
max_scores.push('Collaboration');
}
}
}
}
// display maxes in the console
console.log("max_scores array contains these indexes " + max_scores);
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);
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() {
console.log("arga_initialization_alert was called");
// 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 answer;
var key;
var question_index = $('[data-type="question"]').attr('data-question_index');
player.model["a_score"] = 0;
player.model["ac_score"] = 0;
player.model["c_score"] = 0;
player.model["r_score"] = 0;
player.model["co_score"] = 0;
for (var i = 0; i < player.activity.questions[question_index].queries.length; i++) {
answer = $("#query_answer_" + i).val();
if (i >= 16) {
if (answer == "0") {
player.model["co_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["co_score"]);
}
}
else if (i >= 12) {
if (answer == "0") {
player.model["r_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["r_score"]);
}
}
else if (i >= 8) {
if (answer == "0") {
player.model["c_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["c_score"]);
}
}
else if (i >= 4) {
if (answer == "0") {
player.model["ac_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["ac_score"]);
}
}
else if (i >= 0) {
if (answer == "0") {
player.model["a_score"] += (parseInt(answer) + 1);
console.log("#query_answer_" + i + ": " + player.model["a_score"]);
}
}
}
console.log("computed a_score: " + player.model["a_score"]);
console.log("computed ac_score: " + player.model["ac_score"]);
console.log("computed c_score: " + player.model["c_score"]);
console.log("computed r_score: " + player.model["r_score"]);
console.log("computed co_score: " + player.model["co_score"]);
// put all scores in an array
var all_scores = new Array (player.model["a_score"], player.model["ac_score"], player.model["c_score"], player.model["r_score"], player.model["co_score"]);
// find max value
var max = all_scores[0];
var maxIndex = 0;
for (var i = 1; i < all_scores.length; i++) {
if (all_scores[i] > max) {
maxIndex = i;
max = all_scores[i];
}
}
console.log("the max score is " + max);
// add first max score to array depending on it's index in the all_scores array
if (maxIndex == 0) {
max_scores.push('Avoidance');
}
if (maxIndex == 1) {
max_scores.push('Accommodation');
}
if (maxIndex == 2) {
max_scores.push('Competion');
}
if (maxIndex == 3) {
max_scores.push('Reactivity');
}
if (maxIndex == 4) {
max_scores.push('Collaboration');
}
// compare max score will all other variables in the all_scores
// array and add them to the max_scores array if they are equal
for (i=0; i < all_scores.length; i++) {
if (max == all_scores[i]) {
if (i !== maxIndex) {
if (i == 1) {
max_scores.push('Accommodation');
}
if (i == 2) {
max_scores.push('Competion');
}
if (i == 3) {
max_scores.push('Reactivity');
}
if (i == 4) {
max_scores.push('Collaboration');
}
}
}
}
// display maxes in the console
console.log("max_scores array contains these indexes " + max_scores);
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 scores
$('[data-block_type="a_score"]').text(player.model['a_score']);
$('[data-block_type="ac_score"]').text(player.model['ac_score']);
$('[data-block_type="c_score"]').text(player.model['c_score']);
$('[data-block_type="a_score"]').text(player.model['r_score']);
$('[data-block_type="co_score"]').text(player.model['co_score']);
// display list of max scores
if (max_scores.length == 1) {
$('[data-block_type="max_results"]').text('You primarily manage conflict through ' + max_scores[0]);
}
else if (max_scores.length == 2) {
$('[data-block_type="max_results"]').text('You primarily manage conflict through ' + max_scores[0] + ' and ' + max_scores[1]);
}
else if (max_scores.length == 3) {
$('[data-block_type="max_results"]').text('You primarily manage conflict through ' + max_scores[0] + ', ' + max_scores[1] + ', and ' + max_scores[2]);
}
else if (max_scores.length == 4) {
$('[data-block_type="max_results"]').text('You primarily manage conflict through ' + max_scores[0] + ', ' + max_scores[1] + ', ' + max_scores[2] + ', and ' + max_scores[3]);
}
else if (max_scores.length == 5) {
$('[data-block_type="max_results"]').text('You primarily manage conflict through ' + max_scores[0] + ', ' + max_scores[1] + ', ' + max_scores[2] + ', ' + max_scores[3] + ', and ' + max_scores[4]);
}
} // end show_variables function
});
player = new Player_custom()