diff --git a/js/gratipay/packages.js b/js/gratipay/packages.js index cb47b88453..d880989e36 100644 --- a/js/gratipay/packages.js +++ b/js/gratipay/packages.js @@ -1,14 +1,20 @@ Gratipay.packages = {}; Gratipay.packages.initBulk = function() { - $('button.apply').on('click', Gratipay.packages.postBulk); + $('.important-button button').on('click', Gratipay.packages.postBulk); }; Gratipay.packages.initSingle = function() { - Gratipay.Select('.gratipay-select'); - $('button.apply').on('click', Gratipay.packages.postOne); + Gratipay.Select('.gratipay-select', Gratipay.packages.selectOne); + $('.important-button button').on('click', Gratipay.packages.postOne); + Gratipay.packages.selectOne($('.gratipay-select li.selected')); }; +Gratipay.packages.selectOne = function($li) { + var action = $li.data('action'); + $('.important-button span').hide(); + $('.important-button span.' + action).show(); +}; Gratipay.packages.postBulk = function(e) { e.preventDefault(); @@ -30,10 +36,9 @@ Gratipay.packages.postOne = function(e) { Gratipay.packages.post(email, [package_id]); } - Gratipay.packages.post = function(email, package_ids, show_email) { var action = 'start-verification'; - var $button = $('button.apply') + var $button = $('.important-button button') $button.prop('disabled', true); function reenable() { $button.prop('disabled', false); } diff --git a/js/gratipay/select.js b/js/gratipay/select.js index 25691a5c09..4a82daf1f7 100644 --- a/js/gratipay/select.js +++ b/js/gratipay/select.js @@ -1,6 +1,7 @@ -Gratipay.Select = function(selector) { +Gratipay.Select = function(selector, onselect) { var $ul = $('ul', selector); var $labels = $('label', $ul); + var onselect = onselect || function() {}; // state for vertical position var topFactor = 0; // float between 0 and $labels.length-1 @@ -51,9 +52,11 @@ Gratipay.Select = function(selector) { function close($label) { if ($label) { - if ($label.closest('li').hasClass('disabled')) return; + var $li = $label.closest('li'); + if ($li.hasClass('disabled')) return; $('.selected', $ul).removeClass('selected') - $label.closest('li').addClass('selected').removeClass('hover'); + $li.addClass('selected').removeClass('hover'); + onselect($li); } $ul.css({'top': 0}).removeClass('open'); $ul.unbind('mousewheel'); diff --git a/scss/pages/package.scss b/scss/pages/package.scss index a9f1ccdfbe..bfa49920b3 100644 --- a/scss/pages/package.scss +++ b/scss/pages/package.scss @@ -14,6 +14,12 @@ color: $medium-gray; } + .important-button { + span { + display: none; + } + } + .status-icon { font-size: 12px; line-height: 12px; diff --git a/tests/ttw/test_package_claiming.py b/tests/ttw/test_package_claiming.py index 472005955b..fda3083699 100644 --- a/tests/ttw/test_package_claiming.py +++ b/tests/ttw/test_package_claiming.py @@ -9,13 +9,25 @@ class Test(BrowserHarness): - def check(self, choice=0): - self.make_participant('alice', claimed_time='now') + def setUp(self): + BrowserHarness.setUp(self) + self.alice = self.make_participant( 'alice' + , claimed_time='now' + , email_address='alice@example.com' + ) + self.add_and_verify_email(self.alice, 'bob@example.com') self.sign_in('alice') + + def choose(self, choice=0): + self.css('#content li.selected label').click() # activate select + want = self.css('#content label')[choice] + want.click() + return want.text + + def check(self, choice=0): self.visit('/on/npm/foo') - self.css('#content label')[0].click() # activate select - self.css('#content label')[choice].click() - self.css('#content button')[0].click() + self.choose(choice) + self.css('#content .important-button button').click() address = ('alice' if choice == 0 else 'bob') + '@example.com' assert self.wait_for_success() == 'Check {} for a verification link.'.format(address) return self.db.one('select address from claims c ' @@ -39,18 +51,33 @@ def test_can_send_to_second_email(self): self.make_package(emails=['alice@example.com', 'bob@example.com']) assert self.check(choice=1) == 'bob@example.com' - def test_disabled_items_are_disabled(self): - self.make_package(emails=['alice@example.com', 'bob@example.com']) - alice = self.make_participant('alice', claimed_time='now') - self.add_and_verify_email(alice, 'alice@example.com', 'bob@example.com') - self.sign_in('alice') + def test_button_varies_with_email_state(self): + self.make_package(emails=['alice@example.com', 'bob@example.com', 'cat@example.com', + 'doug@example.com', 'edna@example.com']) + self.make_participant('doug', claimed_time='now', email_address='doug@example.com') + self.alice.start_email_verification('cat@example.com') self.visit('/on/npm/foo') - self.css('#content label')[0].click() # activate select - self.css('#content label')[1].click() # click second item - self.css('#content li')[0].has_class('selected') # first item is still selected - self.css('#content ul')[0].has_class('open') # still open - self.css('#content button').has_class('disabled') - assert self.db.all('select * from claims') == [] + + self.choose(0) == 'alice@example.com' + self.css('li.selected').text.endswith('Your primary email address') + self.css('button').text == 'Apply to accept payments' + + self.choose(1) == 'bob@example.com' + self.css('li.selected').text.endswith('Linked to your account') + self.css('button').text == 'Apply to accept payments' + + self.choose(2) == 'cat@example.com' + self.css('li.selected').text.endswith('Verification pending') + self.css('button').text == 'Verify email address' + + self.choose(3) == 'edna@example.com' + self.css('li.selected').text.endswith('Ready to verify') + self.css('button').text == 'Verify email address' + + # doug is last, can't even be selected + self.choose(4) == 'doug@example.com' + self.css('li.selected label') == 'edna@example.com' + self.css('#content li')[4].text.endswith('Linked to a different account') def test_claimed_packages_can_be_given_to(self): @@ -79,7 +106,7 @@ def test_visiting_verify_link_shows_helpful_information(self): self.make_package() self.check() - link = pickle.loads(self.db.one('select context from email_messages'))['link'] + link = pickle.loads(self.db.all('select context from email_messages')[-1])['link'] link = link[len(self.base_url):] # strip because visit will add it back self.visit(link) diff --git a/www/on/npm/%package.spt b/www/on/npm/%package.spt index 59125a6cce..0e9b9eaaec 100644 --- a/www/on/npm/%package.spt +++ b/www/on/npm/%package.spt @@ -22,7 +22,6 @@ banner = package.name if user.participant: emails = package.classify_emails_for_participant(user.participant) - has_email_options = bool([x for x in emails if x[1] != OTHER]) [---] text/html {% extends "templates/base.html" %} @@ -77,7 +76,10 @@ if user.participant: