Subversion Repositories SmartDukaan

Rev

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