https://www.mediawiki.org/wiki/Special:Code/MediaWiki/103537

Revision: 103537
Author:   kaldari
Date:     2011-11-18 00:28:15 +0000 (Fri, 18 Nov 2011)
Log Message:
-----------
payflowpro lightbox form

Modified Paths:
--------------
    trunk/extensions/DonationInterface/donationinterface.php
    trunk/extensions/DonationInterface/gateway_common/interface.i18n.php
    trunk/extensions/DonationInterface/gateway_forms/Form.php
    
trunk/extensions/DonationInterface/gateway_forms/rapidhtml/RapidHtmlResources.php
    
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/lightbox1.css
    
trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/lightbox1.html
    trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js

Modified: trunk/extensions/DonationInterface/donationinterface.php
===================================================================
--- trunk/extensions/DonationInterface/donationinterface.php    2011-11-18 
00:27:01 UTC (rev 103536)
+++ trunk/extensions/DonationInterface/donationinterface.php    2011-11-18 
00:28:15 UTC (rev 103537)
@@ -585,8 +585,11 @@
 
 $wgResourceModules[ 'ext.donationInterface.errorMessages' ] = array(
        'messages' => array(
+               'donate_interface-noscript-msg',
+               'donate_interface-noscript-redirect-msg',
                'donate_interface-error-msg-general',
                'donate_interface-error-msg-js',
+               'donate_interface-error-msg-validation',
                'donate_interface-error-msg-invalid-amount',
                'donate_interface-error-msg-email',
                'donate_interface-error-msg-card-num',

Modified: trunk/extensions/DonationInterface/gateway_common/interface.i18n.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/interface.i18n.php        
2011-11-18 00:27:01 UTC (rev 103536)
+++ trunk/extensions/DonationInterface/gateway_common/interface.i18n.php        
2011-11-18 00:28:15 UTC (rev 103537)
@@ -166,6 +166,7 @@
        'donate_interface-error-msg-nopaypal' => 'Due to a technical error, we 
cannot send your request to PayPal.  Please try using our regular credit card 
donation form.',
        'donate_interface-error-msg' => 'Please enter your $1',
        'donate_interface-error-msg-js' => 'Please enter your',
+       'donate_interface-error-msg-validation' => 'Please correct the errors 
in the form.',
        'donate_interface-error-msg-invalid-amount' => 'Please enter a valid 
amount',
        'donate_interface-error-msg-email' => 'Please enter a valid e-mail 
address',
        'donate_interface-error-msg-card-num' => 'Please enter a valid credit 
card number for one of the accepted credit card types',
@@ -603,6 +604,7 @@
 An alternative to 'field' in the translation could be 'information'.
 
 This is an error message which appears if one or more of the above fields is 
left empty.",
+       'donate_interface-error-msg-validation' => 'Generic error message for 
form validation failure',
        'donate_interface-error-msg-invalid-amount' => 'Error message for 
invalid amount (e.g. if you put a letter in the amount field).',
        'donate_interface-error-msg-email' => 'Error message if the e-mail 
address is not valid (e.g. non-ASCII characters, spaces or lacking @).',
        'donate_interface-error-msg-card-num' => 'The stars are to attract 
attention to the message in a drop-down box. The stars are not interpreted as 
wiki code when in use in the extension.',

Modified: trunk/extensions/DonationInterface/gateway_forms/Form.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_forms/Form.php   2011-11-18 
00:27:01 UTC (rev 103536)
+++ trunk/extensions/DonationInterface/gateway_forms/Form.php   2011-11-18 
00:28:15 UTC (rev 103537)
@@ -959,9 +959,9 @@
         */
        protected function getSmallSecureLogo() {
 
-               $form = '<table id="secureLogo" width="135" border="0" 
cellpadding="2" cellspacing="0" title=' . 
wfMsg('donate_interface-securelogo-title') . '>';
+               $form = '<table id="secureLogo" width="130" border="0" 
cellpadding="2" cellspacing="0" title=' . 
wfMsg('donate_interface-securelogo-title') . '>';
                $form .= '<tr>';
-               $form .= '<td width="135" align="center" valign="top"><script 
type="text/javascript" 
src="https://seal.verisign.com/getseal?host_name=payments.wikimedia.org&size=S&use_flash=NO&use_transparent=NO&lang=en";></script><br
 /><a href="http://www.verisign.com/ssl-certificate/"; target="_blank"  
style="color:#000000; text-decoration:none; font:bold 7px verdana,sans-serif; 
letter-spacing:.5px; text-align:center; margin:0px; padding:0px;">' . 
wfMsg('donate_interface-secureLogo-text') . '</a></td>';
+               $form .= '<td width="130" align="center" valign="top"><script 
type="text/javascript" 
src="https://seal.verisign.com/getseal?host_name=payments.wikimedia.org&size=S&use_flash=NO&use_transparent=NO&lang=en";></script><br
 /><a href="http://www.verisign.com/ssl-certificate/"; target="_blank"  
style="color:#000000; text-decoration:none; font:bold 7px verdana,sans-serif; 
letter-spacing:.5px; text-align:center; margin:0px; padding:0px;">' . 
wfMsg('donate_interface-secureLogo-text') . '</a></td>';
                $form .= '</tr>';
                $form .= '</table>';
        return $form;

Modified: 
trunk/extensions/DonationInterface/gateway_forms/rapidhtml/RapidHtmlResources.php
===================================================================
--- 
trunk/extensions/DonationInterface/gateway_forms/rapidhtml/RapidHtmlResources.php
   2011-11-18 00:27:01 UTC (rev 103536)
+++ 
trunk/extensions/DonationInterface/gateway_forms/rapidhtml/RapidHtmlResources.php
   2011-11-18 00:28:15 UTC (rev 103537)
@@ -28,9 +28,11 @@
                'jquery.ui.resizable',
                'jquery.ui.button',
                'jquery.ui.dialog',
+               'ext.donationInterface.errorMessages',
        ),
        'messages' => array(
                'donate_interface-cc-button',
+               'donate_interface-ccdc-button',
                'donate_interface-paypal-button',
        ),
        'localBasePath' => dirname( __FILE__ 
).'/../../payflowpro_gateway/forms',

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/lightbox1.css
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/lightbox1.css   
    2011-11-18 00:27:01 UTC (rev 103536)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/css/lightbox1.css   
    2011-11-18 00:28:15 UTC (rev 103537)
@@ -135,6 +135,8 @@
 .call-r {
     float: right;
     margin: 0.2em 0 1em 1em;
+    background-color: #CCE7CD;
+    border: 1px solid #5EAC58;
 }
 #loading {
     font-size: 12px;
@@ -171,8 +173,9 @@
        font-size: 0.8em;
 }
 input.btn {
-       font-size: 15px;
+       font-size: 14px;
        margin-bottom: 4px;
+       width: 18em;
 }
 #dialog{
        overflow: hidden;
@@ -283,6 +286,15 @@
        right: 25px;
        margin: 0 !important;
 }
