Subversion Repositories SmartDukaan

Rev

Rev 27191 | Rev 27231 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23347 ashik.ali 1
$(function() {
24125 govind 2
 
3
	$("#retailer-details-search-button").live(
4
			'click',
5
			function() {
6
				searchContent = $("#retailer-details-search-text").val();
7
				if (typeof (searchContent) == "undefined" || !searchContent) {
8
					searchContent = "";
9
				}
10
				getRetailerDetailsByEmailIdOrMobileNumber(
11
						"retailer-details-container", searchContent);
12
			});
24159 tejbeer 13
 
24125 govind 14
	$(".active-store").live('click', function() {
15
		storeInfo("main-content");
16
	});
24680 govind 17
	$(".inactive-store").live('click', function() {
18
		inactiveStoreInfo("main-content");
19
	});
23347 ashik.ali 20
	$(".retailer-info").live('click', function() {
21
		retailerInfo("main-content");
22
	});
24125 govind 23
 
27171 tejbeer 24
	$("#retailerAddressPinCode").live(
25
			'change',
26
			function() {
27
 
28
				var pincode = $('#retailerAddressPinCode').val();
29
 
30
				if (undefined != pincode) {
31
					doGetAjaxRequestHandler(context + "/postOffice?pinCode="
32
							+ pincode,
33
							function(response) {
34
								console.log(response.response.state);
27202 tejbeer 35
								 $('#retailerAddressCity').find('option').not(':first').remove();
36
								 $('#retailerAddressState').val("");
27171 tejbeer 37
								$('#retailerAddressState').val(
38
										response.response.state);
27191 tejbeer 39
								loadDistrictNames(response.response.state);
27171 tejbeer 40
								for(let city of response.response.cities){
41
									    var opt = $("<option>").val(city).text(city);
42
				                        $('#retailerAddressCity').append(opt);
43
 
44
								}
45
 
46
							});
47
				}
48
			});
49
 
23347 ashik.ali 50
	$("#retailer-details-search-text").live("keyup", function(e) {
51
		var keyCode = e.keyCode || e.which;
24125 govind 52
		if (keyCode == 13) {
53
			$("#retailer-details-search-button").click();
54
		}
23347 ashik.ali 55
	});
24125 govind 56
 
57
	$(".deactivate-store").live('click', function() {
58
		var fofoId = $(this).data("fofoid");
59
		console.log(fofoId);
60
		if (confirm("Are you sure you want to deactivate store!") == true) {
61
			deactivateStore("main-content", fofoId);
62
		}
63
 
23347 ashik.ali 64
	});
24976 amit.gupta 65
	$(".login_as").live('click', function() {
25638 amit.gupta 66
		var fofoId = $('#partnerId').val();
24976 amit.gupta 67
		loginAsPartner(fofoId);
27171 tejbeer 68
 
24976 amit.gupta 69
	});
24125 govind 70
 
24349 amit.gupta 71
	$(".extend-billing").live('click', function() {
72
		var fofoId = $(this).data("fofoid");
73
		console.log(fofoId);
74
		if (confirm("Are you sure you want to extend Billing?")) {
75
			extendBilling($(this).parent(), fofoId);
76
		}
77
 
24125 govind 78
	});
27191 tejbeer 79
 
27171 tejbeer 80
	/*
81
	 * $('#retailerAddressState').live('change', function() { var stateName =
27191 tejbeer 82
	 * $(this).find('option:selected').text();
27171 tejbeer 83
	 * 
27191 tejbeer 84
	 * loadDistrictNames(stateName); });
27171 tejbeer 85
	 */
27191 tejbeer 86
 
24159 tejbeer 87
 
27171 tejbeer 88
	$("#location").live('click', function() {
89
		if ($(this).is(":checked")) {
24159 tejbeer 90
 
27171 tejbeer 91
			$("#divLocation").show();
24159 tejbeer 92
 
27171 tejbeer 93
		} else {
94
			$("#divLocation").hide();
95
		}
96
	});
97
 
24159 tejbeer 98
	$(".addlocationbutton").live(
99
			'click',
100
			function() {
101
				var userId = $('#retailerId').text();
102
				var name = $('#personName').val();
103
				var line1 = $('#line1').val();
104
				var line2 = $('#line2').val();
105
				var city = $('#city').val();
106
				var state = $('#state').val();
107
				var pin = $('#pinCode').val();
108
 
109
				if (name === "" && line1 === "" && city === "" && pin === "") {
110
					alert("Field can't be empty");
111
					return;
112
				}
113
				if (name === "") {
114
					alert("name is required");
115
					return;
116
				}
117
				if (line1 === "") {
118
					alert("line1 is required");
119
					return;
120
				}
121
				if (city === "") {
122
					alert("city is required");
123
					return;
124
				}
125
				if (pin === "") {
126
					alert("pin is required");
127
					return;
128
				}
129
 
130
				var locationData = {};
131
				locationData['userId'] = $('#retailerId').text();
132
				locationData['name'] = $('#personName').val();
133
				locationData['line1'] = $('#line1').val();
134
				locationData['line2'] = $('#line2').val();
135
				locationData['city'] = $('#city').val();
136
				locationData['state'] = $('#state').val();
137
				locationData['pin'] = $('#pinCode').val();
138
 
139
				if (confirm("Are you sure you want to add location!") == true) {
140
					doPostAjaxRequestWithJsonHandler(context + "/addLocation",
141
							JSON.stringify(locationData), function(response) {
142
								if (response == 'true') {
143
									alert("successfully Add");
144
									$("#addLocationModal").modal('hide');
145
 
146
								}
147
							});
148
 
149
					return false;
150
				}
151
			});
152
 
23347 ashik.ali 153
});
154
 
