@@ -2,67 +2,45 @@ define('payments-manage', ['payments'], function(payments) {
22 'use strict' ;
33
44 function refreshAccountForm ( data ) {
5- var $account_list_form = $ ( '#bango-account-list' ) ;
6- $account_list_form . load ( $account_list_form . data ( 'url' ) ) ;
5+ var $accountListForm = $ ( '#bango-account-list' ) ;
6+ $accountListForm . load ( $accountListForm . data ( 'url' ) ) ;
77 }
88
99 function newBangoPaymentAccount ( e ) {
1010 var $overlay = payments . getOverlay ( 'add-bango-account' ) ;
1111 payments . setupPaymentAccountOverlay ( $overlay , showAgreement ) ;
1212 }
1313
14- function agreementSuccess ( pk ) {
15- $ ( '.account-list [data-account=' + pk + '] .terms-accepted' ) . removeClass ( 'rejected' ) . addClass ( 'accepted' ) ;
16- }
14+ function setupAgreementOverlay ( data , onsubmit ) {
15+ var $waiting_overlay = payments . getOverlay ( 'bango-waiting' ) ;
1716
18- function agreementError ( pk ) {
19- $ ( '.account-list [data-account=' + pk + '] .terms-accepted' ) . removeClass ( 'accepted' ) . addClass ( 'rejected' ) ;
20- }
17+ $ . getJSON ( data [ 'agreement-url' ] , function ( response ) {
18+ var $overlay = payments . getOverlay ( 'show-agreement' ) ;
19+ $overlay . on ( 'submit' , 'form' , _pd ( function ( e ) {
20+ var $form = $ ( this ) ;
2121
22- var agreementUrl = $ ( '#show-agreement-template' ) . data ( 'url' ) ;
22+ // Assume the POST below was a success, and close the modal.
23+ $overlay . detach ( ) . trigger ( 'overlay_dismissed' ) ;
24+ onsubmit . apply ( $form , data ) ;
2325
24- function setupAgreementOverlay ( data , $overlay , onsubmit ) {
25- var url = format ( agreementUrl , data . pk ) ;
26+ // If the POST failed, we show an error message.
27+ $ . post ( data [ 'agreement-url' ] , $form . serialize ( ) , refreshAccountForm ) . fail ( function ( ) {
28+ $waiting_overlay . find ( 'h2' ) . text ( gettext ( 'Error' ) ) ;
29+ $waiting_overlay . find ( 'p' ) . text ( gettext ( 'There was a problem contacting the payment server.' ) ) ;
30+ } ) ;
31+ } ) ) ;
2632
27- // TODO: Do something with waiting overlays. This is slow.
28- $ . getJSON ( url , function ( data ) {
2933 // Plop in date of agreement.
3034 var msg = $ ( '.agreement-valid' ) ;
31- msg . html ( format ( msg . html ( ) , { date : data . valid } ) ) ;
35+ msg . html ( format ( msg . html ( ) , { date : response . valid } ) ) ;
3236
3337 // Plop in text of agreement.
34- $ ( '.agreement-text' ) . text ( data . text ) ;
35- } ) ;
36-
37- $overlay . on ( 'submit' , 'form' , _pd ( function ( e ) {
38- var $form = $ ( this ) ;
39-
40- // Assume the POST below was a success, and close the modal.
41- $overlay . detach ( ) ;
42- z . body . removeClass ( 'overlayed' ) ;
43- onsubmit . apply ( $form , data ) ;
44-
45- // If the POST failed, we show an error message.
46- $ . post ( url , $form . serialize ( ) , function ( response ) {
47- if ( response . accepted ) {
48- agreementSuccess ( data . pk ) ;
49- } else {
50- agreementError ( ) ;
51- }
52- } , 'json' ) . error ( function ( ) {
53- agreementError ( data . pk ) ;
54- } ) ;
55- } ) ) . on ( 'overlay_dismissed' , function ( ) {
56- // If it wasn't already marked as successful, then the user cancelled.
57- if ( ! $ ( '.account-list [data-account=' + data . pk + '] .terms-accepted.success' ) ) {
58- agreementError ( data . pk ) ;
59- }
38+ $ ( '.agreement-text' ) . text ( response . text ) ;
6039 } ) ;
6140 }
6241
6342 function showAgreement ( data ) {
64- var $overlay = payments . getOverlay ( 'show-agreement' ) ;
65- setupAgreementOverlay ( data , $overlay , function ( ) {
43+ setupAgreementOverlay ( data , function ( ) {
6644 refreshAccountForm ( ) ;
6745 $ ( '#no-payment-providers' ) . addClass ( 'js-hidden' ) ;
6846 } ) ;
@@ -110,10 +88,12 @@ define('payments-manage', ['payments'], function(payments) {
11088
11189 // Post to the delete URL, then refresh the account form.
11290 $ . post ( $tr . data ( 'delete-url' ) ) . then ( refreshAccountForm ) ;
113- } ) ) . on ( 'click' , 'a .modify-account' , _pd ( function ( ) {
91+ } ) ) . on ( 'click' , '.modify-account' , _pd ( function ( ) {
11492 // Get the account URL from the table row and pass it to
11593 // the function to handle the Edit overlay.
11694 editBangoPaymentAccount ( $ ( this ) . parents ( 'tr' ) . data ( 'account-url' ) ) ( ) ;
95+ } ) ) . on ( 'click' , '.accept-tos' , _pd ( function ( ) {
96+ showAgreement ( $ ( this ) . parents ( 'tr' ) . data ( ) ) ;
11797 } ) ) ;
11898 } ) ;
11999 }
0 commit comments