Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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
			},
18
			line1:{
19
				required:true
20
			},
21
			state:{
22
				required:true
23
			},
24
			city:{
25
				required:true
26
			},
27
			pincode:{
28
				required:true,
29
				digits:true,
30
				minlength: 6,
31
                maxlength: 6,
32
			},
33
			phone:{
34
				required:true,
35
				minlength:10,
36
				maxlength:10,
37
				digits:true
38
			},
39
		},
40
		messages:{
41
			name:{
42
				required:"Please enter the name"
43
			},
44
			line1:{
45
				required:"Please enter the address"
46
			},
47
			state:{
48
				required: "Please select a state"
49
			},
50
			city:{
51
				required: "Please enter the city"
52
			},
53
			email:{
54
				require: "Please enter a valid email address"
55
			},
56
			pincode:{
57
				required: "Please enter the pincode",
58
				digits:"Please enter a valid pincode"
59
			},
60
			phone:{
61
				required: "Please enter the phone number",
62
				digits:"Please enter a valid number",
63
				minlength:"Number should be of 10 digits"
64
			}
65
		},
66
		submitHandler: function (form, event) {
67
			event.preventDefault();
68
			var payload = orderDetailsPayload();
69
			if(!validateOrderDetails()){
70
				alert("Please fix highlighted errors");
71
				return false;
72
			}
73
             $.ajax({
74
                 type: "POST",
75
                 url: "create-order",
76
                 data: payload,
77
                 contentType:'application/json',
78
				async: false,
79
				success: function (data) {
80
					emptyBag();
81
					$('#main-content').html(data);
82
				},
83
				error : function() {
84
					alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
85
				},
86
				cache: false,
87
				processData: false
88
             });
89
             return false; // required to block normal submit since you used ajax
90
         }
91
	});
92
 
93
	$( "input.unitPrice").blur(function() {
94
		console.log("unitPrice blur called");
95
		var $element = $(this);
96
		var unitPrice = $element.val();
97
		if(unitPrice != ''){
98
		    $.ajax({
99
		         type: "GET",
100
		         url: "insurancePrices?price="+unitPrice,
101
		         //data: payload,
102
		         //contentType:'application/json',
103
				async: false,
104
				success: function (data) {
105
					console.log("response : "+JSON.stringify(data));
106
					var insurancePriceMap = data.response;
107
					for(key in insurancePriceMap){
108
						var dealerPrice = insurancePriceMap[key].dealerPrice;
109
						var sellingPrice = insurancePriceMap[key].sellingPrice;
110
						$element.closest('tr').find('.insuranceAmount').attr("placeholder", dealerPrice + "-" + sellingPrice);
111
						break;
112
					}
113
				},
114
				error : function() {
115
					alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
116
				},
117
				cache: false,
118
				processData: false
119
		    });
120
	    }
121
	}).focus(function(){
122
		console.log("unitPrice focus called");
123
		var $element = $(this);
124
		$element.closest('tr').find('.insuranceAmount').attr("placeholder", "");
125
	});
126
 
127
});