Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23347 ashik.ali 1
$(function() {
24125 govind 2
 
3
	$("#retailer-details-search-button").live(
4
			'click',
5
			function() {
6
				searchContent = $("#retailer-details-search-text").val();
7
				if (typeof (searchContent) == "undefined" || !searchContent) {
8
					searchContent = "";
9
				}
10
				getRetailerDetailsByEmailIdOrMobileNumber(
11
						"retailer-details-container", searchContent);
12
			});
24159 tejbeer 13
 
24125 govind 14
	$(".active-store").live('click', function() {
15
		storeInfo("main-content");
16
	});
23347 ashik.ali 17
	$(".retailer-info").live('click', function() {
18
		retailerInfo("main-content");
19
	});
24125 govind 20
 
23347 ashik.ali 21
	$("#retailer-details-search-text").live("keyup", function(e) {
22
		var keyCode = e.keyCode || e.which;
24125 govind 23
		if (keyCode == 13) {
24
			$("#retailer-details-search-button").click();
25
		}
23347 ashik.ali 26
	});
24125 govind 27
 
28
	$(".deactivate-store").live('click', function() {
29
		var fofoId = $(this).data("fofoid");
30
		console.log(fofoId);
31
		if (confirm("Are you sure you want to deactivate store!") == true) {
32
			deactivateStore("main-content", fofoId);
33
		}
34
 
23347 ashik.ali 35
	});
24125 govind 36
 
37
	$('#retailerAddressState').live('change', function() {
38
		var stateName = $(this).find('option:selected').text();
39
		loadDistrictNames(stateName);
40
	});
24159 tejbeer 41
 
42
	$("#location").live(
43
			'click',
44
			function() {
45
				if ($(this).is(":checked")) {
46
					var emailIdOrMobileNumber = $(
47
							'#retailer-details-search-text').val();
48
					var email = $('#emailId').val();
49
					doGetAjaxRequestHandler(context
50
							+ "/userDetails?emailIdOrMobileNumber="
51
							+ emailIdOrMobileNumber, function(response) {
52
						if (response == "true") {
53
							$("#divLocation").show();
54
						} else {
55
							alert("user can not Exist")
56
							$("#location").prop("checked", false);
57
						}
58
					});
59
 
60
				} else {
61
					$("#divLocation").hide();
62
				}
63
			});
64
 
65
	$(".addlocationbutton").live(
66
			'click',
67
			function() {
68
				var userId = $('#retailerId').text();
69
				var name = $('#personName').val();
70
				var line1 = $('#line1').val();
71
				var line2 = $('#line2').val();
72
				var city = $('#city').val();
73
				var state = $('#state').val();
74
				var pin = $('#pinCode').val();
75
 
76
				if (name === "" && line1 === "" && city === "" && pin === "") {
77
					alert("Field can't be empty");
78
					return;
79
				}
80
				if (name === "") {
81
					alert("name is required");
82
					return;
83
				}
84
				if (line1 === "") {
85
					alert("line1 is required");
86
					return;
87
				}
88
				if (city === "") {
89
					alert("city is required");
90
					return;
91
				}
92
				if (pin === "") {
93
					alert("pin is required");
94
					return;
95
				}
96
 
97
				var locationData = {};
98
				locationData['userId'] = $('#retailerId').text();
99
				locationData['name'] = $('#personName').val();
100
				locationData['line1'] = $('#line1').val();
101
				locationData['line2'] = $('#line2').val();
102
				locationData['city'] = $('#city').val();
103
				locationData['state'] = $('#state').val();
104
				locationData['pin'] = $('#pinCode').val();
105
 
106
				if (confirm("Are you sure you want to add location!") == true) {
107
					doPostAjaxRequestWithJsonHandler(context + "/addLocation",
108
							JSON.stringify(locationData), function(response) {
109
								if (response == 'true') {
110
									alert("successfully Add");
111
									$("#addLocationModal").modal('hide');
112
 
113
								}
114
							});
115
 
116
					return false;
117
				}
118
			});
119
 
23347 ashik.ali 120
});
121
 
23837 ashik.ali 122
function getDistance(lat1, lon1, lat2, lon2) {
24125 govind 123
	var deg2rad = 0.017453292519943295; // === Math.PI / 180
124
	var cos = Math.cos;
125
	lat1 *= deg2rad;
126
	lon1 *= deg2rad;
127
	lat2 *= deg2rad;
128
	lon2 *= deg2rad;
129
	var diam = 12742; // Diameter of the earth in km (2 * 6371)
130
	var dLat = lat2 - lat1;
131
	var dLon = lon2 - lon1;
132
	var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 133
 
24125 govind 134
	return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
135
}
23837 ashik.ali 136
 
24125 govind 137
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
138
	doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
139
			+ emailIdOrMobileNumber, function(response) {
23347 ashik.ali 140
		$('#' + domId).html(response);
24159 tejbeer 141
		if ($("#location").is(":checked")){ 
142
 
143
			$("#divLocation").show();
144
		}
23347 ashik.ali 145
	});
