Commit d884f22e by solashirai Committed by Piotr Mitros

renewed documentation

parent 7667b206
function CrowdsourceHinter(runtime, element, data){
//switching units back to a previous question will make a second hinter start up.
//executeHinter is used to disable the hinter after switching units in an edX course.
var executeHinter = true;
var isShowingHintFeedback = false;
var voted = false;
var correctSubmission = false;
$(".crowdsourcehinter_block", element).hide();
if(!executeHinter){
return;
}
var isShowingHintFeedback = false;
var voted = false;
var correctSubmission = false;
/**
* Set executeHinter to false, disabling the hinter xblock. Triggered by switching units
* in edX course.
* This is a workaround for when a student switches to/from a unit and causes multiple
* instances of the hinter to be running.
*/
function stopScript(){
//This function is used to prevent a particular instance of the hinter from acting after
//switching between edX course's units.
executeHinter = false;
}
Logger.listen('seq_next', null, stopScript);
Logger.listen('seq_prev', null, stopScript);
Logger.listen('seq_goto', null, stopScript);
//send student answer data and receive a hint from ajax call.
//pass data to showHint to actually show hint to student
/**
* Get a hint to show to the student after incorrectly answering a question.
* @param data is data generated by the problem_graded event
*/
function get_hint(data){
$(".crowdsourcehinter_block", element).show();
$.ajax({
......@@ -33,8 +38,10 @@ function CrowdsourceHinter(runtime, element, data){
});
}
//first step to starting student feedback for hints
//this function will be called after student correctly answers question
/**
* Start student hint feedback. This function is called after the student answers
* the question correctly.
*/
function start_feedback(){
$('.csh_correct', element).show();
$(".csh_hint_reveal", element).hide();
......@@ -47,9 +54,12 @@ function CrowdsourceHinter(runtime, element, data){
});
}
//This function will determine whether or not the student correctly answered the question.
//if incorrect, call function to get hint to show to student
//if correct, call function to start student feedback on hints
/**
* Check whether student answered the question correctly and call the appropriate
* function afterwards. Current method for determining correctness if very brittle.
* @param event_type, element are both unused but automatically passed
* @param data is generated by problem_graded event, contains status and data of the problem block
*/
function onStudentSubmission(){ return function(event_type, data, element){
//search method of correctness of problem is brittle due to checking for a class within
//the problem block.
......@@ -61,17 +71,24 @@ function CrowdsourceHinter(runtime, element, data){
}}
Logger.listen('problem_graded', data.hinting_element, onStudentSubmission());
/**
* Modify csh_Hints attributes to show hint to the student.
*/
function showHint(result){
//Show a hint to the student after an incorrect answer is submitted.
$('.csh_Hints', element).attr('student_answer', result.StudentAnswer);
$('.csh_Hints', element).attr('hint_received', result.Hints);
$('.csh_Hints', element).text("Hint: " + result.Hints);
Logger.log('crowd_hinter.showHint', {"student_answer": result.StudentAnswer, "hint_received": result.Hints});
}
/**
* Called by showStudentContribution to append hints into divs created by
* showStudentSubmissoinHistory, after the student answered the question correctly.
* Feedback on hints at this stage consists of upvote/downvote/report buttons.
* @param hint is the first hint that was shown to the student
* @param student_answer is the first incorrect answer submitted by the student
*/
function showHintFeedback(hint, student_answer){
//Append answer-specific hints for each student answer during the feedback stage.
//This appended div includes upvote/downvote/reporting buttons, the hint, and the hint's rating
$(".csh_student_answer", element).each(function(){
if ($(this).find('.csh_answer_text').attr('answer') == student_answer){
var html = "";
......@@ -91,8 +108,12 @@ function CrowdsourceHinter(runtime, element, data){
});
}
/**
* Show options to remove or return reported hints from/to the hint pool. Called after
* correctly answering the question, only visible to staff.
* @param result is the reported hint text
*/
function showReportedFeedback(result){
//For staff use, shows hints that have been reporteded by students and allows for the hints' unreporting/removal.
var html = "";
$(function(){
var template = $('#show_reported_feedback').html();
......@@ -104,10 +125,13 @@ function CrowdsourceHinter(runtime, element, data){
$(".csh_reported_hints", element).append(html);
}
/**
* Append new divisions into html for each answer the student submitted before correctly
* answering the question. showHintFeedback appends new hints into these divs.
* When the hinter is set to show best, only one div will be created.
* @param student_answers is the text of the student's incorrect answer
*/
function showStudentSubmissionHistory(student_answers){
//Append new divisions into html for each answer the student submitted before correctly
//answering the question. showHintFeedback appends new hints into these divs.
//When the hinter is set to show best, only one div will be created
var html = "";
var template = $('#show_answer_feedback').html();
var data = {
......@@ -117,6 +141,14 @@ function CrowdsourceHinter(runtime, element, data){
$(".csh_feedback", element).append(html);
}
/**
* Set up student feedback on hints and contribution of new hints. Incorrect answer(s) and the
* the corresponding hint(s) shown to the student are displayed. Students can upvote/downvote/report
* hints or contribute a new hint for their incorrect answer(s).
* Only one incorrect answer and hint will be shown when the hinter is set to show best.
* @param result is a dictionary of incorrect answers and hints, with the index being the hint and the value
* being the incorrect answer
*/
function showStudentContribution(result){
//Set up the student feedback stage. Each student answer and all answer-specific hints for that answer are shown
//to the student, as well as an option to create a new hint for an answer.
......@@ -153,7 +185,7 @@ function CrowdsourceHinter(runtime, element, data){
});
}
//reported hints have their corresponding answer set to "Reported"
else{
else {
showHintFeedback(hint, student_answer);
}
}
......@@ -162,8 +194,12 @@ function CrowdsourceHinter(runtime, element, data){
}
}
/**
* Create a text input area for the student to create a new hint. This function
* is triggered by clicking the "contribute a new hint" button.
* @param clicked is the "contribute a new hint" button that was clicked
*/
function create_text_input(){ return function(clicked){
//create text input area for contributing a new hint
$('.csh_student_hint_creation', element).each(function(){
$(clicked.currentTarget).show();
});
......@@ -185,6 +221,12 @@ function CrowdsourceHinter(runtime, element, data){
}}
$(element).on('click', '.csh_student_hint_creation', create_text_input($(this)));
/**
* Submit a new hint created by the student to the hint pool. Hint text is in
* the text input area created by create_text_input. Contributed hints are specific to
* incorrect answers. Triggered by clicking the "submit hint" button.
* @param clicked is the "submit hint" button clicked
*/
function submit_new_hint(){ return function(clicked){
//add the newly created hint to the hinter's pool of hints
if($('.csh_student_text_input', element).val().length > 0){
......@@ -203,8 +245,13 @@ function CrowdsourceHinter(runtime, element, data){
}}
$(element).on('click', '.csh_submit_new', submit_new_hint($(this)));
/**
* Send vote data to modify a hint's rating (or mark it as reported). Triggered by
* clicking a button to upvote, downvote, or report the hint (both before and after
* the student correctly submits an answer).
* @param clicked is the rate_hint button clicked (upvote/downvote/report)
*/
function rate_hint(){ return function(clicked){
//send info to hinter indicating whether the hint was upvoted, downvoted, or reported
rating = clicked.currentTarget.attributes['data-rate'].value;
if(!voted || rating=="report"){
if (rating == "report"){
......@@ -223,9 +270,12 @@ function CrowdsourceHinter(runtime, element, data){
}}
$(element).on('click', '.csh_rate_hint', rate_hint($(this)));
/**
* Remove a reported hint from the reported feedback area (for staff only). Hints
* are removed from the feedback area regardless of whether they are to be permanently removed
* from the hint pool or not. Called by staff_rate_hint.
*/
function removeFeedback(){
//remove a hint from the staff feedback area after a staff member has
//returned the hint to the hint pool or removed it permanently
$('.csh_hint_value', element).each(function(){
if($(this).attr('value') == hint){
$(this).remove();
......@@ -233,8 +283,12 @@ function CrowdsourceHinter(runtime, element, data){
});
}
/**
* Send staff rating data to determine whether or not a reported hint will be removed from the
* hint pool or not. Triggered by clicking a staff_rate button.
* @param clicked is the csh_staff_rate button that was clicked
*/
function staff_rate_hint(){ return function(clicked){
//Staff "rating" removes or returns a reported hint from/to the hinter's pool of hints
hint = $(clicked.currentTarget).parent().find(".csh_hint").text();
rating = clicked.currentTarget.attributes['data-rate'].value
student_answer = "Reported";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment