Subversion Repositories SmartDukaan

Rev

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