146
}
147
 
24125 govind 148
function updateRetailerDocument() {
149
	// $("#updateRetailerShopDocument0").click( function() {
23347 ashik.ali 150
	console.log("Update Retailer Document Clicked");
24125 govind 151
	// console.log(ownerId);
23347 ashik.ali 152
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
24125 govind 153
	console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
23347 ashik.ali 154
	var file = $('#retailerDocument')[0].files[0];
24125 govind 155
	console.log("file : " + file.name);
156
	uploadRetailerDocument("retailer-details-container", file,
157
			emailIdOrMobileNumber);
23347 ashik.ali 158
}
159
 
24125 govind 160
function updateRetailerShopDocument(ownerId) {
161
	// $("#updateRetailerShopDocument0").click( function() {
23347 ashik.ali 162
	console.log("Update Retailer Shop Document Clicked");
163
	console.log(ownerId);
164
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
24125 govind 165
	console.log("size : " + shopSize);
166
	for (var index = 0; index < shopSize; index++) {
167
		if ("updateRetailerShopDocument" + index == ownerId) {
168
			var emailIdOrMobileNumber = $('#retailer-details-search-text')
169
					.val();
170
			console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
171
			var shopId = $('#retailerShopDocument' + index).attr("shopId");
172
			console.log("shopId : " + shopId);
173
			var file = $('#retailerShopDocument' + index)[0].files[0];
174
			console.log("file : " + file.name);
175
			uploadRetailerShopDocument("retailer-details-container", file,
176
					emailIdOrMobileNumber, shopId);
23347 ashik.ali 177
		}
178
	}
179
}
180
 
24125 govind 181
function loadDistrictNames(stateName) {
182
	if (undefined != $("#districtName")) {
183
		doGetAjaxRequestHandler(
184
				context + "/district/all/stateName?stateName=" + stateName,
185
				function(response) {
186
					console.log(response);
187
					var districtMasters = response.response;
188
					// districtMasters = districtMasters.response;
189
					var districtNameElements = '<option value="" disabled selected>District Name</option>';
190
					for (index = 0; index < districtMasters.length; index++) {
191
						districtNameElements = districtNameElements
192
								+ '<option value="'
193
								+ districtMasters[index].name + '">'
194
								+ districtMasters[index].name + '</option>';
195
					}
196
					$('#districtName').html(districtNameElements);
197
				});
23347 ashik.ali 198
	}
199
}
200
 
24125 govind 201
function retailerInfo(domId) {
202
	doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {
203
		$('#' + domId).html(response);
24159 tejbeer 204
 
23349 ashik.ali 205
	});
24159 tejbeer 206
 
24125 govind 207
}
208
function storeInfo(domId) {
209
	doGetAjaxRequestHandler(context + "/getAllStores", function(response) {
210
		$('#' + domId).html(response);
211
	});
212
}
213
function deactivateStore(domId, fofoId) {
214
	doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
215
			function(response) {
216
				if (response == "true") {
217
					alert("successfully deactivated!");
218
					storeInfo(domId);
219
				}
24159 tejbeer 220
 
24125 govind 221
			});
222
}
24159 tejbeer 223
 
224
function updateLocationButton(id) {
225
 
226
	var userId = id;
227
	var name = $('#personName').val();
228
	var line1 = $('#line1').val();
229
	var line2 = $('#line2').val();
230
	var city = $('#city').val();
231
	var state = $('#state').val();
232
	var pin = $('#pinCode').val();
233
	console.log(id);
234
	if (name === "" && line1 === "" && city === "" && pin === "") {
235
		alert("Field can't be empty");
236
		return;
237
	}
238
	if (name === "") {
239
		alert("name is required");
240
		return;
241
	}
242
	if (line1 === "") {
243
		alert("line1 is required");
244
		return;
245
	}
246
	if (city === "") {
247
		alert("city is required");
248
		return;
249
	}
250
	if (pin === "") {
251
		alert("pin is required");
252
		return;
253
	}
254
 
255
	var changeLocationData = {};
256
 
257
	changeLocationData['userId'] = id;
258
	changeLocationData['name'] = $('#personName').val();
259
	changeLocationData['line1'] = $('#line1').val();
260
	changeLocationData['line2'] = $('#line2').val();
261
	changeLocationData['city'] = $('#city').val();
262
	changeLocationData['state'] = $('#state').val();
263
	changeLocationData['pin'] = $('#pinCode').val();
264
 
265
	console.log(changeLocationData);
266
 
267
	if (confirm("Are you sure you want to add location!") == true) {
268
		doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
269
				.stringify(changeLocationData), function(response) {
270
			if (response == 'true') {
271
				alert("successfully Update");
272
 
273
				$("#addLocationModal").modal('hide');
274
 
275
			}
276
		});
277
 
278
		return false;
279
	}
280
 
281
}