Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7226 anupam.sin 1
$(function() {
7255 amit.gupta 2
 
3
	$("#query").autocomplete({ autoFocus: true, minLength: 3,
4
		source: "auto-suggest",
5
		select: function( event, ui ) {
6
		this.value = ui.item.value;
7
		$('#formSearch').submit();
8
		return false;
9
		}
10
	}); 
11
 
7226 anupam.sin 12
	$('#pincodeForm').submit(function() {
13
 
14
		if($('#pincodeSubmit:hidden').length == 1) {
15
			return false;
16
		}
17
 
18
		if ($('#pincodeText').val().length != 6) {
19
			alert('Please enter 6 digit pin code');
20
			return false;
21
		}
22
 
23
		var result = $('#pincodeText').val().match(/^\d*$/);
24
		if(result == null || result.length == 0) {
25
			alert('Please enter a valid pin code');
26
			return false;
27
		}
28
 
7293 anupam.sin 29
		$('#priceDiv').empty();
7226 anupam.sin 30
		showLoading();
31
		$.ajax({
32
			type: "POST",
7268 anupam.sin 33
			url: "/storewebsite/estimate",
7226 anupam.sin 34
			dataType:"json",
7268 anupam.sin 35
			data:$('#pincodeForm').serialize(),
36
//			timeout: 10000,
7226 anupam.sin 37
			success:function(msg) {
38
				hideLoading();
39
				if(msg.length != 0) {
7293 anupam.sin 40
					if(msg.selling_price == 0.0) {
41
						$('#loading').hide();
42
						$('#shippingAddress').hide();
43
						$('#priceDiv').html("<div class='error'>There was some error. Please try again.</div>");
44
						$('#pincodeSubmit').show();
45
					} else {
46
						$('#priceDiv').html(
47
						"<div class='date'><span class='infoText'>Get this product by </span><span class='infoValue'>" + msg.delivery_estimate + "</span></div>" + 
48
						"<div class='price'><span class='infoText'>Total Price</span><span id='totalPrice' class='infoValue'>&nbsp;Rs.&nbsp;" + msg.selling_price + "</span></div>" +
49
						"<div class='advance'><span class='infoText'>Advance to be paid</span><span class='infoValue'>&nbsp;Rs.&nbsp;" + msg.min_advance_amount + "</span></div>");
50
						$('#shippingAddress input[name=price]').val(msg.selling_price);
51
						$('#shippingAddress input[name=advanceAmount]').val(msg.min_advance_amount);
52
						$('#shippingAddress input[name=deliveryDate]').val(msg.delivery_estimate);
53
						$('#shippingAddress input[name=minPrice]').val(msg.min_selling_price);
54
						$('#shippingAddress input[name=maxPrice]').val(msg.max_selling_price);
55
						$('#pincodeInput').val($('#pincodeText').val());
56
						$('#editPriceButton').show();
57
						$('#editPriceBox').val(msg.selling_price);
58
					}
59
 
7226 anupam.sin 60
				} else {
61
					$('#priceDiv').html("<div class='error'>No info found for this pincode. Please try again.</div>");
62
				}
63
			},
64
			error : function(msg) {
65
				$('#loading').hide();
66
				$('#shippingAddress').hide();
67
				$('#priceDiv').html("<div class='error'>There was some error. Please try again.</div>");
68
				$('#pincodeSubmit').show();
69
	        },
70
	        complete : function() {
71
	        	$('#pinSpan').html($('#pincodeText').val());
72
 
73
	        }
74
		});
75
		return false;
76
	});
77
 
78
	function showLoading() {
79
		$('#pincodeSubmit').hide();
80
		$('#shippingAddress').hide();
81
		$('#loading').show();
82
	}
83
 
84
	function hideLoading() {
85
		$('#loading').hide();
86
		$('#shippingAddress').show();
87
	}
88
 
89
	$('#changePincode').click(function() {
90
		$('#shippingAddress')[0].reset();
91
		$('#shippingAddress input:hidden').val('');
92
		$('#shippingAddress').hide();
93
		$('#priceDiv').empty();
94
		$('#pincodeSubmit').show();
95
	});
7248 anupam.sin 96
 
97
	$('#pincodeEdit').click(function(event){
98
		    event.preventDefault();
99
		    var newForm = jQuery('<form>', {
100
		        'action': '/storewebsite/order-details',
101
		        'target': '_top'
102
		    }).append(jQuery('<input>', {
103
	        'name': 'product_id',
104
	        'value': '9161',
105
	        'type': 'hidden'
106
		}));
107
	    newForm.submit();
108
	});
109
 
110
	$('#addressEdit').click(function() {
111
		$('#createOrder, #showPinDiv, #showAddDiv').hide();
112
		$('#editAddBlock').show();
113
	});
114
 
115
	$('#saveEditedAdd').click(function() {
116
		var editedFields = $('#editAddBlock input');
117
		editedFields.each(function(i, inputField) {
118
			if($(inputField).val() == "") {
119
				alert("Please enter correct " + $(inputField).attr('name'));
120
				return false;
121
			}
122
 
123
			if ($(inputField).attr('name') == "phone") {
124
				if ($(inputField).val().length != 10) {
125
					alert('Please enter a 10 digit mobile number');
126
					return false;
127
				}
128
 
129
				var result = $(inputField).val().match(/^\d*$/);
130
				if(result == null || result.length == 0) {
131
					alert('Please enter a valid mobile number');
132
					return false;
133
				}
134
			}
135
 
136
			var nameToSearch = $(inputField).attr("name");
137
			$('#showAddDiv [name="' + nameToSearch + '"]').html($(inputField).val());
138
			$('#createOrderForm input[name="' + nameToSearch + '"]').val($(inputField).val());
139
		});
140
 
141
		$('#editAddBlock').hide();
142
		$('#createOrder, #showPinDiv, #showAddDiv').show();
143
	});
144
 
145
	$('#paymode').change(function() {
146
		if($('#paymode input:radio[name="paymode"]:checked').val() == "card") {
147
			$('#bankSelector').show();
148
		} else {
149
			$('#bankSelector').hide();
150
		}
151
	});
7293 anupam.sin 152
 
153
	$('#editPriceButton').click(function() {
154
		$('#editPriceButton').hide();
155
		$('#editPriceSpan').show();
156
	});
157
 
158
	$('#priceFixButton').click(function() {
159
		var result = $('#editPriceBox').val().match(/^\d*$/);
160
		if(result == null || result.length == 0) {
161
			alert('Please enter a valid amount');
162
			return false;
163
		}
164
 
165
		if(parseFloat($('#editPriceBox').val()) > parseFloat($('#shippingAddress input[name=maxPrice]').val())) {
166
			alert('You cannot sell this product at more than Rs.' + $('#shippingAddress input[name=maxPrice]').val());
167
			return false;
168
		}
169
 
170
		if(parseFloat($('#editPriceBox').val()) < parseFloat($('#shippingAddress input[name=advanceAmount]').val())) {
171
			alert('You cannot sell below Rs. ' + $('#shippingAddress input[name=advanceAmount]').val());
172
			return false;
173
		}
174
 
175
		if(parseFloat($('#editPriceBox').val()) < parseFloat($('#shippingAddress input[name=minPrice]').val())) {
176
			alert('You will need permission of the zonal head to to sell at this price');
177
		}
178
 
179
		$('#editPriceButton').show();
180
		$('#editPriceSpan').hide();
181
		$('#totalPrice').empty();
182
		$('#totalPrice').text(' Rs. ' + parseFloat($('#editPriceBox').val()).toFixed(1));
183
		$('#shippingAddress input[name=price]').val($('#editPriceBox').val());
184
	});
7226 anupam.sin 185
});
186
 
