Commit bfac16bb by Alan Boudreault

Display the right/wrong icons and tips the same way we do for MRQs

parent 77eee1ac
...@@ -53,32 +53,41 @@ class MCQBlock(QuestionnaireAbstractBlock): ...@@ -53,32 +53,41 @@ class MCQBlock(QuestionnaireAbstractBlock):
log.debug(u'Received MCQ submission: "%s"', submission) log.debug(u'Received MCQ submission: "%s"', submission)
completed = True completed = True
tips_fragments = [] tips = []
for tip in self.get_tips():
completed = completed and self.is_tip_completed(tip, submission) for choice in self.custom_choices:
if submission in tip.display_with_defaults: choice_tips_fragments = []
tips_fragments.append(tip.render()) for tip in self.get_tips():
completed = completed and self.is_tip_completed(tip, submission)
if self.type == 'rating': if choice.value in tip.display_with_defaults:
formatted_tips = render_template('templates/html/tip_question_group.html', { choice_tips_fragments.append(tip.render())
'self': self,
'tips_fragments': tips_fragments, if self.type == 'choices':
'submission': submission, tips.append({
'submission_display': self.get_submission_display(submission), 'choice': choice.value,
}) 'tips': render_template('templates/html/tip_choice_group.html', {
else: 'self': self,
formatted_tips = render_template('templates/html/tip_choice_group.html', { 'tips_fragments': choice_tips_fragments,
'self': self, 'completed': completed,
'tips_fragments': tips_fragments, })
'completed': completed, })
}) else:
tips.append({
'choice': choice.value,
'tips': render_template('templates/html/tip_question_group.html', {
'self': self,
'tips_fragments': choice_tips_fragments,
'submission': submission,
'submission_display': self.get_submission_display(submission),
})
})
self.student_choice = submission self.student_choice = submission
result = { result = {
'type': self.type, 'type': self.type,
'submission': submission, 'submission': submission,
'completed': completed, 'completed': completed,
'tips': formatted_tips, 'tips': tips,
} }
log.debug(u'MCQ submission result: %s', result) log.debug(u'MCQ submission result: %s', result)
return result return result
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
} }
.mentoring .choices .choice-tips .tip-choice-group, .mentoring .choices .choice-tips .tip-choice-group,
.mentoring .choices .choice-message .message-content { .mentoring .choices .choice-message > div {
position: relative; position: relative;
} }
......
...@@ -14,14 +14,47 @@ function MCQBlock(runtime, element) { ...@@ -14,14 +14,47 @@ function MCQBlock(runtime, element) {
}, },
handleSubmit: function(result) { handleSubmit: function(result) {
if (result.type == 'rating') { if (result.type == 'rating') {
var tipsDom = $(element).parent().find('.messages'), if (_.size(result.tips) > 0) {
tipHtml = (result || {}).tips || ''; var tipsDom = $(element).parent().find('.messages'),
tipHtml = result.tips[0].tips || '';
if(tipHtml) if(tipHtml)
tipsDom.append(tipHtml); tipsDom.append(tipHtml);
}
} }
else { // choices else { // choices
var choiceInputs = $('.choice input', element);
$.each(choiceInputs, function(index, choiceInput) {
var choiceInputDOM = $(choiceInput),
choiceDOM = choiceInputDOM.closest('.choice'),
choiceResultDOM = $('.choice-result', choiceDOM),
choiceTipsDOM = $('.choice-tips', choiceDOM),
choiceTipsCloseDOM;
choiceResultDOM.removeClass('incorrect icon-exclamation correct icon-ok');
if (result.completed && choiceInputDOM.val() == result.submission) {
choiceResultDOM.addClass('correct icon-ok');
}
else if (choiceInputDOM.val() == result.submission || _.isNull(result.submission)) {
choiceResultDOM.addClass('incorrect icon-exclamation');
}
var tips = _.find(result.tips, function(obj) {
return obj.choice == choiceInputDOM.val();
});
if (tips) {
choiceTipsDOM.html(tips.tips);
}
choiceTipsCloseDOM = $('.close', choiceTipsDOM);
choiceResultDOM.off('click').on('click', function() {
showPopup(choiceTipsDOM);
});
});
var messageDOM = $('.choice-message', element), var messageDOM = $('.choice-message', element),
allPopupsDOM = $('.choice-tips, .choice-message', element), allPopupsDOM = $('.choice-tips, .choice-message', element),
clearPopupEvents = function() { clearPopupEvents = function() {
...@@ -43,8 +76,15 @@ function MCQBlock(runtime, element) { ...@@ -43,8 +76,15 @@ function MCQBlock(runtime, element) {
showPopup(messageDOM); showPopup(messageDOM);
} }
else if (result.tips) { else if (result.tips) {
messageDOM.html(result.tips); var tips = _.find(result.tips, function(obj) {
showPopup(messageDOM); return obj.choice == result.submission;
});
if (tips) {
messageDOM.html(tips.tips);
showPopup(messageDOM);
} else {
clearPopupEvents();
}
} }
} }
} }
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
<div class="choices-list"> <div class="choices-list">
{% for choice in custom_choices %} {% for choice in custom_choices %}
<div class="choice"> <div class="choice">
<span class="choice-result"></span> <span class="choice-result icon-2x"></span>
<label class="choice-label"> <label class="choice-label">
<input class="choice-selector" type="radio" name="{{ self.name }}" value="{{ choice.value }}"{% if self.student_choice == choice.value %} checked{% endif %}> {{ choice.content }} <input class="choice-selector" type="radio" name="{{ self.name }}" value="{{ choice.value }}"{% if self.student_choice == choice.value %} checked{% endif %}> {{ choice.content }}
</label> </label>
<div class="choice-tips"></div>
</div> </div>
<div class="choice-tips"></div>
{% endfor %} {% endfor %}
<div class="choice-message"></div> <div class="choice-message"></div>
</div> </div>
......
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