Commit a2e3724d by Xavier Antoviaque

Merge pull request #16 from aboudreault/remove-show-answer

Remove show answer
parents 4fb8d0bc bf986ecf
...@@ -132,6 +132,10 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -132,6 +132,10 @@ class MentoringBlock(XBlockWithLightChildren):
if self.completed: if self.completed:
completed = True completed = True
# server-side check to not set completion if the max_attempts is reached
if self.max_attempts > 0 and self.num_attempts >= self.max_attempts:
completed = False
if completed: if completed:
message = self.get_message_html('completed') message = self.get_message_html('completed')
else: else:
......
...@@ -78,7 +78,3 @@ ...@@ -78,7 +78,3 @@
.mentoring .choices-list .choice-selector { .mentoring .choices-list .choice-selector {
margin-right: 5px; margin-right: 5px;
} }
.mentoring .show-answer {
display: none;
}
...@@ -94,20 +94,7 @@ function MCQBlock(runtime, element) { ...@@ -94,20 +94,7 @@ function MCQBlock(runtime, element) {
function MRQBlock(runtime, element) { function MRQBlock(runtime, element) {
return { return {
init: function() {
var answerButton = $('button', element);
answerButton.on('click', _.bind(this.toggleAnswers, this));
this.showAnswerButton();
},
submit: function() { submit: function() {
// hide answers
var choiceInputDOM = $('.choice input', element),
choiceResultDOM = $('.choice-answer', choiceInputDOM.closest('.choice'));
choiceResultDOM.removeClass(
'checkmark-incorrect icon-exclamation fa-exclamation checkmark-correct icon-ok fa-check'
);
var checkedCheckboxes = $('input[type=checkbox]:checked', element), var checkedCheckboxes = $('input[type=checkbox]:checked', element),
checkedValues = []; checkedValues = [];
...@@ -125,24 +112,17 @@ function MRQBlock(runtime, element) { ...@@ -125,24 +112,17 @@ function MRQBlock(runtime, element) {
result.message + '</div>'); result.message + '</div>');
} }
var answers = []; // used in displayAnswers
$.each(result.choices, function(index, choice) { $.each(result.choices, function(index, choice) {
var choiceInputDOM = $('.choice input[value='+choice.value+']', element), var choiceInputDOM = $('.choice input[value='+choice.value+']', element),
choiceDOM = choiceInputDOM.closest('.choice'), choiceDOM = choiceInputDOM.closest('.choice'),
choiceResultDOM = $('.choice-result', choiceDOM), choiceResultDOM = $('.choice-result', choiceDOM),
choiceAnswerDOM = $('.choice-answer', choiceDOM),
choiceTipsDOM = $('.choice-tips', choiceDOM), choiceTipsDOM = $('.choice-tips', choiceDOM),
choiceTipsCloseDOM; choiceTipsCloseDOM;
/* update our answers dict */
answers.push({
input: choiceInputDOM,
answer: choice.completed ? choiceInputDOM.attr('checked') : !choiceInputDOM.attr('checked')
});
choiceResultDOM.removeClass( choiceResultDOM.removeClass(
'checkmark-incorrect icon-exclamation fa-exclamation checkmark-correct icon-ok fa-check' 'checkmark-incorrect icon-exclamation checkmark-correct icon-ok fa-check'
); );
/* show hint if checked or max_attempts is disabled */ /* show hint if checked or max_attempts is disabled */
if (result.completed || choiceInputDOM.prop('checked') || options.max_attempts <= 0) { if (result.completed || choiceInputDOM.prop('checked') || options.max_attempts <= 0) {
if (choice.completed) { if (choice.completed) {
...@@ -159,46 +139,8 @@ function MRQBlock(runtime, element) { ...@@ -159,46 +139,8 @@ function MRQBlock(runtime, element) {
messageView.showMessage(choiceTipsDOM); messageView.showMessage(choiceTipsDOM);
}); });
choiceAnswerDOM.off('click').on('click', function() {
messageView.showMessage(choiceTipsDOM);
});
}); });
}
this.answers = answers;
this.showAnswerButton(options);
},
showAnswerButton: function(options) {
var button = $('.show-answer', element);
var is_enabled = options && (options.num_attempts >= options.max_attempts);
if (is_enabled && _.isArray(this.answers)) {
button.show();
}
else {
button.hide();
}
},
toggleAnswers: function() {
var showAnswerButton = $('button span', element);
var answers_displayed = this.answers_displayed = !this.answers_displayed;
_.each(this.answers, function(answer) {
var choiceResultDOM = $('.choice-answer', answer.input.closest('.choice'));
choiceResultDOM.removeClass('checkmark-correct icon-ok fa-check');
if (answers_displayed) {
if (answer.answer)
choiceResultDOM.addClass('checkmark-correct icon-ok fa-check');
showAnswerButton.text('Hide Answer(s)');
}
else {
showAnswerButton.text('Show Answer(s)');
}
});
}
}; };
} }
...@@ -14,15 +14,9 @@ ...@@ -14,15 +14,9 @@
</input> </input>
</label> </label>
</div> </div>
<span class="choice-answer icon-2x"></span>
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
{{feedback.body_html|safe}} {{feedback.body_html|safe}}
</div> </div>
</fieldset> </fieldset>
<div class="show-answer">
<button class="show">
<span class="show-label">Show Answer(s)</span>
</button>
</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