+#spinner {
+       position: absolute;
+       width: 16px;
+       height: 16px;
+       bottom: 37px;
+       right: 133px;
+       z-index: 2000;
+       display: none;
+}
 #steps #card-errors {
        font-size: 13px;
        line-height: 15px;
@@ -295,3 +307,13 @@
        font-size: 11px;
        line-height: 13px;
 }
+#secure-logo {
+       float: right;
+}
+#moreinfolinks {
+       font-size: 12px;
+}
+#cvv-link {
+       color: #2779AA;
+       font-size: 0.8em;
+}

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/lightbox1.html
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/lightbox1.html 
    2011-11-18 00:27:01 UTC (rev 103536)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/lightbox1.html 
    2011-11-18 00:28:15 UTC (rev 103537)
@@ -16,13 +16,13 @@
                                <div id="donate">
                                        <noscript>
                                                <div id="noscript">
-                                                       <p id="noscript-msg">It 
appears that you do not have JavaScript enabled, or your browser does not 
support it. In order to provide a safe, secure and pleasant experience, our 
donation form requires JavaScript.</p><p id="noscript-redirect-msg">If you 
cannot or do not wish to enable JavaScript, you may still contribute by 
visiting:</p><p id="noscript-redirect-link"><a 
href="http://wikimediafoundation.org/wiki/DonateNonJS/en";>http://wikimediafoundation.org/wiki/DonateNonJS/en</a></p>
+                                                       <p 
id="noscript-msg">%donate_interface-noscript-msg%</p>
+                                                       <p 
id="noscript-redirect-msg">%donate_interface-noscript-redirect-msg%</p>
+                                                       <p 
id="noscript-redirect-link"><a 
href="http://wikimediafoundation.org/wiki/DonateNonJS/en";>http://wikimediafoundation.org/wiki/DonateNonJS/en</a></p>
                                                </div>
                                        </noscript>
