diff --git a/poll/poll.py b/poll/poll.py index a06b57d..9550f5b 100644 --- a/poll/poll.py +++ b/poll/poll.py @@ -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 diff --git a/poll/public/css/poll.css b/poll/public/css/poll.css index 2b03991..780566e 100644 --- a/poll/public/css/poll.css +++ b/poll/public/css/poll.css @@ -207,3 +207,7 @@ th.survey-answer { .poll-hidden { display: none; } + +.poll-submissions-count { + font-weight: bold; +} diff --git a/poll/public/html/poll.html b/poll/public/html/poll.html index 7ff9378..b0e5766 100644 --- a/poll/public/html/poll.html +++ b/poll/public/html/poll.html @@ -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 /> diff --git a/poll/public/html/survey.html b/poll/public/html/survey.html index 645f5b3..def9deb 100644 --- a/poll/public/html/survey.html +++ b/poll/public/html/survey.html @@ -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 /> diff --git a/poll/public/js/poll.js b/poll/public/js/poll.js index 5d8495c..85cacba 100644 --- a/poll/public/js/poll.js +++ b/poll/public/js/poll.js @@ -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); diff --git a/tests/integration/test_max_submissions.py b/tests/integration/test_max_submissions.py index c34df02..73e5d80 100644 --- a/tests/integration/test_max_submissions.py +++ b/tests/integration/test_max_submissions.py @@ -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))