Subversion Repositories SmartDukaan

Rev

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