23837 ashik.ali 155
function getDistance(lat1, lon1, lat2, lon2) {
24125 govind 156
	var deg2rad = 0.017453292519943295; // === Math.PI / 180
157
	var cos = Math.cos;
158
	lat1 *= deg2rad;
159
	lon1 *= deg2rad;
160
	lat2 *= deg2rad;
161
	lon2 *= deg2rad;
162
	var diam = 12742; // Diameter of the earth in km (2 * 6371)
163
	var dLat = lat2 - lat1;
164
	var dLon = lon2 - lon1;
165
	var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 166
 
24125 govind 167
	return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
168
}
23837 ashik.ali 169
 
24125 govind 170
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
171
	doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
172
			+ emailIdOrMobileNumber, function(response) {
23347 ashik.ali 173
		$('#' + domId).html(response);
27171 tejbeer 174
		if ($("#location").is(":checked")) {
175
 
24159 tejbeer 176
			$("#divLocation").show();
177
		}
23347 ashik.ali 178
	});
179
}
180
 
24125 govind 181
function updateRetailerDocument() {
182
	// $("#updateRetailerShopDocument0").click( function() {
23347 ashik.ali 183
	console.log("Update Retailer Document Clicked");
24125 govind 184
	// console.log(ownerId);
23347 ashik.ali 185
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
24125 govind 186
	console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
23347 ashik.ali 187
	var file = $('#retailerDocument')[0].files[0];
24125 govind 188
	console.log("file : " + file.name);
189
	uploadRetailerDocument("retailer-details-container", file,
190
			emailIdOrMobileNumber);
23347 ashik.ali 191
}
192
 
24125 govind 193
function updateRetailerShopDocument(ownerId) {
194
	// $("#updateRetailerShopDocument0").click( function() {
23347 ashik.ali 195
	console.log("Update Retailer Shop Document Clicked");
196
	console.log(ownerId);
197
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
24125 govind 198
	console.log("size : " + shopSize);
199
	for (var index = 0; index < shopSize; index++) {
200
		if ("updateRetailerShopDocument" + index == ownerId) {
201
			var emailIdOrMobileNumber = $('#retailer-details-search-text')
202
					.val();
203
			console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
204
			var shopId = $('#retailerShopDocument' + index).attr("shopId");
205
			console.log("shopId : " + shopId);
206
			var file = $('#retailerShopDocument' + index)[0].files[0];
207
			console.log("file : " + file.name);
208
			uploadRetailerShopDocument("retailer-details-container", file,
209
					emailIdOrMobileNumber, shopId);
23347 ashik.ali 210
		}
211
	}
212
}
213
 