-                       
+                                       <div id="topError" 
class="creditcard-error-msg"></div>
                                        <h3 
id="amount-heading">%donate_interface-amount-legend%</h3>
-                                       
-                                       <p id="topError" 
class="creditcard-error-msg"></p>
                                        <form method="post" 
name="paypalcontribution">
                                                <div style="display: block;" 
id="amount-content">
                                                        <div 
id="amtErrorMessages" class="small"></div>
@@ -42,37 +42,37 @@
                                                        </table> 
                                          
                                                        <p 
class="donate-options">
-                                                               <input 
class="btn" id="cc" value="%donate_interface-cc-button%" type="button"/>
-                                                               <br><input 
class="btn" id="pp" value="%donate_interface-paypal-button%" 
type="button"><span id="loading"></span>
+                                                               <input 
class="btn" id="cc" value="%donate_interface-ccdc-button%" type="button"/><br/>
+                                                               <input 
class="btn" id="pp" value="%donate_interface-paypal-button%" type="button"/>
                                                        </p>
                                                </div>
                                        </form>
                                </div>
-                               
+                               <hr/>
                                <div id="callout-content">
-                                       <hr/>
                                        <p 
id="informationsharing">%donate_interface-informationsharing|url%</p>
+                                       <div 
id="secure-logo">@verisign_logo</div>
+                                       <ul id="moreinfolinks">
+                                               <li><a 
href="http://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=Monthly_donations&language=@language&uselang=@language&country=@country";>%donate_interface-monthly-donation%</a></li>
+                                               <li><a 
href="http://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=Ways_to_Give&language=@language&uselang=@language&country=@country";>%donate_interface-otherways-short%</a></li>
+                                               <li><a 
href="http://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=FAQ&language=@language&uselang=@language&country=@country";>%donate_interface-faqs%</a></li>
+                                               <li><a 
href="http://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=Tax_Deductibility&language=@language&uselang=@language&country=@country";>%donate_interface-tax-info%</a></li>
+                                       </ul>
                                </div>
                        </div>
-                         
+                       <!-- The appeal -->
                        <h2 id="appeal-head"><span 
class="mw-headline">{{LanguageSwitch|2011FR/@appeal-title|@language}}</span></h2>
                        <div id="appeal-body" 
class="plainlinks">{{LanguageSwitch|2011FR/@appeal|@language}}</div>
                </div>
        </div>
-                 
-       <hr/>
-                 
-       <p>
-               <a 
href="http://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=Ways_to_Give&language=@language&uselang=@language&country=@country";>%donate_interface-otherways-short%</a><br/>
-               <a 
href="http://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=FAQ&language=@language&uselang=@language&country=@country";>%donate_interface-faqs%</a>
-       </p>
+
 </div>
     
 <div id="dialog">
        <div id="steps">
                <form id="donationForm" name="donationForm" action="" 
method="post">
                        <fieldset class="step">
-                               
<legend>%donate_interface-billing-address%</legend>
+                               
<legend>%donate_interface-cc-form-header-personal%</legend>
                                <input type="hidden" name="gateway" 
