Subversion Repositories SmartDukaan

Rev

Rev 27171 | Rev 27202 | 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
	});
24680 govind 17
	$(".inactive-store").live('click', function() {
18
		inactiveStoreInfo("main-content");
19
	});
23347 ashik.ali 20
	$(".retailer-info").live('click', function() {
21
		retailerInfo("main-content");
22
	});
24125 govind 23
 
27171 tejbeer 24
	$("#retailerAddressPinCode").live(
25
			'change',
26
			function() {
27
 
28
				var pincode = $('#retailerAddressPinCode').val();
29
 
30
				if (undefined != pincode) {
31
					doGetAjaxRequestHandler(context + "/postOffice?pinCode="
32
							+ pincode,
33
							function(response) {
34
								console.log(response.response.state);
35
 
36
								$('#retailerAddressState').val(
37
										response.response.state);
27191 tejbeer 38
								loadDistrictNames(response.response.state);
27171 tejbeer 39
								for(let city of response.response.cities){
40
									    var opt = $("<option>").val(city).text(city);
41
				                        $('#retailerAddressCity').append(opt);
42
 
43
								}
44
 
45
							});
46
				}
47
			});
48
 
23347 ashik.ali 49
	$("#retailer-details-search-text").live("keyup", function(e) {
50
		var keyCode = e.keyCode || e.which;
24125 govind 51
		if (keyCode == 13) {
52
			$("#retailer-details-search-button").click();
53
		}
23347 ashik.ali 54
	});
24125 govind 55
 
56
	$(".deactivate-store").live('click', function() {
57
		var fofoId = $(this).data("fofoid");
58
		console.log(fofoId);
59
		if (confirm("Are you sure you want to deactivate store!") == true) {
60
			deactivateStore("main-content", fofoId);
61
		}
62
 
23347 ashik.ali 63
	});
24976 amit.gupta 64
	$(".login_as").live('click', function() {
25638 amit.gupta 65
		var fofoId = $('#partnerId').val();
24976 amit.gupta 66
		loginAsPartner(fofoId);
27171 tejbeer 67
 
24976 amit.gupta 68
	});
24125 govind 69
 
24349 amit.gupta 70
	$(".extend-billing").live('click', function() {
71
		var fofoId = $(this).data("fofoid");
72
		console.log(fofoId);
73
		if (confirm("Are you sure you want to extend Billing?")) {
74
			extendBilling($(this).parent(), fofoId);
75
		}
76
 
24125 govind 77
	});
27191 tejbeer 78
 
27171 tejbeer 79
	/*
80
	 * $('#retailerAddressState').live('change', function() { var stateName =
27191 tejbeer 81
	 * $(this).find('option:selected').text();
27171 tejbeer 82
	 * 
27191 tejbeer 83
	 * loadDistrictNames(stateName); });
27171 tejbeer 84
	 */
27191 tejbeer 85
 
24159 tejbeer 86
 
27171 tejbeer 87
	$("#location").live('click', function() {
88
		if ($(this).is(":checked")) {
24159 tejbeer 89
 
27171 tejbeer 90
			$("#divLocation").show();
24159 tejbeer 91
 
27171 tejbeer 92
		} else {
93
			$("#divLocation").hide();
94
		}
95
	});
96
 
