Subversion Repositories SmartDukaan

Rev

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