Subversion Repositories SmartDukaan

Rev

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