Commit 0ca70266 by Xavier Antoviaque

MRQ: Add message popup to MRQ, upon any click on submit

parent b362bc34
...@@ -78,6 +78,7 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -78,6 +78,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
'submissions': submissions, 'submissions': submissions,
'completed': completed, 'completed': completed,
'choices': results, 'choices': results,
'message': self.message,
} }
log.debug(u'MRQ submissions result: %s', result) log.debug(u'MRQ submissions result: %s', result)
return result return result
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
cursor: pointer; cursor: pointer;
} }
.mentoring .choices .choice-tips { .mentoring .choices .choice-tips,
.mentoring .choices .choice-message {
display: none; display: none;
color: #fff; color: #fff;
position: absolute; position: absolute;
...@@ -51,11 +52,13 @@ ...@@ -51,11 +52,13 @@
font-family: arial; font-family: arial;
} }
.mentoring .choices .choice-tips .tip-choice-group { .mentoring .choices .choice-tips .tip-choice-group,
.mentoring .choices .choice-message .message-content {
position: relative; position: relative;
} }
.mentoring .choices .choice-tips .tip-choice-group .close { .mentoring .choices .choice-tips .close,
.mentoring .choices .choice-message .close {
background-image: url({{ close_icon_url }}); background-image: url({{ close_icon_url }});
cursor: pointer; cursor: pointer;
position: absolute; position: absolute;
......
...@@ -36,18 +36,34 @@ function MRQBlock(runtime, element) { ...@@ -36,18 +36,34 @@ function MRQBlock(runtime, element) {
}, },
handleSubmit: function(result) { handleSubmit: function(result) {
var messageDOM = $('.choice-message', element),
allPopupsDOM = $('.choice-tips, .choice-message', element),
clearPopupEvents = function() {
allPopupsDOM.hide();
$('.close', allPopupsDOM).off('click');
},
showPopup = function(popupDOM) {
clearPopupEvents();
popupDOM.show();
popupDOM.on('click', function() {
clearPopupEvents();
choiceTipsDOM.hide();
});
};
if (result.message) {
messageDOM.html('<div class="message-content"><div class="close"></div>' +
result.message + '</div>');
showPopup(messageDOM);
}
$.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),
choiceTipsDOM = $('.choice-tips', choiceDOM), choiceTipsDOM = $('.choice-tips', choiceDOM),
choiceTipsCloseDOM, choiceTipsCloseDOM;
clearPopupEvents;
clearPopupEvents = function() {
$('.choice-tips', element).hide();
$('.choice-tips .close').off('click');
};
if (choice.completed) { if (choice.completed) {
choiceResultDOM.removeClass('incorrect').addClass('correct'); choiceResultDOM.removeClass('incorrect').addClass('correct');
...@@ -59,13 +75,7 @@ function MRQBlock(runtime, element) { ...@@ -59,13 +75,7 @@ function MRQBlock(runtime, element) {
choiceTipsCloseDOM = $('.close', choiceTipsDOM); choiceTipsCloseDOM = $('.close', choiceTipsDOM);
choiceResultDOM.off('click').on('click', function() { choiceResultDOM.off('click').on('click', function() {
clearPopupEvents(); showPopup(choiceTipsDOM);
choiceTipsDOM.show();
choiceTipsCloseDOM.on('click', function() {
clearPopupEvents();
choiceTipsDOM.hide();
});
}); });
}); });
} }
......
...@@ -50,6 +50,7 @@ class QuestionnaireAbstractBlock(LightChild): ...@@ -50,6 +50,7 @@ class QuestionnaireAbstractBlock(LightChild):
""" """
type = String(help="Type of questionnaire", scope=Scope.content, default="choices") type = String(help="Type of questionnaire", scope=Scope.content, default="choices")
question = String(help="Question to ask the student", scope=Scope.content, default="") question = String(help="Question to ask the student", scope=Scope.content, default="")
message = String(help="General feedback provided when submiting", scope=Scope.content, default="")
valid_types = ('choices') valid_types = ('choices')
...@@ -57,8 +58,10 @@ class QuestionnaireAbstractBlock(LightChild): ...@@ -57,8 +58,10 @@ class QuestionnaireAbstractBlock(LightChild):
def init_block_from_node(cls, block, node, attr): def init_block_from_node(cls, block, node, attr):
block.light_children = [] block.light_children = []
for child_id, xml_child in enumerate(node): for child_id, xml_child in enumerate(node):
if xml_child.tag == "question": if xml_child.tag == 'question':
block.question = xml_child.text block.question = xml_child.text
elif xml_child.tag == 'message' and xml_child.get('type') == 'on-submit':
block.message = (xml_child.text or '').strip()
else: else:
cls.add_node_as_child(block, xml_child, child_id) cls.add_node_as_child(block, xml_child, child_id)
......
...@@ -10,5 +10,6 @@ ...@@ -10,5 +10,6 @@
<div class="choice-tips"></div> <div class="choice-tips"></div>
</div> </div>
{% endfor %} {% endfor %}
<div class="choice-message"></div>
</div> </div>
</fieldset> </fieldset>
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
<tip require="gracefulness">This MRQ is indeed very graceful</tip> <tip require="gracefulness">This MRQ is indeed very graceful</tip>
<tip require="elegance,beauty">This is something everyone has to like about this MRQ</tip> <tip require="elegance,beauty">This is something everyone has to like about this MRQ</tip>
<tip reject="bugs">Nah, there isn't any!</tip> <tip reject="bugs">Nah, there isn't any!</tip>
<message type="on-submit">Thank you for answering!</message>
</mrq> </mrq>
<message type="completed"> <message type="completed">
......
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