Subversion Repositories SmartDukaan

Rev

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

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