Subversion Repositories SmartDukaan

Rev

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