value="payflowpro" id="gateway" /> 
                                <input type="hidden" name="returnto" 
value="Thank_You/en" />
                                <input type="hidden" value="@action" 
name="action" />
@@ -141,11 +141,11 @@
                                                </tr>
                                                </table>
                                        </div>
-                                       <a href="#" 
class="continue-button">Continue</a>
+                                       <a href="#" id="personal-continue" 
class="continue-button">Continue</a>
                                </div>
                        </fieldset>
                        <fieldset class="step">
-                               <legend>Payment</legend>
+                               
<legend>%donate_interface-cc-form-header-payment%</legend>
                                <div class="step-content">
                                        <div class="stuff">
                                                <div id="card-errors"></div>
@@ -206,13 +206,15 @@
                                                                <label 
for="email">Security Code</label>
                                                        </td>
                                                        <td>
-                                                               <input 
name="cvv" size="30" value="@cvv" type="text" maxlength="100" class="required" 
id="cvv" style="width: 50px;" />
+                                                               <input 
name="cvv" size="30" value="@cvv" type="text" maxlength="100" class="required" 
id="cvv" style="width: 50px;" />&#160;
+                                                               <a href="#" 
onclick="PopupCVV(); return false;" id="cvv-link">What is this?</a>
                                                        </td>
                                                </tr>
                                                </table>
                                        </div>
                                        <a href="#" class="back-button" 
id="goback">Back</a>
-                                       <a href="#" class="continue-button" 
id="submitcreditcard">Continue</a>
+                                       <a href="#" id="cc-continue" 
class="continue-button">Continue</a>
+                                       <div id="spinner"><img 
src="@script_path/extensions/DonationInterface/gateway_forms/includes/loading-white.gif"/></div>
                                </div>
                        </fieldset>
                </form>

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
===================================================================
--- trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js 
2011-11-18 00:27:01 UTC (rev 103536)
+++ trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js 
2011-11-18 00:28:15 UTC (rev 103537)
@@ -25,27 +25,20 @@
        paymentErrorString = temp.join( "<br />" );
 
        // show the errors
-       var prevError = false;
        if ( amountErrorString != "" ) {
-               $( "#amtErrorMessages" ).html( amountErrorString );
-               prevError = true;
+               $( "#topError" ).html( amountErrorString );
+       } else if ( billingErrorString != "" ) {
+               $( "#topError" ).html( billingErrorString );
+       } else if ( paymentErrorString != "" ) {
+               $( "#topError" ).html( paymentErrorString );
        }
-       if ( billingErrorString != "" ) {
-               $( "#billingErrorMessages" ).html( billingErrorString );
-               if ( !prevError ) {
-                       prevError = true;
-               }
-       }
-       if ( paymentErrorString != "" ) {
-               $( "#paymentErrorMessages" ).html( paymentErrorString );
-       }
        
        $( '#dialog' ).dialog( {
                width: 600,
                resizable: false,
         autoOpen: false,
         modal: true,
-        title: mw.msg( 'donate_interface-cc-button' )
+        title: mw.msg( 'donate_interface-ccdc-button' )
        } );
        
        // If the form is being reloaded, restore the amount
@@ -65,22 +58,52 @@
        }
        
        $( '#cc' ).click( function() {
+       
+               // Make sure cookies are enabled
+               document.cookie = 'wmf_test=1;';
+               if ( document.cookie.indexOf( 'wmf_test=1' ) != -1 ) {
+                       document.cookie = 'wmf_test=; expires=Thu, 01-Jan-70 
00:00:01 GMT;'; // unset the cookie
+               } else {
+                       alert( mw.msg( 'donate_interface-error-msg-cookies' ) 
); // display error
+                       return false;
+               }
+               
                if ( validateAmount() ) {
                        $( '#dialog' ).dialog( 'open' );
+                       $( "#spinner" ).hide(); // just in case
                }
        });
        $( '#pp' ).click( function() {
                if ( validateAmount() ) {
                        //$( 'input#pp' ).attr( 'disabled', 'disabled' );
                        $( "input[name='gateway']" ).val( 'paypal' );
-                       document.paypalcontribution.action = 
"https://wikimediafoundation.org/wiki/Special:ContributionTracking/en";;
+                       $( 'input[name="PaypalRedirect"]' ).val( "1" );
+                       document.paypalcontribution.action = actionURL;
                        document.paypalcontribution.submit();
                }
        });
        