187
function validateAddress() {
7248 anupam.sin 188
	if ($('input[name=name]').val() == "") {
189
		alert("Please enter the customer's name");
190
		return false;
191
	}
192
 
193
	if ($('input[name=phone]').val().length != 10) {
194
		alert('Please enter a 10 digit mobile number');
195
		return false;
196
	}
197
 
198
	var result = $('input[name=phone]').val().match(/^\d*$/);
199
	if(result == null || result.length == 0) {
200
		alert('Please enter a valid mobile number');
201
		return false;
202
	}
203
 
7226 anupam.sin 204
	if ($('input[name=line1]').val() == "") {
205
		alert('Please enter a shipping address');
206
		return false;
207
	}
208
	if ($('input[name=line2]').val() == "") {
209
		alert('Please enter a shipping address');
210
		return false;
211
	}
212
	if ($('input[name=city]').val() == "") {
213
		alert('Please enter the name of the city');
214
		return false;
215
	}
216
	if ($('input[name=state]').val() == "") {
217
		alert('Please enter the name of the state');
218
		return false;
219
	}
220
	return true;
7248 anupam.sin 221
}
222
 
223
function validatePaymentDetails() {
224
	if($('#paymode input:radio[name="paymode"]:checked').val() == "card") {
225
		if($('#bankSelector input:radio[name="bank"]:checked').length == 0) {
226
			alert('Please select the name of the bank of card terminal');
227
			return false;
228
		}
229
	}
7226 anupam.sin 230
}