Commit 51b05499 by Piotr Mitros

Code review: aria-live for feedback. Handle submission with no votes. Standard unicode smiley

parent 5ef74e21
...@@ -43,7 +43,7 @@ class RateXBlock(XBlock): ...@@ -43,7 +43,7 @@ class RateXBlock(XBlock):
default_prompt = {'freeform': "Please provide us feedback on this section.", default_prompt = {'freeform': "Please provide us feedback on this section.",
'likert': "Please rate your overall experience with this section.", 'likert': "Please rate your overall experience with this section.",
'mouseovers': ["Excellent", "Good", "Average", "Fair", "Poor"], 'mouseovers': ["Excellent", "Good", "Average", "Fair", "Poor"],
'icons': [u"😁", u"😊", u"😐", u"☹", u"😟"]} 'icons': [u"😁", u"😊", u"😐", u"😞", u"😭"]}
# This is a list of prompts. If we have multiple elements in the # This is a list of prompts. If we have multiple elements in the
# list, one will be chosen at random. This is currently not # list, one will be chosen at random. This is currently not
...@@ -123,7 +123,16 @@ class RateXBlock(XBlock): ...@@ -123,7 +123,16 @@ class RateXBlock(XBlock):
indexes = range(len(prompt['icons'])) indexes = range(len(prompt['icons']))
active_vote = ["checked" if i == self.user_vote else "" for i in indexes] active_vote = ["checked" if i == self.user_vote else "" for i in indexes]
scale = u"".join(scale_item.format(level=level, icon=icon, i=i, active=active) for (level, icon, i, active) in zip(prompt['mouseovers'], prompt['icons'], indexes, active_vote)) scale = u"".join(scale_item.format(level=level, icon=icon, i=i, active=active) for (level, icon, i, active) in zip(prompt['mouseovers'], prompt['icons'], indexes, active_vote))
rendered = html.format(self=self, scale=scale, freeform_prompt=prompt['freeform'], likert_prompt=prompt['likert']) print self.user_vote
if self.user_vote != -1:
response = "Thank you for voting!"
else:
response = ""
rendered = html.format(self=self,
scale=scale,
freeform_prompt=prompt['freeform'],
likert_prompt=prompt['likert'],
response=response)
# We initialize self.p_r if not initialized -- this sets whether # We initialize self.p_r if not initialized -- this sets whether
# or not we show it. From there, if it is less than odds of showing, # or not we show it. From there, if it is less than odds of showing,
...@@ -197,7 +206,7 @@ class RateXBlock(XBlock): ...@@ -197,7 +206,7 @@ class RateXBlock(XBlock):
{'old_vote': self.user_vote, {'old_vote': self.user_vote,
'new_vote': data['vote']}) 'new_vote': data['vote']})
self.vote(data) self.vote(data)
return {"success": True} return {"success": True, "response": "Thank you!"}
# TO-DO: change this to create the scenarios you'd like to see in the # TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock. # workbench while developing your XBlock.
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
.rate_thank_you { .rate_thank_you {
color: green; color: green;
visibility: hidden;
} }
.rate_block .rate_header { .rate_block .rate_header {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<label class="rate_header" for="rate_freeform_textarea">{freeform_prompt}</label> <label class="rate_header" for="rate_freeform_textarea">{freeform_prompt}</label>
<div class="rate_freeform_input"> <div class="rate_freeform_input">
<textarea id="rate_freeform_textarea" class="rate_freeform_area" rows="4" cols="30">{self.user_freeform}</textarea> <textarea id="rate_freeform_textarea" class="rate_freeform_area" rows="4" cols="30">{self.user_freeform}</textarea>
<div class="rate_thank_you">Thank you!</div> <div class="rate_thank_you" aria-live=polite>{response}</div>
</div> </div>
<fieldset class="rate_likert_field"> <fieldset class="rate_likert_field">
<legend class="rate_likert_header">{likert_prompt}</legend> <legend class="rate_likert_header">{likert_prompt}</legend>
......
...@@ -17,7 +17,11 @@ function RateXBlock(runtime, element) { ...@@ -17,7 +17,11 @@ function RateXBlock(runtime, element) {
$(".rate_submit_feedback", element).click(function(eventObject) { $(".rate_submit_feedback", element).click(function(eventObject) {
freeform = $(".rate_freeform_area", element).val(); freeform = $(".rate_freeform_area", element).val();
vote = parseInt($(".rate_radio:checked", element).attr("id").split("_")[1]); if ($(".rate_radio:checked", element).length == 0) {
vote = -1
} else {
vote = parseInt($(".rate_radio:checked", element).attr("id").split("_")[1]);
}
feedback = {"freeform": freeform, feedback = {"freeform": freeform,
"vote": vote} "vote": vote}
Logger.log("edx.ratexblock.submit", feedback) Logger.log("edx.ratexblock.submit", feedback)
...@@ -25,7 +29,7 @@ function RateXBlock(runtime, element) { ...@@ -25,7 +29,7 @@ function RateXBlock(runtime, element) {
type: "POST", type: "POST",
url: feedback_handler, url: feedback_handler,
data: JSON.stringify(feedback), data: JSON.stringify(feedback),
success: function() {$('.rate_thank_you', element).css('visibility','visible')} success: function(data) {console.log(data.response); $('.rate_thank_you', element).text(data.response);}
}); });
}); });
......
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