Палсеич— (lusever) wrote in changelog,
Палсеич—
lusever
changelog

[ljcom] r10188: LJSUP-8014: Credit card payment process ...

Committer: pkornilov
LJSUP-8014: Credit card payment process refactoring.
U   trunk/htdocs/js/pay.js
Modified: trunk/htdocs/js/pay.js
===================================================================
--- trunk/htdocs/js/pay.js	2011-03-04 08:47:52 UTC (rev 10187)
+++ trunk/htdocs/js/pay.js	2011-03-04 10:09:16 UTC (rev 10188)
@@ -85,43 +85,6 @@
     return;
 }
 
-function validate_cc_input()
-{
-    var form = document.getElementById("ccform");
-    if (! form) return true;
-
-    var finish = document.getElementById("submit_cc");
-
-    if (! finish) return true;
-    finish.disabled = true;
-
-    var check_fields = [ 'cc_num', 'cc_cvv2', 'name_full', 'addr', 'city', 'email' ];
-
-    for ($i=0;$i < check_fields.length;$i++) {
-        var field = form.elements[ check_fields[$i] ];
-        if ( field.value.length == 0 ) {
-            set_error( "Please enter values for all fields." );
-            finish.disabled = false;
-            return false;
-        }
-    }
-
-    var cc = form.elements[ 'cc_num' ];
-    var star = /\*/g;
-    var starcount = cc.value.match(star);
-    if (starcount) starcount = starcount.length;
-    if ( cc.value.length < 15 || cc.value.length > 32 || starcount >= 1 ) {
-        set_error( "Your credit card number is invalid." );
-        finish.disabled = false;
-        return false;
-    }
-
-    var spinner = document.getElementById("hourglass");
-    if (spinner) spinner.style.display = 'inline';
-
-    return true;
-}
-
 function set_error(text)
 {
     var div = document.getElementById("error");
@@ -410,6 +373,61 @@
 	{
 		// mobile webkit, support :hover
 		jQuery('#shop_vgift .b-gifts-catalog>ul>li>div').click(jQuery.noop);
+	},
+	
+	pageCreditCard: function()
+	{
+		jQuery('form#ccform').each(function()
+		{
+			var form = this;
+			
+			jQuery('dd>input, dd>select', this)
+				.focus(function()
+				{
+					jQuery(this).closest('li')
+						.find('.b-bubble-warning').hide()
+						.end().find('.b-bubble-lite').show();
+				})
+				.blur(function()
+				{
+					jQuery(this).closest('li')
+						.find('.b-bubble-lite').hide()
+						.end().find('.b-bubble-warning').show();
+				});
+				
+				jQuery([this.name_full, this.email]).input(function()
+				{
+					if (/[^a-z0-9@\'. -]/i.test(this.value)) {
+						jQuery(this).closest('li')
+							.find('.b-bubble-lite').hide()
+							.end().find('.b-bubble-alert').show();
+					} else {
+						jQuery(this).closest('li')
+							.find('.b-bubble-lite').show()
+							.end().find('.b-bubble-alert').hide();
+					}
+				});
+			
+			// card type and American Express logic
+			jQuery(this.type).change(function()
+			{
+				var val = jQuery(this).val(),
+					bubble = $('bubble_cc_num'),
+					bubble_ml;
+				if (val !== 'AmEx') {
+					bubble_ml = Shop.ml_cardnumber_bubble.replace('%card_type%', val);
+					jQuery('#cc_num').attr('maxlength', 16);
+				} else {
+					bubble_ml = Shop.ml_cardnumber_bubble_americanexpress;
+					jQuery('#cc_num').attr('maxlength', 15);
+				}
+				
+				Shop.ml_cardnumber_bubble
+				bubble.replaceChild(document.createTextNode(bubble_ml), bubble.lastChild);
+			})
+			// init
+			.change();
+		});
 	}
 }
 
@@ -422,5 +440,6 @@
 	$('shop_wallet') && Shop.pageWallet() ||
 	$('shop_userheads') && Shop.pageUserheads() ||
 	$('shop_diskquota') && Shop.pageDiskquota() ||
-	$('shop_renameaccount') && Shop.pageRename();
+	$('shop_renameaccount') && Shop.pageRename() ||
+	$('ccform') && Shop.pageCreditCard();
 });

Tags: js, ljcom, lusever
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments