Subversion Repositories SmartDukaan

Rev

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