-       /* Set selected amount to amount */
-       $( "input[name='amountRadio']" ).click( function() { setAmount( $( this 
) ); } );
-       $( "#other-amount" ).change( function() { setAmount( $( this ) ); } );
+       // Set amount when a radio button is clicked
+       $( 'input[name="amountRadio"]' ).click( function() {
+               if ( !isNaN( $( this ).val() ) ) {
+                       setAmount( $( this ) );
+               }
+               if ( $( this ).val() == 'other' ) {
+                       setAmount( $( '#other-amount' ) );
+               }
+       } );
+       // Change the amount when "other" is focused
+       $( "#other-amount" ).focus( function() {
+               $( '#input_amount_other' ).attr( 'checked', true );
+               setAmount( $( '#other-amount' ) );
+       } );
+       // Reset the amount field when "other" is changed
+       $( "#other-amount" ).keyup( function() {
+               if ( $( '#input_amount_other' ).is( ':checked' ) ) {
+                       setAmount( $( this ) );
+               }
+       } );
+       
        function setAmount(e) { $("input[name='amount']").val( e.val() ); }
 
        /* number of fieldsets */
@@ -94,10 +117,7 @@
        Set the final sum as the total width of the steps element.
        */
        var stepsWidth  = 0;
-    var widths                 = new Array();
        $( '#steps .step' ).each( function(i) {
-        var $step              = $( this );
-               widths[i]               = stepsWidth;
         stepsWidth             += 600; // Hard-coding as $.width() is not 
working for some reason
     } );
        $( '#steps' ).width( stepsWidth );
@@ -107,37 +127,33 @@
        
        /* make continue buttons */
        $( 'a.continue-button' ).button();
-       $( 'a.continue-button' ).click( function(e) {
-               var $this       = $( this );
-               current = $( this ).parent().parent().index() + 1;
-               if ( current == fieldsetCount ) {
-                       finalSubmit();
-                       return false;
-               }
-               if ( validateStep( current ) === 1 ) {
-                       current = current + 1;
-                       $( '#steps' ).stop().animate( { marginLeft: '-' + 
widths[current - 1] + 'px' }, 500, 
+       $( 'a#personal-continue' ).click( function(e) {
+               if ( validatePersonal() ) {
+                       // Advance to the next step
+                       $( '#steps' ).stop().animate( { marginLeft: '-600px' }, 
500, 
                                function() {
-                               $( '#donationForm' ).children( ':nth-child(' + 
parseInt(current) + ')' ).find( ':input:first' ).focus();
+                               $( '#donationForm' ).children( ':nth-child(1)' 
).find( ':input:first' ).focus();
                        }
                );
-               } else {
-                       $this.blur();
                }
-               
-        e.preventDefault();
+               $( this ).blur();
+               e.preventDefault();
+               return false;
     });
+    $( 'a#cc-continue' ).click( function(e) {
+       finalSubmit();
+               e.preventDefault();
+               return false;
+    });
     
     /* Make back button */
        $( 'a.back-button' ).button();
        $( 'a.back-button' ).click( function(e) {
-               var $this       = $( this );
                /* Set current to 1 less than previous step */
                current = $( this ).parent().parent().index();
-               
-               $( '#steps' ).stop().animate( { marginLeft: '+' + 
widths[current - 1] + 'px' }, 500 );
-               
-        e.preventDefault();
+               $( '#steps' ).stop().animate( { marginLeft: '0px' }, 500 );
+               $( this ).blur();
+               e.preventDefault();
     });
 
        /* Hitting tab on the last input of each fieldset makes the form slide 
to the next step. */
@@ -152,37 +168,42 @@
                });
        });
 