24125 govind 214
function loadDistrictNames(stateName) {
215
	if (undefined != $("#districtName")) {
216
		doGetAjaxRequestHandler(
217
				context + "/district/all/stateName?stateName=" + stateName,
218
				function(response) {
219
					console.log(response);
220
					var districtMasters = response.response;
221
					// districtMasters = districtMasters.response;
222
					var districtNameElements = '<option value="" disabled selected>District Name</option>';
223
					for (index = 0; index < districtMasters.length; index++) {
224
						districtNameElements = districtNameElements
225
								+ '<option value="'
226
								+ districtMasters[index].name + '">'
227
								+ districtMasters[index].name + '</option>';
228
					}
229
					$('#districtName').html(districtNameElements);
230
				});
23347 ashik.ali 231
	}
232
}
233
 
24125 govind 234
function retailerInfo(domId) {
235
	doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {
236
		$('#' + domId).html(response);
24159 tejbeer 237
 
23349 ashik.ali 238
	});
24159 tejbeer 239
 
24125 govind 240
}
241
function storeInfo(domId) {
242
	doGetAjaxRequestHandler(context + "/getAllStores", function(response) {
243
		$('#' + domId).html(response);
244
	});
245
}
24680 govind 246
function inactiveStoreInfo(domId) {
27171 tejbeer 247
	doGetAjaxRequestHandler(context + "/getAllInactiveStores", function(
248
			response) {
24680 govind 249
		$('#' + domId).html(response);
250
	});
251
}
24125 govind 252
function deactivateStore(domId, fofoId) {
253
	doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
254
			function(response) {
255
				if (response == "true") {
256
					alert("successfully deactivated!");
257
					storeInfo(domId);
258
				}
24159 tejbeer 259
 
24125 govind 260
			});
261
}
24976 amit.gupta 262
function loginAsPartner(fofoId) {
27171 tejbeer 263
	doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
264
			function(response) {
265
				window.create({
266
					"url" : "/dashboard",
267
					"incognito" : true
268
				});
269
			});
24976 amit.gupta 270
}
24349 amit.gupta 271
function extendBilling(container, fofoId) {
272
	doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,
273
			function(response) {
27171 tejbeer 274
				if (isFinite(response)) {
275
					alert("successfully deactivated!");
276
					container.html("Billing extended upto "
277
							+ moment().add(1, 'day').format("DD-MM-YY")
278
							+ " Grace count(" + response + ")");
279
				}
280
			});
24349 amit.gupta 281
}
24159 tejbeer 282
 
283
function updateLocationButton(id) {
284
 
285
	var userId = id;
286
	var name = $('#personName').val();
287
	var line1 = $('#line1').val();
288
	var line2 = $('#line2').val();
289
	var city = $('#city').val();
290
	var state = $('#state').val();
291
	var pin = $('#pinCode').val();
292
	console.log(id);
293
	if (name === "" && line1 === "" && city === "" && pin === "") {
294
		alert("Field can't be empty");
295
		return;
296
	}
297
	if (name === "") {
298
		alert("name is required");
299
		return;
300
	}
301
	if (line1 === "") {
302
		alert("line1 is required");
303
		return;
304
	}
305
	if (city === "") {
306
		alert("city is required");
307
		return;
308
	}
309
	if (pin === "") {
310
		alert("pin is required");
311
		return;
312
	}
313
 
314
	var changeLocationData = {};
315
 
316
	changeLocationData['userId'] = id;
317
	changeLocationData['name'] = $('#personName').val();
318
	changeLocationData['line1'] = $('#line1').val();
319
	changeLocationData['line2'] = $('#line2').val();
320
	changeLocationData['city'] = $('#city').val();
321
	changeLocationData['state'] = $('#state').val();
322
	changeLocationData['pin'] = $('#pinCode').val();
323
 
324
	console.log(changeLocationData);
325
 
326
	if (confirm("Are you sure you want to add location!") == true) {
327
		doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
328
				.stringify(changeLocationData), function(response) {
329
			if (response == 'true') {
330
				alert("successfully Update");
331
 
332
				$("#addLocationModal").modal('hide');
333
 
334
			}
335
		});
336
 
337
		return false;
338
	}
339
 
340
}