Commit 1a94e3ef by Xavier Antoviaque

Merge pull request #8 from mckinseyacademy/cleanup

Addressed nits and remaining work from max submissions task.
parents 2a4ff349 c3d895c4
...@@ -303,6 +303,8 @@ class PollBlock(PollBase): ...@@ -303,6 +303,8 @@ class PollBlock(PollBase):
'url_name': getattr(self, 'url_name', ''), 'url_name': getattr(self, 'url_name', ''),
'display_name': self.display_name, 'display_name': self.display_name,
'can_vote': self.can_vote(), 'can_vote': self.can_vote(),
'max_submissions': self.max_submissions,
'submissions_count': self.submissions_count,
}) })
if self.choice: if self.choice:
...@@ -393,6 +395,8 @@ class PollBlock(PollBase): ...@@ -393,6 +395,8 @@ class PollBlock(PollBase):
result['success'] = True result['success'] = True
result['can_vote'] = self.can_vote() result['can_vote'] = self.can_vote()
result['submissions_count'] = self.submissions_count
result['max_submissions'] = self.max_submissions
self.send_vote_event({'choice': self.choice}) self.send_vote_event({'choice': self.choice})
...@@ -504,7 +508,9 @@ class SurveyBlock(PollBase): ...@@ -504,7 +508,9 @@ class SurveyBlock(PollBase):
# The SDK doesn't set url_name. # The SDK doesn't set url_name.
'url_name': getattr(self, 'url_name', ''), 'url_name': getattr(self, 'url_name', ''),
'block_name': self.block_name, 'block_name': self.block_name,
'can_vote': self.can_vote() 'can_vote': self.can_vote(),
'submissions_count': self.submissions_count,
'max_submissions': self.max_submissions,
}) })
return self.create_fragment( return self.create_fragment(
...@@ -739,6 +745,8 @@ class SurveyBlock(PollBase): ...@@ -739,6 +745,8 @@ class SurveyBlock(PollBase):
self.send_vote_event({'choices': self.choices}) self.send_vote_event({'choices': self.choices})
result['can_vote'] = self.can_vote() result['can_vote'] = self.can_vote()
result['submissions_count'] = self.submissions_count
result['max_submissions'] = self.max_submissions
return result return result
......
...@@ -207,3 +207,7 @@ th.survey-answer { ...@@ -207,3 +207,7 @@ th.survey-answer {
.poll-hidden { .poll-hidden {
display: none; display: none;
} }
.poll-submissions-count {
font-weight: bold;
}
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
<input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled /> <input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled />
</form> </form>
<div class="poll-voting-thanks{% if not choice or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div> <div class="poll-voting-thanks{% if not choice or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
<div class="poll-submissions-count poll-hidden">
You have used <span class="poll-current-count">{{ submissions_count }}</span>
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
</div>
{% if feedback %} {% if feedback %}
<div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}"> <div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}">
<hr /> <hr />
......
...@@ -34,6 +34,10 @@ ...@@ -34,6 +34,10 @@
<input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled /> <input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled />
</form> </form>
<div class="poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div> <div class="poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"><span>Thank you for your submission!</span></div>
<div class="poll-submissions-count poll-hidden">
You have used <span class="poll-current-count">{{ submissions_count }}</span>
out of <span class="poll-max-submissions">{{ max_submissions }}</span> submissions.
</div>
{% if feedback %} {% if feedback %}
<div class="poll-feedback-container{% if not choices %} poll-hidden{% endif %}"> <div class="poll-feedback-container{% if not choices %} poll-hidden{% endif %}">
<hr /> <hr />
......
...@@ -16,6 +16,9 @@ function PollUtil (runtime, element, pollType) { ...@@ -16,6 +16,9 @@ function PollUtil (runtime, element, pollType) {
self.getResults({'success': true}); self.getResults({'success': true});
return false; return false;
} }
if (parseInt($('.poll-max-submissions').text()) > 1 && parseInt($('.poll-current-count').text()) > 0) {
$('.poll-submissions-count', element).show();
}
return true; return true;
}; };
...@@ -31,6 +34,7 @@ function PollUtil (runtime, element, pollType) { ...@@ -31,6 +34,7 @@ function PollUtil (runtime, element, pollType) {
var choice = radio.val(); var choice = radio.val();
var thanks = $('.poll-voting-thanks', element); var thanks = $('.poll-voting-thanks', element);
thanks.addClass('poll-hidden'); thanks.addClass('poll-hidden');
// JQuery's fade functions set element-level styles. Clear these.
thanks.removeAttr('style'); thanks.removeAttr('style');
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -111,6 +115,10 @@ function PollUtil (runtime, element, pollType) { ...@@ -111,6 +115,10 @@ function PollUtil (runtime, element, pollType) {
alert(data['errors'].join('\n')); alert(data['errors'].join('\n'));
} }
var can_vote = data['can_vote']; var can_vote = data['can_vote'];
$('.poll-current-count', element).text(data['submissions_count']);
if (data['max_submissions'] > 1) {
$('.poll-submissions-count').show();
}
if ($('div.poll-block', element).data('private')) { if ($('div.poll-block', element).data('private')) {
// User may be changing their vote. Give visual feedback that it was accepted. // User may be changing their vote. Give visual feedback that it was accepted.
var thanks = $('.poll-voting-thanks', element); var thanks = $('.poll-voting-thanks', element);
......
...@@ -50,12 +50,9 @@ class TestPrivateResults(PollBaseTest): ...@@ -50,12 +50,9 @@ class TestPrivateResults(PollBaseTest):
for __ in range(0, 2): for __ in range(0, 2):
self.go_to_page(page) self.go_to_page(page)
for ___ in range(1, 5): for ___ in range(1, 5):
self.submission_run(names) self.do_submit(names)
self.assertTrue(self.get_submit().is_enabled()) self.assertTrue(self.get_submit().is_enabled())
def submission_run(self, names):
self.do_submit(names)
@unpack @unpack
@data(*scenarios_max) @data(*scenarios_max)
def test_max_submissions_one_view(self, page, names): def test_max_submissions_one_view(self, page, names):
...@@ -78,3 +75,19 @@ class TestPrivateResults(PollBaseTest): ...@@ -78,3 +75,19 @@ class TestPrivateResults(PollBaseTest):
self.go_to_page(page) self.go_to_page(page)
self.do_submit(names) self.do_submit(names)
self.assertFalse(self.get_submit().is_enabled()) self.assertFalse(self.get_submit().is_enabled())
@unpack
@data(*scenarios_max)
def test_max_submissions_counter(self, page, names):
"""
Verify a counter is displayed stating how many submissions have been used.
Our XML allows two submissions, and we must mind the off-by-one for range.
"""
self.go_to_page(page)
counter_div = self.browser.find_element_by_css_selector('.poll-submissions-count')
counter = self.browser.find_element_by_css_selector('.poll-current-count')
self.assertFalse(counter_div.is_displayed())
for i in range(1, 3):
self.do_submit(names)
self.assertTrue(counter_div.is_displayed())
self.assertEqual(counter.text.strip(), str(i))
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