-       /*
-       Validates errors on all the fieldsets.
-       Records if the form has errors in $( '#donationForm' ).data().
-       */
-       function validateSteps() {
-               var formErrors = false;
-               for( var i = 1; i < fieldsetCount; ++i ) {
-                       var error = validateStep(i);
-                       if ( error == -1 ) formErrors = true;
-               }
-               $( '#donationForm' ).data( 'errors', formErrors );
-       }
-       
        function finalSubmit() {
-       
-               // Reset the error display
-               $( '#card-errors' ).empty();
+               var step = 2;
+               var errors = false;
                
-               var formErrors = false;
-               for( var i = 1; i <= fieldsetCount; ++i ) {
-                       var error = validateStep(i);
-                       if ( error == -1 ) formErrors = true;
+               $( '#donationForm' ).children( ':nth-child(' + step + ')' 
).find( ':input:not(button).required' ).each( function() {
+                       var $this               = $( this );
+                       var valueLength = $.trim( $this.val() ).length;
+                       if ( valueLength == 0 ) {
+                               errors = true;
+                               $this.css( 'background-color', '#FFEDEF' );
+                       } else {
+                               $this.css( 'background-color', '#FFFFFF' );
+                       }
+               });
+               
+               // Validate credit card number
+               cardNumber = $( '#card_num' ).val();
+               cardNumber = $.trim( cardNumber );
+               if ( cardNumber != '' ) {
+                       cardNumber = cardNumber.replace(/ /g,''); // remove any 
spaces
+                       // Make sure it contains only digits
+                       var ccCheckRegExp = /[^\d]/; 
+                       if ( ccCheckRegExp.test(cardNumber) ) {
+                               errors = true;
+                               $( '#card_num' ).css( 'background-color', 
'#FFEDEF' );
+                       } else {
+                               $( '#card_num' ).css( 'background-color', 
'#FFFFFF' );
+                       }
                }
-               $( '#donationForm' ).data( 'errors', formErrors );
                
-               if ( $( '#donationForm' ).data( 'errors' ) ) {
-                       alert( 'Please correct the errors in the form.' );
+               if ( errors ) {
+                       //alert( mw.msg( 
'donate_interface-error-msg-validation' ) );
                        return false;
                } else {
                        /* Set country to US */
-                       $( "input[name='country']" ).val('US' );
+                       $( "input[name='country']" ).val( 'US' );
                                                        
                        /* Set expiration date */
                        $( "input[name='expiration']" ).val(
@@ -190,81 +211,55 @@
                        )
                        
                        /* Submit the form */
-                       var sendData = {
-                               'action': 'donate',
-                               'gateway': 'payflowpro',
-                               'currency_code': 'USD',
-                               'amount': $( "input[name='amount']" ).val(),
-                               'fname': $( "input[name='fname']" ).val(),
-                               'lname': $( "input[name='lname']" ).val(),
-                               'street': $( "input[name='street']" ).val(),
-                               'city': $( "input[name='city']" ).val(),
-                               'state': $( 'select#state option:selected' 
).val(),
-                               'zip': $( "input[name='zip']" ).val(),
-                               'emailAdd': $( "input[name='emailAdd']" ).val(),
-                               'country': $( "input[name='country']" ).val(),
-                               'payment_method': 'cc',
-                               'language': 'en',
-                               
-                               'expiration': $( "input[name='expiration']" 
).val(),
-                               'card_num': $( "input[name='card_num']" ).val(),
-                               'cvv': $( "input[name='cvv']" ).val(),
-                               'card_type': '',
-                               
-                               'format': 'json'
-                       };
-       
-                       $.ajax( {
-                               'url': mw.util.wikiScript( 'api' ),
-                               'data': sendData,
-                               'dataType': 'json',
-                               'type': 'POST',
-                               'success': function( data ) {
-                                       console.debug( data );
-                                       if ( data.result.errors ) {
-                                               var errors = new Array();
-                                               $.each( data.result.errors, 
function( index, value ) {
-                                                       $( '#card-errors' 
).append( '<div class="error-msg">'+value+'</div>' );
-                                               } );
-                                       } else {
-                                               if ( data.result.returnurl ) {
-                                                       window.location = 
data.result.returnurl;
-                                               }
-                                       }
-                               }
-                       } );
-                       //document.donationForm.action = $( 
"input[name='action']" ).val();
+                       document.donationForm.action = $( 
"input[name='action']" ).val();
+                       $( "#spinner" ).show();
                        //document.donationForm.submit();
                }
        }
