Commit 7ab8773d by Alan Boudreault

Fix various issues and modified the main behavior of answers.

parent 0decd359
......@@ -249,7 +249,6 @@ class String(LightChildField):
class Integer(LightChildField):
def __init__(self, *args, **kwargs):
self.value = kwargs.get('default', 0)
print self.value
def __str__(self):
return str(self.value)
......
......@@ -80,7 +80,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
# What's the proper way to get my value saved? it doesn't work without '.value'
# this is incorrect and the num_attempts is resetted if we restart the server.
self.num_attempts.value = int(self.num_attempts) + 1
self.num_attempts.value = int(self.num_attempts) + 1 if self.max_attempts else 0
max_attempts_reached = False
if self.max_attempts:
......@@ -89,9 +89,9 @@ class MRQBlock(QuestionnaireAbstractBlock):
max_attempts_reached = num_attempts >= max_attempts
if max_attempts_reached and (not completed or num_attempts > max_attempts):
log.debug(u'MRQ max attempts reached');
completed = True
self.message += u' You have reached the maximum number of attempts for this question. Your next answers won''t be saved. You can check the answer(s) using the "Show Answer(s)" button.'
self.message += u' You have reached the maximum number of attempts for this question. ' \
'Your next answers won''t be saved. You can check the answer(s) using the "Show Answer(s)" button.'
else: # only save the student_choices if there was a attempt left, might be incorrect or unuseful
self.student_choices = submissions
......
......@@ -51,7 +51,7 @@
.mentoring .progress .indicator {
display: inline-block;
margin-top: 5px;
vertical-align: middle;
}
.mentoring .progress .indicator .checkmark-correct {
......
......@@ -11,21 +11,26 @@
margin: 10px 0;
}
.mentoring .choices .choice-checkbox {
display: inline-block;
margin-top: 5px;
margin-bottom: 5px;
}
.mentoring .choices .choice-result {
padding-right: 10px;
display: inline-block;
width: 40px;
vertical-align: middle;
}
.mentoring .choices .choice-result.correct {
.mentoring .choices .choice-result.correct, .choice-answer.correct {
color: #006600;
position: relative;
top: -3px;
}
.mentoring .choices .choice-result.incorrect {
margin-right: 10px;
padding-left: 10px;
padding-right: 10px;
.mentoring .choices .choice-result.incorrect, .choice-answer.incorrect {
text-align:center;
color: #ff0000;
}
......
......@@ -35,7 +35,7 @@ function MRQBlock(runtime, element) {
if (_.isUndefined(this.answers))
showAnswerButton.hide();
else
showAnswerButton.on('click', _.bind(this.displayAnswers, this));
showAnswerButton.on('click', _.bind(this.toggleAnswers, this));
}
},
......@@ -44,6 +44,11 @@ function MRQBlock(runtime, element) {
},
submit: function() {
// hide answers
var choiceInputDOM = $('.choice input', element),
choiceResultDOM = $('.choice-answer', choiceInputDOM.closest('.choice'));
choiceResultDOM.removeClass('incorrect icon-exclamation correct icon-ok');
var checkedCheckboxes = $('input[type=checkbox]:checked', element),
checkedValues = [];
......@@ -91,7 +96,8 @@ function MRQBlock(runtime, element) {
});
choiceResultDOM.removeClass('incorrect icon-exclamation correct icon-ok');
if (choiceInputDOM.prop('checked')) { /* show hint if checked */
/* show hint if checked or max_attempts is disabled */
if (choiceInputDOM.prop('checked') || _.isNull(result.max_attempts)) {
if (choice.completed) {
choiceResultDOM.addClass('correct icon-ok');
} else if (!choice.completed) {
......@@ -112,21 +118,19 @@ function MRQBlock(runtime, element) {
this.renderAttempts();
},
displayAnswers: function() {
toggleAnswers: function() {
var showAnswerButton = $('button span', element);
var answers_displayed = this.answers_displayed = !this.answers_displayed;
_.each(this.answers, function(answer) {
var choiceResultDOM = $('.choice-result', answer.input.closest('.choice'));
var choiceResultDOM = $('.choice-answer', answer.input.closest('.choice'));
choiceResultDOM.removeClass('incorrect icon-exclamation correct icon-ok');
if (answers_displayed) {
answer.input.attr('checked', answer.answer);
if (answer.answer)
choiceResultDOM.addClass('correct icon-ok');
showAnswerButton.text('Hide Answer(s)');
}
else {
answer.input.attr('checked', false);
showAnswerButton.text('Show Answer(s)');
}
});
......
......@@ -4,10 +4,17 @@
<div class="choices-list">
{% for choice in custom_choices %}
<div class="choice">
<span class="choice-result icon-2x"></span>
<div class="choice-checkbox">
<label class="choice-label">
<input class="choice-selector" type="checkbox" name="{{ self.name }}" value="{{ choice.value }}"{% if choice.value in self.student_choices %} checked{% endif %}> {{ choice.content }}
<input class="choice-selector" type="checkbox" name="{{ self.name }}"
value="{{ choice.value }}"
{% if choice.value in self.student_choices %} checked{% endif %}>
{{ choice.content }}
</input>
</label>
<span class="choice-result icon-2x"></span>
</div>
<span class="choice-answer icon-2x"></span>
<div class="choice-tips"></div>
</div>
{% endfor %}
......
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