Subversion Repositories SmartDukaan

Rev

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