var Activity_manuscript_type = Activity.extend({
current_question: 1,
quiz_complete: false,
answered_all_queries:true,
// this needs to be updated in player.js. Remove it from here once that update has occurred
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();
// treat empty grade as -2
if (grade == "") {
grade = -2;
}
var due_date_passed = (Get_ARGA_Data("due_date_has_passed") == "1");
var msg = "";
var buttons;
// no alert for instructors
if (player.activity.is_student()) {
if (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; in this case we don't actually want to show an alert for standard basic activities
// note that in LaunchPad, the student will see the checkmark in the banner, so this really isn't necessary.
} else {
// msg = "You have completed this activity, and your grade (" + grade + "%) has been submitted.
"
;
// buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
}
// grade has not been submitted
} else {
// if due date has passed, don't do anything for standard basic activities
// (what we *do* do is show an alert if/when the student tries to start the quiz
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, dialogClass:"arga_init_dialog", closeOnEscape: false});
} else {
player.activity.ARGA_initialization_final();
}
},
ARGA_initialization_final: function(decision) {
this._super(decision);
// if decision is "reset", don't do anything with previous answers. otherwise...
if (decision != "reset") {
var a = player.activity;
// by default current_question will be 1 (see above)
// but check to see if the user has already answered some or all questions
for (var i = 1; i < a.questions.length; ++i) {
if (a.questions[i].is_complete()) {
a.current_question = i+1;
}
}
// if user has answered all questions...
if (a.current_question >= a.questions.length) {
// change button label to "Review the ..."
UI_Elements.update_button_label("start_quiz_link", "Review the " + player.md.quiz_title);
// change activity instructions to say that you'll review your answers below
$("#activity_instructions").html("You have completed this activity. Click the button below to review your answers.");
// call complete_quiz so that all questions will be showing when the user clicks the button
a.complete_quiz(false);
// enable quiz
player.enable_quiz();
// else if user has answered some, but not all, questions, jump to the next question
} else if (a.current_question > 1) {
// change button label to "Resume the ..."
UI_Elements.update_button_label("start_quiz_link", "Resume the " + player.md.quiz_title);
// change activity instructions accordingly
$("#activity_instructions").html("Click the button below to resume answering questions for this activity.");
// enable quiz
player.enable_quiz();
}
}
},
restore_saved_answers: function() {
// don't restore saved answers for instructors
if (!player.activity.is_instructor()) {
this._super();
}
},
get_question_number: function(q) {
// always use q.index here
return q.index;
},
show_next_question: function(question) {
// if the quiz has started and we're done, complete the quiz
if (player.quiz_enabled == true && this.current_question >= this.questions.length - 1) {
this.complete_quiz(true);
return;
}
//this.current_question=this.current_question+1;
//this._super(this.questions[this.current_question++]);
var q = "";
if(this.current_question==0)
{
q = this.questions[this.current_question];
}
else
{
q = this.questions[this.current_question+1];
}
this.current_question=this.current_question+1;
// show the question
q.jq.show();
},
complete_quiz: function(scroll_to_bottom) {
// only complete the quiz once!
if (this.quiz_complete == true) {
return;
}
// make sure question_submit_button's are hidden
$(".question_submit_button").hide();
// also question_sequence_navigator should be hidden
$(".question_sequence_navigator").hide();
// show questions
for (var i = 1; i < this.questions.length; ++i) {
this.questions[i].jq.show();
}
var html = ""
+ "Total Score: " + player.activity.total_points_earned
+ " out of " + player.activity.total_points_possible
+ " points (" + player.activity.grade_percent + "%)"
+ "
"
;
player.question_block.append(html);
// since we're using this special score indicator, hide the "standard" question_sequence_review
$(".question_sequence_review").hide();
// scroll to bottom of screen if directed to
if (scroll_to_bottom == true) {
$(window).scrollTo(5000, {
duration:200
, axis:'y'
});
}
this.quiz_complete = true;
}
});
var Player_manuscript_type = Player.extend({
activity_title: null,
// this will be initialized with the jquery of the question block,
// which might be a question_sequence or question_sequence_one_at_a_time
question_block: null,
// this will be set to true when the user is allowed to take the quiz
quiz_enabled: false,
// metadata
md: new Object(),
// no navigation to show, since we only have one section per activity
show_navigation: function() {
var html = "";
// find the question_block
this.question_block = $("[data-block_type=question_sequence]");
if (this.question_block.length == 0) {
this.question_block = $("[data-block_type=question_sequence_one_at_a_time]");
}
if (this.question_block.length == 0) {
this.question_block = $("[data-block_type=questions]");
}
this.question_block.hide();
// Show activity type and title, unless activity data says to hide it
html += "";
if (this.md.activity_type_title != null) {
html += "
" + this.md.activity_type_title + "
";
}
html += this.activity_title
+ "
"
;
console.log(this.md.activity_type_title);
console.log(this.activity_title);
// insert this at the top of the (only) section
$("[data-type=section]").first().prepend(html);
// Instructions for starting the quiz
if (this.md.activity_instructions != null) {
html = ""
+ this.md.activity_instructions
+ "
"
;
// insert this before the first figure block
$("[data-type=figure]").first().before(html);
}
// button for starting the quiz -- after the figure block
html = ""
+ UI_Elements.get_button_html({
id: "start_quiz_button"
, label: this.md.quiz_start_button_label
, fn: "player.start_quiz()"
})
+ "
"
$("[data-type=figure]").first().after(html);
UI_Elements.activate_buttons();
// Show title for questions at start of questions block
html = "";
this.question_block.prepend(html);
},
enable_quiz: function() {
this.quiz_enabled = true;
},
start_quiz: function() {
// if the quiz is not yet enabled...
if (!this.quiz_enabled) {
// if user has instructor-level access, tell them students won't see it
// but let them through
if (player.activity.is_instructor() == true) {
alert("Please note: Students will not be able to view these questions until they have completed the activity. Instructors, however, can view the questions at any time.");
// otherwise don't let them start the quiz!
} else {
alert(this.md.quiz_premature_warning);
return;
}
}
$("#activity_instructions").css("visibility","hidden");
$("#start_quiz_link").hide();
this.question_block.show();
// unless quiz is already complete (meaning we're just reviewing)...
if (this.activity.quiz_complete != true) {
// current_question will be determined in ARGA_initialization_final; if the user started, stopped, and
// came back, current_question might not be 1
var q = this.activity.questions[this.activity.current_question];
// show the question
q.jq.show();
// show the question sequence
var qs = q.question_sequence.index;
$("#question_sequence_index_" + qs).html(this.activity.current_question);
// scroll to bottom of screen
$(window).scrollTo(2000, {
duration:200
, axis:'y'
, onAfter: function() {
// for students, if the due date has passed and the quiz is not complete, warn them that they can't submit
if (player.ARGA_running == true && Get_ARGA_Data("due_date_has_passed") == "1" && player.activity.quiz_complete == false) {
var msg = "The due date for this activity has passed. You can still attempt the questions, but no grade will be recorded.
";
Standard_Dialog.open(msg);
}
}
});
}
},
extract_activity_metadata: function() {
this._super();
// optional metadata val: activity_type_title
this.required_metadata_val("enable_quiz_time", 30);
this.required_metadata_val("activity_instructions", "After you've completed the activity, click the button below to answer questions about what you've learned.");
this.required_metadata_val("quiz_title", "Activity Comprehension Quiz");
this.required_metadata_val("quiz_start_button_label", "Begin the " + this.md.quiz_title);
this.required_metadata_val("quiz_premature_warning", "You must complete the activity before you can take the " + this.md.quiz_title + ".");
// if enable_quiz_time is > 2000, it's almost certainly specified in milliseconds, so convert to seconds
if (this.md.enable_quiz_time > 2000) {
this.md.enable_quiz_time = Math.round(this.md.enable_quiz_time / 1000);
}
},
initialize: function() {
// extract metadata
this.extract_activity_metadata();
// activity title is data-type="title" inside h1
this.activity_title = $("h1").find("[data-type=title]").html();
this.answered_all_queries=true;
this._super();
// first call this.super, then re-initialize the activity to the custom
// activity type for this manuscript
this.activity = new Activity_manuscript_type();
// start a timer that determines when the user is allowed to take the quiz
setTimeout("player.enable_quiz()", (this.md.enable_quiz_time * 1000));
},
initialize2: function() {
this._super();
$("#manuscript").show();
},
init: function() {
this._super();
}
});
player = new Player_manuscript_type();