r103130 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103129‎ | r103130 | r103131 >
Date:04:40, 15 November 2011
Author:kaldari
Status:ok
Tags:
Comment:
consolidating some of the validateAmount functions
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects.bt.js (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects.js (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects2nd-US.js (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects2nd.js (modified) (history)
  • /trunk/extensions/DonationInterface/modules/validate_input.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects.js
@@ -104,28 +104,3 @@
105105 $( "#selected-amount" ).html( "$" + e.val() + "" );
106106 $( "#change-amount" ).show();
107107 }
108 -window.validateAmount = function() {
109 - var error = true;
110 - var amount = $( 'input[name="amount"]' ).val(); // get the amount
111 - // Normalize weird amount formats.
112 - // Don't mess with these unless you know what you're doing.
113 - amount = amount.replace( /[,.](\d)$/, '\:$10' );
114 - amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
115 - amount = amount.replace( /[,.]/g, '' );
116 - amount = amount.replace( /:/, '.' );
117 - $( 'input[name="amount"]' ).val( amount ); // set the new amount back into the form
118 -
119 - // Check amount is a real number, sets error as true (good) if no issues
120 - error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
121 -
122 - // Check amount is at least the minimum
123 - var currency_code = $( 'input[name="currency_code"]' ).val();
124 - if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
125 - wgCurrencyMinimums[currency_code] = 1;
126 - }
127 - if ( amount < wgCurrencyMinimums[currency_code] || error ) {
128 - alert( mw.msg( 'donate_interface-smallamount-error' ).replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
129 - error = true;
130 - }
131 - return !error;
132 -}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects.bt.js
@@ -120,28 +120,3 @@
121121 $( "#selected-amount" ).html( + e.val() + " " + $( 'input[name="currency_code"]' ).val() );
122122 $( "#change-amount" ).show();
123123 }
124 -function validateAmount() {
125 - var error = true;
126 - var amount = $( 'input[name="amount"]' ).val(); // get the amount
127 - // Normalize weird amount formats.
128 - // Don't mess with these unless you know what you're doing.
129 - amount = amount.replace( /[,.](\d)$/, '\:$10' );
130 - amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
131 - amount = amount.replace( /[,.]/g, '' );
132 - amount = amount.replace( /:/, '.' );
133 - $( 'input[name="amount"]' ).val( amount ); // set the new amount back into the form
134 -
135 - // Check amount is a real number, sets error as true (good) if no issues
136 - error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
137 -
138 - // Check amount is at least the minimum
139 - var currency_code = $( 'input[name="currency_code"]' ).val();
140 - if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
141 - wgCurrencyMinimums[currency_code] = 1;
142 - }
143 - if ( amount < wgCurrencyMinimums[currency_code] || error ) {
144 - alert( mw.msg( 'donate_interface-smallamount-error' ).replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
145 - error = true;
146 - }
147 - return !error;
148 -}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects2nd.js
@@ -50,7 +50,7 @@
5151 } );
5252
5353 $( "#bt-continueBtn" ).live( "click", function() {
54 - if ( validateAmount() && validate_personal( document.paypalcontribution ) ) {
 54+ if ( validate_personal( document.paypalcontribution ) && validateAmount() ) {
5555 document.paypalcontribution.action = actionURL;
5656 document.paypalcontribution.submit();
5757 }
@@ -154,31 +154,7 @@
155155 $( "#selected-amount" ).html( + e.val() + " " + $( 'input[name="currency_code"]' ).val() );
156156 $( "#change-amount" ).show();
157157 }
158 -function validateAmount() {
159 - var error = true;
160 - var amount = $( 'input[name="amount"]' ).val(); // get the amount
161 - // Normalize weird amount formats.
162 - // Don't mess with these unless you know what you're doing.
163 - amount = amount.replace( /[,.](\d)$/, '\:$10' );
164 - amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
165 - amount = amount.replace( /[,.]/g, '' );
166 - amount = amount.replace( /:/, '.' );
167 - $( 'input[name="amount"]' ).val( amount ); // set the new amount back into the form
168158
169 - // Check amount is a real number, sets error as true (good) if no issues
170 - error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
171 -
172 - // Check amount is at least the minimum
173 - var currency_code = $( 'input[name="currency_code"]' ).val();
174 - if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
175 - wgCurrencyMinimums[currency_code] = 1;
176 - }
177 - if ( amount < wgCurrencyMinimums[currency_code] || error ) {
178 - alert( mw.msg( 'donate_interface-smallamount-error' ).replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
179 - error = true;
180 - }
181 - return !error;
182 -}
183159 window.showStep1 = function() {
184160 // show the correct sections
185161 $( "#step1wrapper" ).slideDown();
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects2nd-US.js
@@ -112,11 +112,7 @@
113113 } );
114114
115115 $( "#step1header" ).click( function() {
116 - // show the correct sections
117 - $( "#step1wrapper" ).slideDown();
118 - $( "#step2wrapper" ).slideDown();
119 - $( "#step3wrapper" ).slideUp();
120 - $( "#change-amount" ).hide();
 116+ showStep1();
121117 } );
122118
123119
@@ -150,31 +146,7 @@
151147 $( "#selected-amount" ).html( "$" + e.val() );
152148 $( "#change-amount" ).show();
153149 }
154 -function validateAmount() {
155 - var error = true;
156 - var amount = $( 'input[name="amount"]' ).val(); // get the amount
157 - // Normalize weird amount formats.
158 - // Don't mess with these unless you know what you're doing.
159 - amount = amount.replace( /[,.](\d)$/, '\:$10' );
160 - amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
161 - amount = amount.replace( /[,.]/g, '' );
162 - amount = amount.replace( /:/, '.' );
163 - $( 'input[name="amount"]' ).val( amount ); // set the new amount back into the form
164150
165 - // Check amount is a real number, sets error as true (good) if no issues
166 - error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
167 -
168 - // Check amount is at least the minimum
169 - var currency_code = $( 'input[name="currency_code"]' ).val();
170 - if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
171 - wgCurrencyMinimums[currency_code] = 1;
172 - }
173 - if ( amount < wgCurrencyMinimums[currency_code] || error ) {
174 - alert( mw.msg( 'donate_interface-smallamount-error' ).replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
175 - error = true;
176 - }
177 - return !error;
178 -}
179151 window.showStep1 = function() {
180152 // show the correct sections
181153 $( "#step1wrapper" ).slideDown();
Index: trunk/extensions/DonationInterface/modules/validate_input.js
@@ -38,7 +38,48 @@
3939 document.getElementById('payflowpro_gateway-form-submit-paypal').style.display = 'none';
4040 };
4141
42 -/*
 42+/**
 43+ * Validate the donation amount to make sure it is formatted correctly and at least a minimum amount.
 44+ */
 45+window.validateAmount = function() {
 46+ var error = true;
 47+ var amount = $( 'input[name="amount"]' ).val(); // get the amount
 48+ // Normalize weird amount formats.
 49+ // Don't mess with these unless you know what you're doing.
 50+ amount = amount.replace( /[,.](\d)$/, '\:$10' );
 51+ amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
 52+ amount = amount.replace( /[,.]/g, '' );
 53+ amount = amount.replace( /:/, '.' );
 54+ $( 'input[name="amount"]' ).val( amount ); // set the new amount back into the form
 55+
 56+ // Check amount is a real number, sets error as true (good) if no issues
 57+ error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
 58+
 59+ // Check amount is at least the minimum
 60+ var currency_code = $( 'input[name="currency_code"]' ).val();
 61+ if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
 62+ wgCurrencyMinimums[currency_code] = 1;
 63+ }
 64+ if ( amount < wgCurrencyMinimums[currency_code] || error ) {
 65+ alert( mw.msg( 'donate_interface-smallamount-error' ).replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
 66+ error = true;
 67+ // See if we're on a webitects accordian form
 68+ if ( $( '#step1wrapper' ).length ) {
 69+ $( "#step1wrapper" ).slideDown();
 70+ $( "#paymentContinue" ).show();
 71+ // If we're on a GlobalCollect iframe form, slide up the 3rd step to force the user to
 72+ // generate a new iframe after they change the form.
 73+ if ( $( '#payment iframe' ).length ) {
 74+ $( "#step3wrapper" ).slideUp();
 75+ }
 76+ }
 77+ $( '#other-amount' ).val( '' );
 78+ $( '#other-amount' ).focus();
 79+ }
 80+ return !error;
 81+}
 82+
 83+/**
4384 * Validates the personal information fields
4485 *
4586 * @input form The form containing the inputs to be checked
@@ -47,8 +88,6 @@
4889 */
4990 window.validate_personal = function( form ){
5091
51 - // TODO: this form should only report a single error for the email address?
52 -
5392 var output = '';
5493 var currField = '';
5594 var i = 0;

Follow-up revisions

RevisionCommit summaryAuthorDate
r103263MFT r103080, r103130, r103219, r103223, r103229, r103235, r103237, r103238, r...awjrichards23:43, 15 November 2011

Status & tagging log