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):
'url_name': getattr(self, 'url_name', ''),
'display_name': self.display_name,
'can_vote': self.can_vote(),
'max_submissions': self.max_submissions,
'submissions_count': self.submissions_count,
})
if self.choice:
......@@ -393,6 +395,8 @@ class PollBlock(PollBase):
result['success'] = True
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})
......@@ -504,7 +508,9 @@ class SurveyBlock(PollBase):
# The SDK doesn't set url_name.
'url_name': getattr(self, 'url_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(
......@@ -739,6 +745,8 @@ class SurveyBlock(PollBase):
self.send_vote_event({'choices': self.choices})
result['can_vote'] = self.can_vote()
result['submissions_count'] = self.submissions_count
result['max_submissions'] = self.max_submissions
return result
......
......@@ -207,3 +207,7 @@ th.survey-answer {
.poll-hidden {
display: none;
}
.poll-submissions-count {
font-weight: bold;
}
......@@ -27,6 +27,10 @@
<input class="input-main" type="button" name="poll-submit" value="{% if choice %}Resubmit{% else %}Submit{% endif %}" disabled />
</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-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 %}
<div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}">
<hr />
......
......@@ -34,6 +34,10 @@
<input class="input-main" type="button" name="poll-submit" value="{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}" disabled />
</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-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 %}
<div class="poll-feedback-container{% if not choices %} poll-hidden{% endif %}">
<hr />
......
......@@ -16,6 +16,9 @@ function PollUtil (runtime, element, pollType) {
self.getResults({'success': true});
return false;
}
if (parseInt($('.poll-max-submissions').text()) > 1 && parseInt($('.poll-current-count').text()) > 0) {
$('.poll-submissions-count', element).show();
}
return true;
};
......@@ -31,6 +34,7 @@ function PollUtil (runtime, element, pollType) {
var choice = radio.val();
var thanks = $('.poll-voting-thanks', element);
thanks.addClass('poll-hidden');
// JQuery's fade functions set element-level styles. Clear these.
thanks.removeAttr('style');
$.ajax({
type: "POST",
......@@ -111,6 +115,10 @@ function PollUtil (runtime, element, pollType) {
alert(data['errors'].join('\n'));
}
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')) {
// User may be changing their vote. Give visual feedback that it was accepted.
var thanks = $('.poll-voting-thanks', element);
......
......@@ -50,12 +50,9 @@ class TestPrivateResults(PollBaseTest):
for __ in range(0, 2):
self.go_to_page(page)
for ___ in range(1, 5):
self.submission_run(names)
self.do_submit(names)
self.assertTrue(self.get_submit().is_enabled())
def submission_run(self, names):
self.do_submit(names)
@unpack
@data(*scenarios_max)
def test_max_submissions_one_view(self, page, names):
......@@ -78,3 +75,19 @@ class TestPrivateResults(PollBaseTest):
self.go_to_page(page)
self.do_submit(names)
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