Subversion Repositories SmartDukaan

Rev

Rev 22956 | Rev 23343 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22245 ashik.ali 1
$().ready(function() {
2
	$("form#cd input").each(function(){
3
		$(this).attr('autocomplete', 'off');
4
	});
5
});
6
$().ready(function() {
7
        // validate the comment form when it is submitted
8
        $('#cd').validate({
9
		rules:{
10
			name:{
11
				required:true
12
			},
13
			email:{
14
				required:true,
15
				email:true
16
			},
17
			line1:{
18
				required:true
19
			},
20
			state:{
21
				required:true
22
			},
23
			city:{
24
				required:true
25
			},
26
			pincode:{
27
				required:true,
28
				digits:true,
29
				minlength: 6,
30
                maxlength: 6,
31
			},
32
			phone:{
33
				required:true,
34
				minlength:10,
35
				maxlength:10,
36
				digits:true
37
			},
38
		},
39
		messages:{
40
			name:{
41
				required:"Please enter the name"
42
			},
43
			line1:{
44
				required:"Please enter the address"
45
			},
46
			state:{
47
				required: "Please select a state"
48
			},
49
			city:{
50
				required: "Please enter the city"
51
			},
52
			email:{
53
				require: "Please enter a valid email address"
54
			},
55
			pincode:{
56
				required: "Please enter the pincode",
57
				digits:"Please enter a valid pincode"
58
			},
59
			phone:{
60
				required: "Please enter the phone number",
61
				digits:"Please enter a valid number",
62
				minlength:"Number should be of 10 digits"
63
			}
64
		},
65
		submitHandler: function (form, event) {
66
			event.preventDefault();
67
			var payload = orderDetailsPayload();
68
			if(!validateOrderDetails()){
69
				alert("Please fix highlighted errors");
70
				return false;
71
			}
72
             $.ajax({
73
                 type: "POST",
74
                 url: "create-order",
75
                 data: payload,
76
                 contentType:'application/json',
77
				async: false,
78
				success: function (data) {
79
					emptyBag();
80
					$('#main-content').html(data);
81
				},
82
				cache: false,
83
				processData: false
84
             });
85
             return false; // required to block normal submit since you used ajax
86
         }
87
	});
88
 
23340 ashik.ali 89
	$("input.unitPrice").blur(function() {
22245 ashik.ali 90
		console.log("unitPrice blur called");
91
		var $element = $(this);
92
		var unitPrice = $element.val();
22354 ashik.ali 93
		var mopPrice = parseFloat($(this).attr('mopPrice'));
94
		if(parseFloat(unitPrice) < mopPrice){
95
			//error = true;
96
			alert("sellingPrice must be greater than equal to mop")
97
			$element.addClass("border-highlight");
98
		}else{
99
			$element.removeClass("border-highlight")
22660 ashik.ali 100
			if(unitPrice == mopPrice){
101
				$("input.discountAmount").removeAttr("readonly");
102
			}
22354 ashik.ali 103
			if(unitPrice != ''){
104
			    $.ajax({
105
			         type: "GET",
106
			         url: "insurancePrices?price="+unitPrice,
107
			         //data: payload,
108
			         //contentType:'application/json',
109
					async: false,
110
					success: function (data) {
111
						console.log("response : "+JSON.stringify(data));
112
						var insurancePriceMap = data.response;
113
						for(key in insurancePriceMap){
114
							var dealerPrice = insurancePriceMap[key].dealerPrice;
115
							var sellingPrice = insurancePriceMap[key].sellingPrice;
116
							$element.closest('tr').find('.insuranceAmount').attr("placeholder", dealerPrice + "-" + sellingPrice);
117
							break;
118
						}
119
					},
120
					error : function() {
121
						alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
122
					},
123
					cache: false,
124
					processData: false
125
			    });
126
		    }
127
		}
22245 ashik.ali 128
	}).focus(function(){
129
		console.log("unitPrice focus called");
130
		var $element = $(this);
131
		$element.closest('tr').find('.insuranceAmount').attr("placeholder", "");
132
	});
22354 ashik.ali 133
 
134
	$( "input.phone").blur(function() {
135
		console.log("phone blur called");
136
		var mobileNumber = $(this).val();
137
		writeOldCustomerDetailsByMobileNumber(mobileNumber);
138
	});
22245 ashik.ali 139
 
140
});