Subversion Repositories SmartDukaan

Rev

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