Subversion Repositories SmartDukaan

Rev

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