24159 tejbeer 97
	$(".addlocationbutton").live(
98
			'click',
99
			function() {
100
				var userId = $('#retailerId').text();
101
				var name = $('#personName').val();
102
				var line1 = $('#line1').val();
103
				var line2 = $('#line2').val();
104
				var city = $('#city').val();
105
				var state = $('#state').val();
106
				var pin = $('#pinCode').val();
107
 
108
				if (name === "" && line1 === "" && city === "" && pin === "") {
109
					alert("Field can't be empty");
110
					return;
111
				}
112
				if (name === "") {
113
					alert("name is required");
114
					return;
115
				}
116
				if (line1 === "") {
117
					alert("line1 is required");
118
					return;
119
				}
120
				if (city === "") {
121
					alert("city is required");
122
					return;
123
				}
124
				if (pin === "") {
125
					alert("pin is required");
126
					return;
127
				}
128
 
129
				var locationData = {};
130
				locationData['userId'] = $('#retailerId').text();
131
				locationData['name'] = $('#personName').val();
132
				locationData['line1'] = $('#line1').val();
133
				locationData['line2'] = $('#line2').val();
134
				locationData['city'] = $('#city').val();
135
				locationData['state'] = $('#state').val();
136
				locationData['pin'] = $('#pinCode').val();
137
 
138
				if (confirm("Are you sure you want to add location!") == true) {
139
					doPostAjaxRequestWithJsonHandler(context + "/addLocation",
140
							JSON.stringify(locationData), function(response) {
141
								if (response == 'true') {
142
									alert("successfully Add");
143
									$("#addLocationModal").modal('hide');
144
 
145
								}
146
							});
147
 
148
					return false;
149
				}
150
			});
151
 
23347 ashik.ali 152
});
153
 
23837 ashik.ali 154
function getDistance(lat1, lon1, lat2, lon2) {
24125 govind 155
	var deg2rad = 0.017453292519943295; // === Math.PI / 180
156
	var cos = Math.cos;
157
	lat1 *= deg2rad;
158
	lon1 *= deg2rad;
159
	lat2 *= deg2rad;
160
	lon2 *= deg2rad;
161
	var diam = 12742; // Diameter of the earth in km (2 * 6371)
162
	var dLat = lat2 - lat1;
163
	var dLon = lon2 - lon1;
164
	var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 165
 
24125 govind 166
	return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
167
}
23837 ashik.ali 168
 
24125 govind 169
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
170
	doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
171
			+ emailIdOrMobileNumber, function(response) {
23347 ashik.ali 172
		$('#' + domId).html(response);
27171 tejbeer 173
		if ($("#location").is(":checked")) {
174
 
24159 tejbeer 175
			$("#divLocation").show();
176
		}
23347 ashik.ali 177
	});
178
}
179
 
24125 govind 180
function updateRetailerDocument() {
181
	// $("#updateRetailerShopDocument0").click( function() {
23347 ashik.ali 182
	console.log("Update Retailer Document Clicked");
24125 govind 183
	// console.log(ownerId);
23347 ashik.ali 184
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
24125 govind 185
	console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
23347 ashik.ali 186
	var file = $('#retailerDocument')[0].files[0];
24125 govind 187
	console.log("file : " + file.name);
188
	uploadRetailerDocument("retailer-details-container", file,
189
			emailIdOrMobileNumber);
23347 ashik.ali 190
}
191
 
24125 govind 192
function updateRetailerShopDocument(ownerId) {
193
	// $("#updateRetailerShopDocument0").click( function() {
23347 ashik.ali 194
	console.log("Update Retailer Shop Document Clicked");
195
	console.log(ownerId);
196
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
24125 govind 197
	console.log("size : " + shopSize);
198
	for (var index = 0; index < shopSize; index++) {
199
		if ("updateRetailerShopDocument" + index == ownerId) {
200
			var emailIdOrMobileNumber = $('#retailer-details-search-text')
201
					.val();
202
			console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
203
			var shopId = $('#retailerShopDocument' + index).attr("shopId");
204
			console.log("shopId : " + shopId);
205
			var file = $('#retailerShopDocument' + index)[0].files[0];
206
			console.log("file : " + file.name);
207
			uploadRetailerShopDocument("retailer-details-container", file,
208
					emailIdOrMobileNumber, shopId);
23347 ashik.ali 209
		}
210
	}
211
}
212
 
