r102213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102212‎ | r102213 | r102214 >
Date:00:02, 7 November 2011
Author:kaldari
Status:ok
Tags:fundraising 
Comment:
redoing amount validation so we dont have to repeat the list all over the place
Modified paths:
  • /trunk/extensions/DonationInterface/donationinterface.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/rapidhtml/RapidHtmlResources.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/rapidhtml/html/webitects_1.html (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/rapidhtml/html/webitects_1a.html (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/rapidhtml/html/webitects_2.html (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/rapidhtml/js/lightbox1.js (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/lightbox1.js (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects.js (modified) (history)
  • /trunk/extensions/DonationInterface/modules/validate.currencyMinimums.js (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/webitects_2_2step.js (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/webitects_2_3step.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/donationinterface.php
@@ -622,11 +622,17 @@
623623 )
624624 );
625625
 626+// minimum amounts for all currencies
 627+$wgResourceModules[ 'di.form.core.minimums' ] = array(
 628+ 'scripts' => 'validate.currencyMinimums.js',
 629+ 'localBasePath' => $donationinterface_dir . 'modules',
 630+ 'remoteExtPath' => 'DonationInterface/modules'
 631+);
 632+
626633 // form validation resource
627 -//TODO: Move this somewhere gateway-agnostic.
628 -$wgResourceModules[ 'pfp.form.core.validate' ] = array(
 634+$wgResourceModules[ 'di.form.core.validate' ] = array(
629635 'scripts' => 'validate_input.js',
630 - 'dependencies' => array( 'pfp.form.core.pfp_css', 'ext.donationInterface.errorMessages' ),
 636+ 'dependencies' => array( 'pfp.form.core.pfp_css', 'di.form.core.minimums', 'ext.donationInterface.errorMessages' ),
631637 'localBasePath' => $donationinterface_dir . 'modules',
632638 'remoteExtPath' => 'DonationInterface/modules'
633639 );
@@ -635,7 +641,7 @@
636642 //TODO: Move this somewhere gateway-agnostic.
637643 $wgResourceModules[ 'pfp.form.core.placeholders' ] = array(
638644 'scripts' => 'form_placeholders.js',
639 - 'dependencies' => 'pfp.form.core.validate',
 645+ 'dependencies' => 'di.form.core.validate',
640646 'messages' => array(
641647 'donate_interface-donor-fname',
642648 'donate_interface-donor-lname',
@@ -660,7 +666,7 @@
661667 // TowStepTwoColumnLetter3
662668 $wgResourceModules[ 'pfp.form.TwoStepTwoColumnLetter3' ] = array(
663669 'styles' => 'css/TwoStepTwoColumnLetter3.css',
664 - 'dependencies' => 'pfp.form.core.validate',
 670+ 'dependencies' => 'di.form.core.validate',
665671 ) + $wgResourceTemplate;
666672
667673 // API JS
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
@@ -204,9 +204,6 @@
205205 }
206206
207207 function validateAmount(){
208 - var minimums = {
209 - 'USD' : 1
210 - };
211208 var error = true;
212209 var amount = $( "input[name='amount']" ).val(); // get the amount
213210 var otherAmount = amount // create a working copy
@@ -222,11 +219,11 @@
223220 // Check amount is at least the minimum
224221 var currency = 'USD'; // hard-coded for these forms and tests
225222 $( "input[name='currency']" ).val( currency );
226 - if ( typeof( minimums[currency] ) == 'undefined' ) {
227 - minimums[currency] = 1;
 223+ if ( typeof( wgCurrencyMinimums[currency] ) == 'undefined' ) {
 224+ wgCurrencyMinimums[currency] = 1;
228225 }
229 - if ( amount < minimums[currency] || error ) {
230 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 226+ if ( amount < wgCurrencyMinimums[currency] || error ) {
 227+ alert( 'You must contribute at least $1'.replace('$1', wgCurrencyMinimums[currency] + ' ' + currency ) );
231228 error = true;
232229 }
233230 return !error;
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/webitects_2_2step.js
@@ -157,14 +157,10 @@
158158 $( "#change-amount" ).show();
159159 }
160160 function validateAmount() {
161 -
162 - // TODO: THIS NEEDS TO BE REPLACED WITH KALDARI'S CURRENCIES
163 - var minimums = {
164 - 'USD' : 1,
165 - 'CAD' : 1
166 - };
167161 var error = true;
168162 var amount = $( 'input[name="amount"]' ).val(); // get the amount
 163+ // Normalize weird amount formats.
 164+ // Don't mess with these unless you know what you're doing.
169165 amount = amount.replace( /[,.](\d)$/, '\:$10' );
170166 amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
171167 amount = amount.replace( /[,.]/g, '' );
@@ -176,11 +172,11 @@
177173
178174 // Check amount is at least the minimum
179175 var currency_code = $( 'input[name="currency_code"]' ).val();
180 - if ( typeof( minimums[currency_code] ) == 'undefined' ) {
181 - minimums[currency_code] = 1;
 176+ if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
 177+ wgCurrencyMinimums[currency_code] = 1;
182178 }
183 - if ( amount < minimums[currency_code] || error ) {
184 - alert( 'You must contribute at least $1'.replace( '$1', minimums[currency_code] + ' ' + currency_code ) );
 179+ if ( amount < wgCurrencyMinimums[currency_code] || error ) {
 180+ alert( 'You must contribute at least $1'.replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
185181 error = true;
186182 }
187183 return !error;
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/webitects_2_3step.js
@@ -174,14 +174,10 @@
175175 $( "#change-amount" ).show();
176176 }
177177 function validateAmount() {
178 -
179 - // TODO: THIS NEEDS TO BE REPLACED WITH KALDARI'S CURRENCIES
180 - var minimums = {
181 - 'USD' : 1,
182 - 'CAD' : 1
183 - };
184178 var error = true;
185179 var amount = $( 'input[name="amount"]' ).val(); // get the amount
 180+ // Normalize weird amount formats.
 181+ // Don't mess with these unless you know what you're doing.
186182 amount = amount.replace( /[,.](\d)$/, '\:$10' );
187183 amount = amount.replace( /[,.](\d)(\d)$/, '\:$1$2' );
188184 amount = amount.replace( /[,.]/g, '' );
@@ -193,11 +189,11 @@
194190
195191 // Check amount is at least the minimum
196192 var currency_code = $( 'input[name="currency_code"]' ).val();
197 - if ( typeof( minimums[currency_code] ) == 'undefined' ) {
198 - minimums[currency_code] = 1;
 193+ if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
 194+ wgCurrencyMinimums[currency_code] = 1;
199195 }
200 - if ( amount < minimums[currency_code] || error ) {
201 - alert( 'You must contribute at least $1'.replace( '$1', minimums[currency_code] + ' ' + currency_code ) );
 196+ if ( amount < wgCurrencyMinimums[currency_code] || error ) {
 197+ alert( 'You must contribute at least $1'.replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
202198 error = true;
203199 }
204200 return !error;
Index: trunk/extensions/DonationInterface/gateway_forms/rapidhtml/html/webitects_1.html
@@ -320,9 +320,6 @@
321321 });
322322
323323 function validateAmount(){
324 - var minimums = {
325 - 'USD' : 1
326 - };
327324 var error = true;
328325 var amount = $('input[name="amount"]').val(); // get the amount
329326 var otherAmount = amount // create a working copy
@@ -338,11 +335,11 @@
339336 // Check amount is at least the minimum
340337 var currency = 'USD'; // hard-coded for these forms and tests
341338 $('input[name="currency"]').val(currency);
342 - if ( typeof( minimums[currency] ) == 'undefined' ) {
343 - minimums[currency] = 1;
 339+ if ( typeof( wgCurrencyMinimums[currency] ) == 'undefined' ) {
 340+ wgCurrencyMinimums[currency] = 1;
344341 }
345 - if ( amount < minimums[currency] || error ) {
346 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 342+ if ( amount < wgCurrencyMinimums[currency] || error ) {
 343+ alert( 'You must contribute at least $1'.replace('$1', wgCurrencyMinimums[currency] + ' ' + currency ) );
347344 error = true;
348345 }
349346 return !error;
Index: trunk/extensions/DonationInterface/gateway_forms/rapidhtml/html/webitects_1a.html
@@ -321,9 +321,6 @@
322322 });
323323
324324 function validateAmount(){
325 - var minimums = {
326 - 'USD' : 1
327 - };
328325 var error = true;
329326 var amount = $('input[name="amount"]').val(); // get the amount
330327 var otherAmount = amount // create a working copy
@@ -339,11 +336,11 @@
340337 // Check amount is at least the minimum
341338 var currency = 'USD'; // hard-coded for these forms and tests
342339 $('input[name="currency"]').val(currency);
343 - if ( typeof( minimums[currency] ) == 'undefined' ) {
344 - minimums[currency] = 1;
 340+ if ( typeof( wgCurrencyMinimums[currency] ) == 'undefined' ) {
 341+ wgCurrencyMinimums[currency] = 1;
345342 }
346 - if ( amount < minimums[currency] || error ) {
347 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 343+ if ( amount < wgCurrencyMinimums[currency] || error ) {
 344+ alert( 'You must contribute at least $1'.replace('$1', wgCurrencyMinimums[currency] + ' ' + currency ) );
348345 error = true;
349346 }
350347 return !error;
Index: trunk/extensions/DonationInterface/gateway_forms/rapidhtml/html/webitects_2.html
@@ -324,9 +324,6 @@
325325 });
326326
327327 function validateAmount(){
328 - var minimums = {
329 - 'USD' : 1
330 - };
331328 var error = true;
332329 var amount = $('input[name="amount"]').val(); // get the amount
333330 var otherAmount = amount // create a working copy
@@ -342,11 +339,11 @@
343340 // Check amount is at least the minimum
344341 var currency = 'USD'; // hard-coded for these forms and tests
345342 $('input[name="currency"]').val(currency);
346 - if ( typeof( minimums[currency] ) == 'undefined' ) {
347 - minimums[currency] = 1;
 343+ if ( typeof( wgCurrencyMinimums[currency] ) == 'undefined' ) {
 344+ wgCurrencyMinimums[currency] = 1;
348345 }
349 - if ( amount < minimums[currency] || error ) {
350 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 346+ if ( amount < wgCurrencyMinimums[currency] || error ) {
 347+ alert( 'You must contribute at least $1'.replace('$1', wgCurrencyMinimums[currency] + ' ' + currency ) );
351348 error = true;
352349 }
353350 return !error;
Index: trunk/extensions/DonationInterface/gateway_forms/rapidhtml/RapidHtmlResources.php
@@ -119,7 +119,7 @@
120120 'scripts' => 'js/webitects_2_3step.js',
121121 'dependencies' => array(
122122 'di.form.rapidhtml.webitects',
123 - 'pfp.form.core.validate'
 123+ 'di.form.core.validate'
124124 ),
125125 'localBasePath' => dirname( __FILE__ ).'/../../payflowpro_gateway/forms',
126126 'remoteExtPath' => $wgPayflowRapidHtmlRemoteExtPath,
@@ -129,7 +129,7 @@
130130 'scripts' => 'js/webitects_2_2step.js',
131131 'dependencies' => array(
132132 'di.form.rapidhtml.webitects',
133 - 'pfp.form.core.validate'
 133+ 'di.form.core.validate'
134134 ),
135135 'localBasePath' => dirname( __FILE__ ).'/../../payflowpro_gateway/forms',
136136 'remoteExtPath' => $wgPayflowRapidHtmlRemoteExtPath,
Index: trunk/extensions/DonationInterface/gateway_forms/rapidhtml/js/lightbox1.js
@@ -156,9 +156,6 @@
157157 }
158158
159159 function validateAmount(){
160 - var minimums = {
161 - 'USD' : 1
162 - };
163160 var error = true;
164161 var amount = $( "input[name='amount']" ).val(); // get the amount
165162 var otherAmount = amount // create a working copy
@@ -174,11 +171,11 @@
175172 // Check amount is at least the minimum
176173 var currency = 'USD'; // hard-coded for these forms and tests
177174 $( "input[name='currency']" ).val( currency );
178 - if ( typeof( minimums[currency] ) == 'undefined' ) {
179 - minimums[currency] = 1;
 175+ if ( typeof( wgCurrencyMinimums[currency] ) == 'undefined' ) {
 176+ wgCurrencyMinimums[currency] = 1;
180177 }
181 - if ( amount < minimums[currency] || error ) {
182 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 178+ if ( amount < wgCurrencyMinimums[currency] || error ) {
 179+ alert( 'You must contribute at least $1'.replace('$1', wgCurrencyMinimums[currency] + ' ' + currency ) );
183180 error = true;
184181 }
185182 return !error;
Index: trunk/extensions/DonationInterface/gateway_forms/Form.php
@@ -795,7 +795,7 @@
796796
797797 protected function loadValidateJs() {
798798 global $wgOut;
799 - $wgOut->addModules( 'pfp.form.core.validate' );
 799+ $wgOut->addModules( 'di.form.core.validate' );
800800 }
801801
802802 protected function loadApiJs() {
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/lightbox1.js
@@ -191,9 +191,6 @@
192192 }
193193
194194 function validateAmount(){
195 - var minimums = {
196 - 'USD' : 1
197 - };
198195 var error = true;
199196 var amount = $( "input[name='amount']" ).val(); // get the amount
200197 var otherAmount = amount // create a working copy
@@ -209,11 +206,11 @@
210207 // Check amount is at least the minimum
211208 var currency = 'USD'; // hard-coded for these forms and tests
212209 $( "input[name='currency']" ).val( currency );
213 - if ( typeof( minimums[currency] ) == 'undefined' ) {
214 - minimums[currency] = 1;
 210+ if ( typeof( wgCurrencyMinimums[currency] ) == 'undefined' ) {
 211+ wgCurrencyMinimums[currency] = 1;
215212 }
216 - if ( amount < minimums[currency] || error ) {
217 - alert( 'You must contribute at least $1'.replace('$1', minimums[currency] + ' ' + currency ) );
 213+ if ( amount < wgCurrencyMinimums[currency] || error ) {
 214+ alert( 'You must contribute at least $1'.replace('$1', wgCurrencyMinimums[currency] + ' ' + currency ) );
218215 error = true;
219216 }
220217 return !error;
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects.js
@@ -72,93 +72,6 @@
7373 $( "#change-amount" ).show();
7474 }
7575 window.validateAmount = function() {
76 -
77 - // If you change these, also change in currencyRates.inc.
78 - var minimums = {
79 - 'AED': 4,
80 - 'ARS': 4,
81 - 'AUD': 1,
82 - 'BBD': 2,
83 - 'BDT': 76,
84 - 'BGN': 1.4,
85 - 'BHD': 0.4,
86 - 'BMD': 1,
87 - 'BND': 1.3,
88 - 'BOB': 7,
89 - 'BRL': 1.7,
90 - 'BSD': 1,
91 - 'BZD': 2,
92 - 'CAD': 1,
93 - 'CHF': 0.9,
94 - 'CLP': 494,
95 - 'CNY': 6,
96 - 'COP': 1910,
97 - 'CRC': 512,
98 - 'CZK': 18,
99 - 'DKK': 5,
100 - 'DOP': 38,
101 - 'DZD': 73,
102 - 'EEK': 11,
103 - 'EGP': 6,
104 - 'EUR': 0.7,
105 - 'GBP': 0.6,
106 - 'GTQ': 7.8,
107 - 'HKD': 7.7,
108 - 'HNL': 19,
109 - 'HRK': 5,
110 - 'HUF': 219,
111 - 'IDR': 8960,
112 - 'ILS': 3.6,
113 - 'INR': 49,
114 - 'JMD': 85,
115 - 'JOD': 0.7,
116 - 'JPY': 78,
117 - 'KES': 97,
118 - 'KRW': 1127,
119 - 'KYD': 0.8,
120 - 'KZT': 147,
121 - 'LBP': 1500,
122 - 'LKR': 110,
123 - 'LTL': 2.5,
124 - 'LVL': 0.5,
125 - 'MAD': 8.1,
126 - 'MKD': 45,
127 - 'MUR': 29,
128 - 'MVR': 15,
129 - 'MXN': 13,
130 - 'MYR': 3,
131 - 'NOK': 5.5,
132 - 'NZD': 1.2,
133 - 'OMR': 0.3,
134 - 'PAB': 1,
135 - 'PEN': 2.7,
136 - 'PHP': 43,
137 - 'PKR': 86,
138 - 'PLN': 3,
139 - 'PYG': 4190,
140 - 'QAR': 3.6,
141 - 'RON': 3.1,
142 - 'RUB': 30,
143 - 'SAR': 3.7,
144 - 'SEK': 6.5,
145 - 'SGD': 1.2,
146 - 'SVC': 8.7,
147 - 'THB': 30,
148 - 'TJS': 4.7,
149 - 'TND': 1.4,
150 - 'TRY': 1.7,
151 - 'TTD': 6,
152 - 'TWD': 30,
153 - 'UAH': 8,
154 - 'USD': 1,
155 - 'UYU': 19,
156 - 'UZS': 1760,
157 - 'VND': 21000,
158 - 'XAF': 470,
159 - 'XCD': 2.7,
160 - 'XOF': 476,
161 - 'ZAR': 7.8
162 - };
16376 var error = true;
16477 var amount = $( 'input[name="amount"]' ).val(); // get the amount
16578 // Normalize weird amount formats.
@@ -174,11 +87,11 @@
17588
17689 // Check amount is at least the minimum
17790 var currency_code = $( 'input[name="currency_code"]' ).val();
178 - if ( typeof( minimums[currency_code] ) == 'undefined' ) {
179 - minimums[currency_code] = 1;
 91+ if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' ) {
 92+ wgCurrencyMinimums[currency_code] = 1;
18093 }
181 - if ( amount < minimums[currency_code] || error ) {
182 - alert( 'You must contribute at least $1'.replace( '$1', minimums[currency_code] + ' ' + currency_code ) );
 94+ if ( amount < wgCurrencyMinimums[currency_code] || error ) {
 95+ alert( 'You must contribute at least $1'.replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
18396 error = true;
18497 }
18598 return !error;
Index: trunk/extensions/DonationInterface/modules/validate.currencyMinimums.js
@@ -0,0 +1,86 @@
 2+// If you change these, also change in currencyRates.inc.
 3+window.wgCurrencyMinimums = {
 4+ 'AED': 4,
 5+ 'ARS': 4,
 6+ 'AUD': 1,
 7+ 'BBD': 2,
 8+ 'BDT': 76,
 9+ 'BGN': 1.4,
 10+ 'BHD': 0.4,
 11+ 'BMD': 1,
 12+ 'BND': 1.3,
 13+ 'BOB': 7,
 14+ 'BRL': 1.7,
 15+ 'BSD': 1,
 16+ 'BZD': 2,
 17+ 'CAD': 1,
 18+ 'CHF': 0.9,
 19+ 'CLP': 494,
 20+ 'CNY': 6,
 21+ 'COP': 1910,
 22+ 'CRC': 512,
 23+ 'CZK': 18,
 24+ 'DKK': 5,
 25+ 'DOP': 38,
 26+ 'DZD': 73,
 27+ 'EEK': 11,
 28+ 'EGP': 6,
 29+ 'EUR': 0.7,
 30+ 'GBP': 0.6,
 31+ 'GTQ': 7.8,
 32+ 'HKD': 7.7,
 33+ 'HNL': 19,
 34+ 'HRK': 5,
 35+ 'HUF': 219,
 36+ 'IDR': 8960,
 37+ 'ILS': 3.6,
 38+ 'INR': 49,
 39+ 'JMD': 85,
 40+ 'JOD': 0.7,
 41+ 'JPY': 78,
 42+ 'KES': 97,
 43+ 'KRW': 1127,
 44+ 'KYD': 0.8,
 45+ 'KZT': 147,
 46+ 'LBP': 1500,
 47+ 'LKR': 110,
 48+ 'LTL': 2.5,
 49+ 'LVL': 0.5,
 50+ 'MAD': 8.1,
 51+ 'MKD': 45,
 52+ 'MUR': 29,
 53+ 'MVR': 15,
 54+ 'MXN': 13,
 55+ 'MYR': 3,
 56+ 'NOK': 5.5,
 57+ 'NZD': 1.2,
 58+ 'OMR': 0.3,
 59+ 'PAB': 1,
 60+ 'PEN': 2.7,
 61+ 'PHP': 43,
 62+ 'PKR': 86,
 63+ 'PLN': 3,
 64+ 'PYG': 4190,
 65+ 'QAR': 3.6,
 66+ 'RON': 3.1,
 67+ 'RUB': 30,
 68+ 'SAR': 3.7,
 69+ 'SEK': 6.5,
 70+ 'SGD': 1.2,
 71+ 'SVC': 8.7,
 72+ 'THB': 30,
 73+ 'TJS': 4.7,
 74+ 'TND': 1.4,
 75+ 'TRY': 1.7,
 76+ 'TTD': 6,
 77+ 'TWD': 30,
 78+ 'UAH': 8,
 79+ 'USD': 1,
 80+ 'UYU': 19,
 81+ 'UZS': 1760,
 82+ 'VND': 21000,
 83+ 'XAF': 470,
 84+ 'XCD': 2.7,
 85+ 'XOF': 476,
 86+ 'ZAR': 7.8
 87+};
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r102243MFT r102191, r102195, r102196, r102200, r102203, r102213, r102214, r102215, r...awjrichards03:31, 7 November 2011

Status & tagging log