-
-       /*
-       validates one fieldset
-       returns -1 if errors found, or 1 if not
-       */
-       function validateStep( step ) {
-               var error = 1;
-               $( '#donationForm' ).children( ':nth-child(' + parseInt(step) + 
')' ).find( ':input:not(button).required' ).each( function() {
+       
+       function validatePersonal() {
+               var step = 1;
+               var errors = false;
+               
+               $( '#donationForm' ).children( ':nth-child(' + step + ')' 
).find( ':input:not(button).required' ).each( function() {
                        var $this               = $( this );
-                       var valueLength = jQuery.trim( $this.val() ).length;
-
-                       if ( valueLength == '' ) {
-                               error = -1;
+                       var valueLength = $.trim( $this.val() ).length;
+                       if ( valueLength == 0 ) {
+                               errors = true;
                                $this.css( 'background-color', '#FFEDEF' );
                        } else {
                                $this.css( 'background-color', '#FFFFFF' );
                        }
                });
-
-               return error;
+               
+               // Validate email address
+               email = $( '#email' ).val();
+               email = $.trim( email );
+               if( email != '' ) {
+                       var apos = email.indexOf("@");
+                       var dotpos = email.lastIndexOf(".");
+                       if( apos < 1 || dotpos-apos < 2 ) {
+                               errors = true;
+                               $( '#email' ).css( 'background-color', 
'#FFEDEF' );
+                       } else {
+                               $( '#email' ).css( 'background-color', 
'#FFFFFF' );
+                       }
+               }
+               
+               if ( errors ) {
+                       return false;
+               } else {
+                       return true;
+               }
        }
 
        /**
         * Validate the donation amount to make sure it is formatted correctly 
and at least a minimum amount.
         */
        function validateAmount() {
-               var error = true;
+               var errors = false;
                var amount = $( "input[name='amount']" ).val(); // get the 
amount
+               
                // Normalize weird amount formats.
                // Don't mess with these unless you know what you're doing.
                amount = amount.replace( /[,.](\d)$/, '\:$10' );
@@ -273,8 +268,8 @@
                amount = amount.replace( /:/, '.' );
                $( 'input[name="amount"]' ).val( amount ); // set the new 
amount back into the form
                
-               // Check amount is a real number, sets error as true (good) if 
no issues
-               error = ( amount == null || isNaN( amount ) || amount.value <= 
0 );
+               // Check amount is a real number greater than 0
+               errors = ( amount == null || isNaN( amount ) || parseFloat( 
amount ) <= 0 );
                
                // Find out the currency code
                if ( $( 'input[name="currency_code"]' ).val() == '' ) {
@@ -288,12 +283,16 @@
                if ( typeof( wgCurrencyMinimums[currency_code] ) == 'undefined' 
) {
                        wgCurrencyMinimums[currency_code] = 1;
                }
-               if ( amount < wgCurrencyMinimums[currency_code] || error ) {
+               if ( amount < wgCurrencyMinimums[currency_code] || errors ) {
+                       errors = true;
                        alert( mw.msg( 'donate_interface-smallamount-error' 
).replace( '$1', wgCurrencyMinimums[currency_code] + ' ' + currency_code ) );
-                       error = true;
                        $( '#other-amount' ).val( '' );
                        $( '#other-amount' ).focus();
                }
-               return !error;
+               if ( errors ) {
+                       return false;
+               } else {
+                       return true;
+               }
        };
 });


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to