Commit e0f4ed5e by solashirai

Merge pull request #7 from solashirai/sola/working

fixed issue with answers containing spaces
parents 87b53fbe 4287fa6a
......@@ -286,10 +286,10 @@ class CrowdsourceHinter(XBlock):
# for the time being only the first answer/hint pair will be shown to the studen
if self.used[0] in self.hint_database[self.incorrect_answers[0]]:
# add new key (hint) to used_hint_answer_text with a value (incorrect answer)
used_hint_answer_text[json.dumps(self.used[0])] = json.dumps(self.incorrect_answers[0])
used_hint_answer_text[self.used[0]] = self.incorrect_answers[0]
else:
# if the student's answer had no hints (or all the hints were reported and unavailable) return None
used_hint_answer_text[None] = json.dumps(self.incorrect_answers[0])
used_hint_answer_text[None] = self.incorrect_answers[0]
self.incorrect_answers = []
self.used = []
return used_hint_answer_text
......
<script type='x-tmpl/mustache' id='show_hint_rating_ux'>
<div class='csh_hint_value' value="{{hintText}}">
<div class='csh_hint_value' value="{{hintIdentifier}}">
<div class='csh_hint_data'>
<div class="csh_hint">You received the following hint: <b>{{hintText}}</b></div>
</div>
......@@ -18,7 +18,7 @@
</script>
<script type="x-tmpl/mustache" id="show_reported_moderation">
<div class="csh_hint_value" value ="{{reportedHintText}}">
<div class="csh_hint_value" value ="{{reportedHintIdentifier}}">
<div class="csh_hint">{{reportedHintText}}</div>
<div role="button" class="csh_staff_rate" data-rate="unreport" aria-label="unreport">
<u><b>Return hint for use in the hinter</b></u>
......@@ -46,11 +46,11 @@
<script type="x-tmpl/mustache" id="show_student_submission">
<div class="csh_student_answer">
<h class="csh_answer_text" answer={{answer}}>
<h class="csh_answer_text" answer={{answerIdentifier}}>
<div role="button" class="csh_reveal_info">Help us improve hints for this problem </div>
<div class="csh_user_info" style="display: none;"> <br> Submitting an incorrect answer for this problem provides you with a hint specific to the mistake that you made - these hints are made by other students who made the same mistake as you did. Help to make the hints for this problem better by rating the hint that you received, or if you might have better advice to give other students, submit a new hint! <br> If you choose to submit a new hint, keep in mind that the hints are specific to one incorrect answer; specific advice (perhaps on some aspect of the problem that you overlooked) is more helpful than generic advice.</div>
<br>
Your original answer was: <b>{{answer}}</b></h>
Your original answer was: <b>{{answerText}}</b></h>
</div>
</script>
......
......@@ -119,7 +119,7 @@ function CrowdsourceHinter(runtime, element, data){
* @param student_answer is the first incorrect answer submitted by the student
*/
function showStudentHintRatingUX(hint, student_answer){
var hintRatingUXTemplate = $(Mustache.render($('#show_hint_rating_ux').html(), {hintText: hint}));
var hintRatingUXTemplate = $(Mustache.render($('#show_hint_rating_ux').html(), {hintIdentifier: encodeURI(hint), hintText: hint}));
$('.csh_answer_text', element).append(hintRatingUXTemplate);
var hintCreationTemplate = $(Mustache.render($('#add_hint_creation').html(), {}));
$('.csh_answer_text', element).append(hintCreationTemplate);
......@@ -134,7 +134,7 @@ function CrowdsourceHinter(runtime, element, data){
* @param reportedHint is the reported hint text
*/
function showReportedModeration(reportedHint){
var reportedModerationTemplate = $(Mustache.render($('#show_reported_moderation').html(), {reportedHintText: reportedHint}));
var reportedModerationTemplate = $(Mustache.render($('#show_reported_moderation').html(), {reportedHintIdentifier: encodeURI(reportedHint), reportedHintText: reportedHint}));
$('.csh_reported_hints', element).append(reportedModerationTemplate);
}
......@@ -145,7 +145,7 @@ function CrowdsourceHinter(runtime, element, data){
* @param student_answers is the text of the student's incorrect answer
*/
function showStudentSubmissionHistory(student_answer){
var showStudentSubmissionTemplate = $(Mustache.render($('#show_student_submission').html(), {answer:student_answer}));
var showStudentSubmissionTemplate = $(Mustache.render($('#show_student_submission').html(), {answerIdentifier: encodeURI(student_answer), answerText: student_answer}));
$('.csh_student_submission', element).append(showStudentSubmissionTemplate);
}
......@@ -169,7 +169,7 @@ function CrowdsourceHinter(runtime, element, data){
}
$.each(result, function(index, value) {
if(value != "Reported"){
showStudentSubmissionHistory($.parseJSON(value));
showStudentSubmissionHistory(value);
student_answer = value;
hint = index;
//hints return null if no answer-specific hints exist
......@@ -213,7 +213,10 @@ function CrowdsourceHinter(runtime, element, data){
function submitNewHint(){ return function(submitHintButtonHTML){
//add the newly created hint to the hinter's pool of hints
if($('.csh_student_text_input', element).val().length > 0){
var studentAnswer = unescape(submitHintButtonHTML.currentTarget.attributes['answer'].value);
//encodeURI is used on the answer string when it is passed to mustache due to errors that
//arise in answers that contain spaces. Since the original answer is not in the encoded form,
//we must use the decoded form here.
var studentAnswer = decodeURI(submitHintButtonHTML.currentTarget.attributes['answer'].value);
var newHint = unescape($('.csh_student_text_input').val());
$('.csh_submitbutton', element).show();
$.ajax({
......@@ -242,7 +245,10 @@ function CrowdsourceHinter(runtime, element, data){
$('.csh_hint_text', element).attr('rating', rating);
$('.csh_hint', element).attr('rating', rating);
hint = $('.csh_hint_text', element).attr('hint_received');
student_answer = $('.csh_hint_text', element).attr('student_answer');
//encodeURI is used on the answer string when it is passed to mustache due to errors that
//arise in answers that contain spaces. Since the original answer is not in the encoded form,
//we must use the decoded form here.
student_answer = decodeURI($('.csh_hint_text', element).attr('student_answer'));
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
......@@ -257,7 +263,10 @@ function CrowdsourceHinter(runtime, element, data){
function reportHint(){ return function(reportHintButtonHTML){
hint = $('.csh_hint_text', element).attr('hint_received');
student_answer = $('.csh_hint_text', element).attr('student_answer');
//encodeURI is used on the answer string when it is passed to mustache due to errors that
//arise in answers that contain spaces. Since the original answer is not in the encoded form,
//we must use the decoded form here.
student_answer = decodeURI($('.csh_hint_text', element).attr('student_answer'));
$('.csh_hint_text', element).text('This hint has been reported for review.');
$('.csh_hint', element).text('This hint has been reported for review.');
$.ajax({
......
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