24125 govind 213
function loadDistrictNames(stateName) {
214
	if (undefined != $("#districtName")) {
215
		doGetAjaxRequestHandler(
216
				context + "/district/all/stateName?stateName=" + stateName,
217
				function(response) {
218
					console.log(response);
219
					var districtMasters = response.response;
220
					// districtMasters = districtMasters.response;
221
					var districtNameElements = '<option value="" disabled selected>District Name</option>';
222
					for (index = 0; index < districtMasters.length; index++) {
223
						districtNameElements = districtNameElements
224
								+ '<option value="'
225
								+ districtMasters[index].name + '">'
226
								+ districtMasters[index].name + '</option>';
227
					}
228
					$('#districtName').html(districtNameElements);
229
				});
23347 ashik.ali 230
	}
231
}
232
 
24125 govind 233
function retailerInfo(domId) {
234
	doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {
235
		$('#' + domId).html(response);
24159 tejbeer 236
 
23349 ashik.ali 237
	});
24159 tejbeer 238
 
24125 govind 239
}
240
function storeInfo(domId) {
241
	doGetAjaxRequestHandler(context + "/getAllStores", function(response) {
242
		$('#' + domId).html(response);
243
	});
244
}
24680 govind 245
function inactiveStoreInfo(domId) {
27171 tejbeer 246
	doGetAjaxRequestHandler(context + "/getAllInactiveStores", function(
247
			response) {
24680 govind 248
		$('#' + domId).html(response);
249
	});
250
}
24125 govind 251
function deactivateStore(domId, fofoId) {
252
	doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
253
			function(response) {
254
				if (response == "true") {
255
					alert("successfully deactivated!");
256
					storeInfo(domId);
257
				}
24159 tejbeer 258
 
24125 govind 259
			});
260
}
24976 amit.gupta 261
function loginAsPartner(fofoId) {
27171 tejbeer 262
	doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
263
			function(response) {
264
				window.create({
265
					"url" : "/dashboard",
266
					"incognito" : true
267
				});
268
			});
24976 amit.gupta 269
}
24349 amit.gupta 270
function extendBilling(container, fofoId) {
271
	doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,
272
			function(response) {
27171 tejbeer 273
				if (isFinite(response)) {
274
					alert("successfully deactivated!");
275
					container.html("Billing extended upto "
276
							+ moment().add(1, 'day').format("DD-MM-YY")
277
							+ " Grace count(" + response + ")");
278
				}
279
			});
24349 amit.gupta 280
}
24159 tejbeer 281
 
282
function updateLocationButton(id) {
283
 
284
	var userId = id;
285
	var name = $('#personName').val();
286
	var line1 = $('#line1').val();
287
	var line2 = $('#line2').val();
288
	var city = $('#city').val();
289
	var state = $('#state').val();
290
	var pin = $('#pinCode').val();
291
	console.log(id);
292
	if (name === "" && line1 === "" && city === "" && pin === "") {
293
		alert("Field can't be empty");
294
		return;
295
	}
296
	if (name === "") {
297
		alert("name is required");
298
		return;
299
	}
300
	if (line1 === "") {
301
		alert("line1 is required");
302
		return;
303
	}
304
	if (city === "") {
305
		alert("city is required");
306
		return;
307
	}
308
	if (pin === "") {
309
		alert("pin is required");
310
		return;
311
	}
312
 
313
	var changeLocationData = {};
314
 
315
	changeLocationData['userId'] = id;
316
	changeLocationData['name'] = $('#personName').val();
317
	changeLocationData['line1'] = $('#line1').val();
318
	changeLocationData['line2'] = $('#line2').val();
319
	changeLocationData['city'] = $('#city').val();
320
	changeLocationData['state'] = $('#state').val();
321
	changeLocationData['pin'] = $('#pinCode').val();
322
 
323
	console.log(changeLocationData);
324
 
325
	if (confirm("Are you sure you want to add location!") == true) {
326
		doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
327
				.stringify(changeLocationData), function(response) {
328
			if (response == 'true') {
329
				alert("successfully Update");
330
 
331
				$("#addLocationModal").modal('hide');
332
 
333
			}
334
		});
335
 
336
		return false;
337
	}
338
 
339
}