Subversion Repositories SmartDukaan

Rev

Rev 24440 | Rev 24649 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24440 Rev 24595
Line 1... Line 1...
1
var logosmapping = {
1
var logosmapping = {
2
		mobile_insurance_providers  : 
2
	mobile_insurance_providers : {
3
		{
-
 
4
			"0" :  context+'/resources/images/icons/provider-logos/iffco.png',
3
		"0" : context + '/resources/images/icons/provider-logos/iffco.png',
5
			"1" : context + '/resources/images/icons/provider-logos/icici.jpg',
4
		"1" : context + '/resources/images/icons/provider-logos/icici.jpg',
6
			"2" : context + '/resources/images/icons/provider-logos/tataaig.png'
5
		"2" : context + '/resources/images/icons/provider-logos/tataaig.png'
7
		}
6
	}
8
}
7
}
9
function badRequestAlert(response){
8
function badRequestAlert(response) {
10
	console.log(response.responseText);
9
	console.log(response.responseText);
11
	var errorObject = JSON.parse(response.responseText);
10
	var errorObject = JSON.parse(response.responseText);
12
	errorObject = errorObject.response;
11
	errorObject = errorObject.response;
13
	bootbox.alert('Bad Request\n'+
12
	bootbox.alert('Bad Request\n' + 'rejectedType : '
14
			'rejectedType : '+errorObject.rejectedType+'\n'+
13
			+ errorObject.rejectedType + '\n' + 'rejectedValue : '
15
			'rejectedValue : '+errorObject.rejectedValue+'\n'+
14
			+ errorObject.rejectedValue + '\n' + 'message : '
16
			'message : '+errorObject.message);
15
			+ errorObject.message);
17
}
16
}
18
	
17
 
19
function internalServerErrorAlert(response){
18
function internalServerErrorAlert(response) {
20
	console.log(response.responseText);
19
	console.log(response.responseText);
21
	var errorObject = JSON.parse(response.responseText);
20
	var errorObject = JSON.parse(response.responseText);
22
	errorObject = errorObject.response;
21
	errorObject = errorObject.response;
23
	bootbox.alert('Internal Server Error\n'+
22
	bootbox.alert('Internal Server Error\n' + 'rejectedType : '
24
		'rejectedType : '+errorObject.rejectedType+'\n'+
23
			+ errorObject.rejectedType + '\n' + 'rejectedValue : '
25
		'rejectedValue : '+errorObject.rejectedValue+'\n'+
24
			+ errorObject.rejectedValue + '\n' + 'message : '
26
		'message : '+errorObject.message);
25
			+ errorObject.message);
27
}
26
}
28
 
27
 
29
$( document ).ajaxError(function(event, jqxhr, settings, thrownError) {
28
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
30
	if(typeof loaderDialogObj!="undefined")
29
	if (typeof loaderDialogObj != "undefined")
31
		loaderDialogObj.modal('hide');
30
		loaderDialogObj.modal('hide');
32
	if(jqxhr.status == 400){
31
	if (jqxhr.status == 400) {
33
		// $('#error-prompt-model').modal();
32
		// $('#error-prompt-model').modal();
34
		badRequestAlert(jqxhr);	
33
		badRequestAlert(jqxhr);
35
	}else{
34
	} else {
36
		internalServerErrorAlert(jqxhr);
35
		internalServerErrorAlert(jqxhr);
37
	}
36
	}
38
});
37
});
39
 
38
 
40
$(document).ajaxComplete(function(){
39
$(document).ajaxComplete(function() {
41
	if(typeof loaderDialogObj!="undefined")
40
	if (typeof loaderDialogObj != "undefined")
42
		loaderDialogObj.modal('hide');
41
		loaderDialogObj.modal('hide');
43
});
42
});
44
 
43
 
-
 
44
$(document)
-
 
45
		.ajaxStart(
45
$( document ).ajaxStart(function() {
46
				function() {
46
		if(typeof loaderDialogObj!="undefined")
47
					if (typeof loaderDialogObj != "undefined")
47
			loaderDialogObj.modal('show');
48
						loaderDialogObj.modal('show');
48
		if(typeof isInvestmentOk != "undefined" && !isInvestmentOk && $('#order-details').length == 0) {
49
					if (typeof isInvestmentOk != "undefined" && !isInvestmentOk
-
 
50
							&& $('#order-details').length == 0) {
49
			var investmentDialog = bootbox.dialog({
51
						var investmentDialog = bootbox
-
 
52
								.dialog({
50
				title: '<h3	class="text-danger">ATTENTION!! ORDERING THROUGH APP MAY BE BLOCKED DUE TO LOW INVESTMENTS!</h3>',
53
									title : '<h3	class="text-danger">ATTENTION!! ORDERING THROUGH APP MAY BE BLOCKED DUE TO LOW INVESTMENTS!</h3>',
51
				message : "<h3>Dear Partner, your investments are low by " + shortPercentage + "%</h3>"
54
									message : "<h3>Dear Partner, your investments are low by "
-
 
55
											+ shortPercentage
-
 
56
											+ "%</h3>"
52
					+  "<dl>"
57
											+ "<dl>"
53
					+  "<dt>Investment Should be</dt><dd>- " + minimumInvestmentAmount +"</dd>"
58
											+ "<dt>Investment Should be</dt><dd>- "
-
 
59
											+ minimumInvestmentAmount
-
 
60
											+ "</dd>"
54
					+ "<dt>Total Invested Amount</dt><dd>-" + totalInvestedAmount +"</dd>"
61
											+ "<dt>Total Invested Amount</dt><dd>-"
-
 
62
											+ totalInvestedAmount
-
 
63
											+ "</dd>"
55
					+  '<dt>Investment Amount Short By</dt><dd class="text-danger lead">-  ' + shortAmount+'</dd></dl>'
64
											+ '<dt>Investment Amount Short By</dt><dd class="text-danger lead">-  '
-
 
65
											+ shortAmount
-
 
66
											+ '</dd></dl>'
56
			 		+ '<pre class="text-danger" style="font-size:18px;"><strong>To unblock your Billing, please \nadd Rs.'+ minAmountToBeAdded + ' to wallet immediately.</strong></pre>',
67
											+ '<pre class="text-danger" style="font-size:18px;"><strong>To unblock your Billing, please \nadd Rs.'
-
 
68
											+ minAmountToBeAdded
-
 
69
											+ ' to wallet immediately.</strong></pre>',
57
			 	buttons:{
70
									buttons : {
58
			 			cancel: {
71
										cancel : {
59
			 				label: "OK",
72
											label : "OK",
60
			 		        className: 'btn-primary'
73
											className : 'btn-primary'
61
			 			}
74
										}
62
			 		},
75
									},
63
			});
76
								});
64
			investmentDialog.on('shown.bs.modal', function(){
77
						investmentDialog.on('shown.bs.modal',
-
 
78
								function() {
-
 
79
									var dialogEl = investmentDialog
65
				var dialogEl = investmentDialog.find('.modal-content')[0];
80
											.find('.modal-content')[0];
-
 
81
									var dialogRect = dialogEl
66
				var dialogRect = dialogEl.getBoundingClientRect();
82
											.getBoundingClientRect();
67
				var height = window.innerHeight - dialogRect.height;
83
									var height = window.innerHeight
-
 
84
											- dialogRect.height;
68
				var width = window.innerWidth - dialogRect.width;
85
									var width = window.innerWidth
-
 
86
											- dialogRect.width;
-
 
87
									var left = Math
69
				var left = Math.floor(Math.random()*width) - dialogRect.left
88
											.floor(Math.random() * width)
-
 
89
											- dialogRect.left
-
 
90
									var top = Math
70
				var top = Math.floor(Math.random()*height) - dialogRect.top
91
											.floor(Math.random() * height)
-
 
92
											- dialogRect.top
71
				$(dialogEl).css("left",left).css("top",top);
93
									$(dialogEl).css("left", left).css("top",
-
 
94
											top);
72
			});
95
								});
73
		}
96
					}
74
	});
97
				});
75
 
-
 
76
 
-
 
77
 
98
 
78
function doAjaxRequestWithParamsHandler(urlString, httpType, params, callback_function){
99
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
-
 
100
		callback_function) {
79
	$.ajax({
101
	$.ajax({
80
	   url: urlString,
102
		url : urlString,
81
	   async: true,
103
		async : true,
82
	   cache: false,
104
		cache : false,
83
	   data: params,
105
		data : params,
84
       // dataType:'json',
106
		// dataType:'json',
85
	   type: httpType,
107
		type : httpType,
86
	   success: function(response) {
108
		success : function(response) {
87
	      callback_function(response);
109
			callback_function(response);
88
	      $('.currency').each(function(index,ele){
110
			$('.currency').each(function(index, ele) {
89
	    	  if(!isNaN(parseInt($(ele).html()))) {
111
				if (!isNaN(parseInt($(ele).html()))) {
90
	    		  $(ele).html(numberToComma($(ele).html()));  
112
					$(ele).html(numberToComma($(ele).html()));
91
	    	  }
113
				}
92
	      });
114
			});
93
	   }
115
		}
94
	});
116
	});
95
}
117
}
96
 
118
 
97
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function){
119
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
98
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
120
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
99
}
121
}
100
 
122
 
101
function doPostAjaxRequestWithParamsHandler(urlString, params, callback_function){
123
function doPostAjaxRequestWithParamsHandler(urlString, params,
-
 
124
		callback_function) {
102
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
125
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
103
}
126
}
104
 
127
 
105
function doAjaxRequestWithJsonHandler(urlString, httpType, json, callback_function){
128
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
-
 
129
		callback_function) {
106
	$.ajax({
130
	$.ajax({
107
	   url: urlString,
131
		url : urlString,
108
	   async: true,
132
		async : true,
109
	   cache: false,
133
		cache : false,
110
	   processData: false,
134
		processData : false,
111
	   data: json,
135
		data : json,
112
       contentType:'application/json',
136
		contentType : 'application/json',
113
	   type: httpType,
137
		type : httpType,
114
	   success: function(response) {
138
		success : function(response) {
115
	      // console.log("response"+JSON.stringify(data));
139
			// console.log("response"+JSON.stringify(data));
116
	      callback_function(response);
140
			callback_function(response);
117
	      $('.currency').each(function(index,ele){
141
			$('.currency').each(function(index, ele) {
118
	    	  if(!isNaN(parseInt($(ele).html()))) {
142
				if (!isNaN(parseInt($(ele).html()))) {
119
	    		  $(ele).html(numberToComma($(ele).html()));  
143
					$(ele).html(numberToComma($(ele).html()));
120
	    	  }
144
				}
121
	      });
145
			});
122
	   }
146
		}
123
	});
147
	});
124
}
148
}
125
 
149
 
126
function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function){
150
function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function) {
127
	doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);
151
	doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);
128
}
152
}
129
 
153
 
130
function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function){
154
function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function) {
131
	doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);
155
	doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);
132
}
156
}
133
 
157
 
134
function doAjaxRequestHandler(urlString, httpType, callback_function){
158
function doAjaxRequestHandler(urlString, httpType, callback_function) {
135
	$.ajax({
159
	$.ajax({
136
	   url: urlString,
160
		url : urlString,
137
	   async: true,
161
		async : true,
138
	   cache: false,
162
		cache : false,
139
	   type: httpType,
163
		type : httpType,
140
	   success: function(response) {
164
		success : function(response) {
141
	      callback_function(response);
165
			callback_function(response);
142
	      $('.currency').each(function(index,ele){
166
			$('.currency').each(function(index, ele) {
143
	    	  if(!isNaN(parseInt($(ele).html()))) {
167
				if (!isNaN(parseInt($(ele).html()))) {
144
	    		  $(ele).html(numberToComma($(ele).html()));  
168
					$(ele).html(numberToComma($(ele).html()));
145
	    	  }
169
				}
146
	      });
170
			});
147
	   }
171
		}
148
	});
172
	});
149
}
173
}
150
 
174
 
151
function doGetAjaxRequestHandler(urlString, callback_function){
175
function doGetAjaxRequestHandler(urlString, callback_function) {
152
	doAjaxRequestHandler(urlString, "GET", callback_function);
176
	doAjaxRequestHandler(urlString, "GET", callback_function);
153
}
177
}
154
 
178
 
155
function doPutAjaxRequestHandler(urlString, callback_function){
179
function doPutAjaxRequestHandler(urlString, callback_function) {
156
	doAjaxRequestHandler(urlString, "PUT", callback_function);
180
	doAjaxRequestHandler(urlString, "PUT", callback_function);
157
}
181
}
158
 
182
 
159
function doPostAjaxRequestHandler(urlString, callback_function){
183
function doPostAjaxRequestHandler(urlString, callback_function) {
160
	doAjaxRequestHandler(urlString, "POST", callback_function);
184
	doAjaxRequestHandler(urlString, "POST", callback_function);
161
}
185
}
162
 
186
 
163
function doDeleteAjaxRequestHandler(urlString, callback_function){
187
function doDeleteAjaxRequestHandler(urlString, callback_function) {
164
	doAjaxRequestHandler(urlString, "DELETE", callback_function);
188
	doAjaxRequestHandler(urlString, "DELETE", callback_function);
165
}
189
}
166
 
190
 
167
function doAjaxUploadRequest(urlString, httpType, file){
191
function doAjaxUploadRequest(urlString, httpType, file) {
168
	var response;
192
	var response;
169
	doAjaxUploadRequestHandler(urlString, httpType, file, function(ajaxResponse){
193
	doAjaxUploadRequestHandler(urlString, httpType, file,
-
 
194
			function(ajaxResponse) {
170
		response = ajaxResponse;
195
				response = ajaxResponse;
171
	});
196
			});
172
	return response;
197
	return response;
173
}
198
}
174
 
199
 
175
function doAjaxUploadRequestHandler(urlString, httpType, file, callback_function){
200
function doAjaxUploadRequestHandler(urlString, httpType, file,
-
 
201
		callback_function) {
176
	var formData = new FormData();
202
	var formData = new FormData();
177
	formData.append("file", file);
203
	formData.append("file", file);
178
	$.ajax({
204
	$.ajax({
179
	   url: urlString,
205
		url : urlString,
180
	   type: httpType,
206
		type : httpType,
181
	   data: formData,
207
		data : formData,
182
       dataType: 'json',
208
		dataType : 'json',
183
       async: true,
209
		async : true,
184
       cache: false,
210
		cache : false,
185
       contentType: false,
211
		contentType : false,
186
       enctype: 'multipart/form-data',
212
		enctype : 'multipart/form-data',
187
       processData: false,
213
		processData : false,
188
	   success: function(response) {
214
		success : function(response) {
189
	      // console.log("response"+JSON.stringify(data));
215
			// console.log("response"+JSON.stringify(data));
190
	      callback_function(response);
216
			callback_function(response);
191
	   }
217
		}
192
	});
218
	});
193
}
219
}
194
function doAjaxUploadRequestJsonHandler(urlString, httpType, file,json,callback_function){
220
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
-
 
221
		callback_function) {
195
	var formData = new FormData();
222
	var formData = new FormData();
196
	formData.append("file", file);
223
	formData.append("file", file);
197
	formData.append('json',new Blob([json]));
224
	formData.append('json', new Blob([ json ]));
198
	$.ajax({
225
	$.ajax({
199
	   url: urlString,
226
		url : urlString,
200
	   type: httpType,
227
		type : httpType,
201
	   data: formData,
228
		data : formData,
202
	   enctype: 'multipart/form-data',
229
		enctype : 'multipart/form-data',
203
       contentType: false,
230
		contentType : false,
204
       processData: false,
231
		processData : false,
205
	   success: function(response) {
232
		success : function(response) {
206
	      // console.log("response"+JSON.stringify(data));
233
			// console.log("response"+JSON.stringify(data));
207
	      callback_function(response);
234
			callback_function(response);
208
	   }
235
		}
209
	});
236
	});
210
}
237
}
211
 
238
 
212
function uploadDocument(file){
239
function uploadDocument(file) {
213
	var url = webApiScheme + '://'+ webApiHost + ':' + webApiPort +  webApiRoot + '/document-upload';
240
	var url = webApiScheme + '://' + webApiHost + ':' + webApiPort + webApiRoot
-
 
241
			+ '/document-upload';
214
	doAjaxUploadRequestHandler(url, 'POST', file, function(response){
242
	doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
215
		var documentId = response.response.document_id; 
243
		var documentId = response.response.document_id;
216
		console.log("documentId : "+documentId);
244
		console.log("documentId : " + documentId);
217
		return documentId;
245
		return documentId;
218
	});
246
	});
219
}
247
}
220
 
248
 
221
function doAjaxGetDownload(urlString, fileName){
249
function doAjaxGetDownload(urlString, fileName) {
222
	console.log("fileName : "+fileName);
250
	console.log("fileName : " + fileName);
223
	doAjaxDownload(urlString, "GET", null, fileName);
251
	doAjaxDownload(urlString, "GET", null, fileName);
224
}
252
}
225
 
253
 
226
function doAjaxPostDownload(urlString, data, fileName){
254
function doAjaxPostDownload(urlString, data, fileName) {
227
	doAjaxDownload(urlString, "POST", data, fileName);
255
	doAjaxDownload(urlString, "POST", data, fileName);
228
}
256
}
229
 
257
 
230
function doAjaxDownload(urlString, httpType, data, fileName){
258
function doAjaxDownload(urlString, httpType, data, fileName) {
231
	xhttp = new XMLHttpRequest();
259
	xhttp = new XMLHttpRequest();
232
	xhttp.onreadystatechange = function() {
260
	xhttp.onreadystatechange = function() {
233
	    var a;
261
		var a;
234
	    if(xhttp.readyState === 2){
262
		if (xhttp.readyState === 2) {
235
	    	if(xhttp.status == 200){
263
			if (xhttp.status == 200) {
236
	    		xhttp.responseType = "blob";
264
				xhttp.responseType = "blob";
237
            } else {
265
			} else {
238
                xhttp.responseType = "text";
266
				xhttp.responseType = "text";
239
            }
267
			}
240
	    }else if (xhttp.readyState === 4 && xhttp.status === 200) {
268
		} else if (xhttp.readyState === 4 && xhttp.status === 200) {
241
	        // Trick for making downloadable link
269
			// Trick for making downloadable link
242
	        a = document.createElement('a');
270
			a = document.createElement('a');
243
	        a.href = window.URL.createObjectURL(xhttp.response);
271
			a.href = window.URL.createObjectURL(xhttp.response);
244
	        // Give filename you wish to download
272
			// Give filename you wish to download
245
	        a.download = fileName;
273
			a.download = fileName;
246
	        a.style.display = 'none';
274
			a.style.display = 'none';
247
	        document.body.appendChild(a);
275
			document.body.appendChild(a);
248
	        a.click();
276
			a.click();
249
	    }else if(xhttp.readyState == 4 && xhttp.status === 400){
277
		} else if (xhttp.readyState == 4 && xhttp.status === 400) {
250
    		badRequestAlert(xhttp);
278
			badRequestAlert(xhttp);
251
	    }else if(xhttp.readyState == 4 && xhttp.status === 500){
279
		} else if (xhttp.readyState == 4 && xhttp.status === 500) {
252
	    	internalServerErrorAlert(xhttp);
280
			internalServerErrorAlert(xhttp);
253
	    }
281
		}
254
	};
282
	};
255
	// Post data to URL which handles post request
283
	// Post data to URL which handles post request
256
	xhttp.open(httpType, urlString);
284
	xhttp.open(httpType, urlString);
257
	if(httpType == "POST"){
285
	if (httpType == "POST") {
258
		xhttp.setRequestHeader("Content-Type", "application/json");
286
		xhttp.setRequestHeader("Content-Type", "application/json");
259
	}
287
	}
260
	// You should set responseType as blob for binary responses
288
	// You should set responseType as blob for binary responses
261
	// xhttp.responseType = 'blob';
289
	// xhttp.responseType = 'blob';
262
	xhttp.send(data);
290
	xhttp.send(data);
263
}
291
}
264
 
292
 
265
function loadPaginatedNextItems(url, params, paginatedIdentifier, tableIdentifier, detailsContainerIdentifier){
293
function loadPaginatedNextItems(url, params, paginatedIdentifier,
-
 
294
		tableIdentifier, detailsContainerIdentifier) {
266
	var start = $("#"+paginatedIdentifier+" .start").text();
295
	var start = $("#" + paginatedIdentifier + " .start").text();
267
	var end = $("#"+paginatedIdentifier+" .end").text();
296
	var end = $("#" + paginatedIdentifier + " .end").text();
268
	url = context + url + "?offset=" + end;
297
	url = context + url + "?offset=" + end;
269
	
298
 
270
	if(params != null){
299
	if (params != null) {
271
		for (var key in params) {
300
		for ( var key in params) {
272
			if (params.hasOwnProperty(key)) {
301
			if (params.hasOwnProperty(key)) {
273
				// console.log(key + " -> " + p[key]);
302
				// console.log(key + " -> " + p[key]);
274
				url = url +"&" + key + "=" + params[key];
303
				url = url + "&" + key + "=" + params[key];
275
			}
304
			}
276
		}
305
		}
277
	}
306
	}
278
	
307
 
279
	doGetAjaxRequestHandler(url, function(response){
308
	doGetAjaxRequestHandler(url, function(response) {
280
		var size = $("#"+paginatedIdentifier+" .size").text();
309
		var size = $("#" + paginatedIdentifier + " .size").text();
281
		if((parseInt(end) + 10) > parseInt(size)){
310
		if ((parseInt(end) + 10) > parseInt(size)) {
282
			console.log("(end + 10) > size == true");
311
			console.log("(end + 10) > size == true");
283
			$("#"+paginatedIdentifier+" .end").text(size);
312
			$("#" + paginatedIdentifier + " .end").text(size);
284
		}else{
313
		} else {
285
			console.log("(end + 10) > size == false");
314
			console.log("(end + 10) > size == false");
286
			$("#"+paginatedIdentifier+" .end").text(+end + +10);
315
			$("#" + paginatedIdentifier + " .end").text(+end + +10);
287
		}
316
		}
288
		$("#"+paginatedIdentifier+" .start").text(+start + +10);
317
		$("#" + paginatedIdentifier + " .start").text(+start + +10);
289
		var last = $("#"+paginatedIdentifier+" .end").text();
318
		var last = $("#" + paginatedIdentifier + " .end").text();
290
		var temp = $("#"+paginatedIdentifier+" .size").text();
319
		var temp = $("#" + paginatedIdentifier + " .size").text();
291
		if (parseInt(last) >= parseInt(temp)){
320
		if (parseInt(last) >= parseInt(temp)) {
292
			$("#"+paginatedIdentifier+" .next").prop('disabled', true);
321
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
293
			// $( "#good-inventory-paginated .end" ).text(temp);
322
			// $( "#good-inventory-paginated .end" ).text(temp);
294
		}
323
		}
295
	    $('#'+tableIdentifier).html(response);
324
		$('#' + tableIdentifier).html(response);
296
	    if(detailsContainerIdentifier != null){
325
		if (detailsContainerIdentifier != null) {
297
			$('#'+detailsContainerIdentifier).html('');
326
			$('#' + detailsContainerIdentifier).html('');
298
		}
327
		}
299
	    $("#"+paginatedIdentifier+" .previous").prop('disabled', false);
328
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
300
	});
329
	});
301
    
-
 
302
}
-
 
303
 
330
 
-
 
331
}
304
 
332
 
305
function loadPaginatedPreviousItems(url, params, paginatedIdentifier, tableIdentifier, detailsContainerIdentifier){
333
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
-
 
334
		tableIdentifier, detailsContainerIdentifier) {
306
	var start = $("#"+paginatedIdentifier+" .start").text();
335
	var start = $("#" + paginatedIdentifier + " .start").text();
307
	var end =  $("#"+paginatedIdentifier+" .end").text();
336
	var end = $("#" + paginatedIdentifier + " .end").text();
308
	var size = $("#"+paginatedIdentifier+" .size").text();
337
	var size = $("#" + paginatedIdentifier + " .size").text();
309
	if(parseInt(end) == parseInt(size) && parseInt(end)%10 !=0){
338
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
310
		var mod = parseInt(end) % 10;
339
		var mod = parseInt(end) % 10;
311
		end = parseInt(end) + (10 - mod); 
340
		end = parseInt(end) + (10 - mod);
312
	}
341
	}
313
	var pre = end - 20;
342
	var pre = end - 20;
314
	
343
 
315
	url = context + url + "?offset=" + pre;
344
	url = context + url + "?offset=" + pre;
316
	
345
 
317
	if(params != null){
346
	if (params != null) {
318
		for (var key in params) {
347
		for ( var key in params) {
319
			if (params.hasOwnProperty(key)) {
348
			if (params.hasOwnProperty(key)) {
320
				url = url +"&" + key + "=" + params[key];
349
				url = url + "&" + key + "=" + params[key];
321
			}
350
			}
322
		}
351
		}
323
	}
352
	}
324
	
353
 
325
	doGetAjaxRequestHandler(url, function(response){
354
	doGetAjaxRequestHandler(url, function(response) {
326
		$("#"+paginatedIdentifier+" .end").text(+end - +10);
355
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
327
		$("#"+paginatedIdentifier+" .start").text(+start - +10);
356
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
328
		$('#'+tableIdentifier).html(response);
357
		$('#' + tableIdentifier).html(response);
329
		if(detailsContainerIdentifier != null){
358
		if (detailsContainerIdentifier != null) {
330
			$('#'+detailsContainerIdentifier).html('');
359
			$('#' + detailsContainerIdentifier).html('');
331
		}
-
 
332
		$("#"+paginatedIdentifier+" .next").prop('disabled', false);
-
 
333
		if (parseInt(pre)==0){
-
 
334
			$("#"+paginatedIdentifier+" .previous").prop('disabled', true);
-
 
335
		}
360
		}
-
 
361
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
336
	});	
362
		if (parseInt(pre) == 0) {
-
 
363
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
337
	
364
		}
338
}
365
	});
339
 
366
 
-
 
367
}
340
 
368
 
341
function numberToComma(x) {
369
function numberToComma(x) {
342
	x=parseInt(x);
370
	x = parseInt(x);
343
	x=x.toString();
371
	x = x.toString();
344
	var lastThree = x.substring(x.length-3);
372
	var lastThree = x.substring(x.length - 3);
345
	var otherNumbers = x.substring(0,x.length-3);
373
	var otherNumbers = x.substring(0, x.length - 3);
346
	if(otherNumbers != '')
374
	if (otherNumbers != '')
347
	    lastThree = ',' + lastThree;
375
		lastThree = ',' + lastThree;
348
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
376
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
349
}
377
}
350
 
378
 
351
function dateRangeCallback(start, end) {
379
function dateRangeCallback(start, end) {
352
	startMoment = start;
380
	startMoment = start;
353
	endMoment = end;
381
	endMoment = end;
354
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
382
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
355
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
383
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
356
}
384
}
357
 
385
 
358
function getSingleDatePicker(){
386
function getSingleDatePicker() {
359
	var singleDatePicker =  
387
	var singleDatePicker = {
360
	{ 
-
 
361
		"todayHighlight": true, 
388
		"todayHighlight" : true,
362
		"startDate": startMoment || moment(),
389
		"startDate" : startMoment || moment(),
363
		"autoclose": true,
390
		"autoclose" : true,
364
		"autoUpdateInput": true,
391
		"autoUpdateInput" : true,
365
		"singleDatePicker": true,
392
		"singleDatePicker" : true,
366
    "locale": {
393
		"locale" : {
367
		'format': 'DD/MM/YYYY'
394
			'format' : 'DD/MM/YYYY'
368
	}
395
		}
369
  };
396
	};
370
	return singleDatePicker;
397
	return singleDatePicker;
371
}
398
}
372
 
399
 
373
function getRangedDatePicker(showRanges){
400
function getRangedDatePicker(showRanges) {
374
	if(typeof showRanges=="undefined") {
401
	if (typeof showRanges == "undefined") {
375
		showRanges = false;
402
		showRanges = false;
376
	}
403
	}
377
	var rangedDatePicker =  
404
	var rangedDatePicker = {
378
	{ 
-
 
379
			"todayHighlight": true,
405
		"todayHighlight" : true,
380
			"opens": "right",
406
		"opens" : "right",
381
			"startDate": startMoment || moment(),
407
		"startDate" : startMoment || moment(),
382
			"endDate": endMoment || moment(),
408
		"endDate" : endMoment || moment(),
383
			"autoclose": true,
409
		"autoclose" : true,
384
			"alwaysShowCalendars": false,
410
		"alwaysShowCalendars" : false,
385
			"autoUpdateInput": true,
411
		"autoUpdateInput" : true,
386
			"locale": {
412
		"locale" : {
387
				'format': 'DD/MM/YYYY'
413
			'format' : 'DD/MM/YYYY'
388
			}
414
		}
389
	};
415
	};
390
	if(showRanges) {
416
	if (showRanges) {
391
		rangedDatePicker['ranges'] = 
417
		rangedDatePicker['ranges'] = {
392
		{
-
 
393
            'Today': [moment(), moment()],
418
			'Today' : [ moment(), moment() ],
394
            'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
419
			'Yesterday' : [ moment().subtract(1, 'days'),
-
 
420
					moment().subtract(1, 'days') ],
395
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
421
			'Last 7 Days' : [ moment().subtract(6, 'days'), moment() ],
396
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
422
			'Last 30 Days' : [ moment().subtract(29, 'days'), moment() ],
397
            'This Month': [moment().startOf('month'), moment().endOf('month')],
423
			'This Month' : [ moment().startOf('month'), moment().endOf('month') ],
398
            'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
424
			'Last Month' : [ moment().subtract(1, 'month').startOf('month'),
-
 
425
					moment().subtract(1, 'month').endOf('month') ]
399
         }
426
		}
400
	}
427
	}
401
	return rangedDatePicker;
428
	return rangedDatePicker;
402
}
429
}
403
function showPosition(position) {
430
function showPosition(position) {
404
	if(typeof latitude == "undefined") {
431
	if (typeof latitude == "undefined") {
-
 
432
		var coords = {
-
 
433
			latitude : position.coords.latitude,
405
		var coords = {latitude:position.coords.latitude, longitude:position.coords.longitude}
434
			longitude : position.coords.longitude
-
 
435
		}
406
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON.stringify(coords), function(){
436
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
-
 
437
				.stringify(coords), function() {
407
			latitude = position.coords.latitude;
438
			latitude = position.coords.latitude;
408
			longitude = position.coords.longitude;
439
			longitude = position.coords.longitude;
409
		});
440
		});
410
	}
441
	}
411
	// distance = getDistance(latitude, longitude, position.coords.latitude,
442
	// distance = getDistance(latitude, longitude, position.coords.latitude,
412
	// position.coords.longitude);
443
	// position.coords.longitude);
413
}
444
}
414
 
445
 
415
function getAuthorisedWarehouses(callback){
446
function getAuthorisedWarehouses(callback) {
416
	bootBoxObj = { 
447
	bootBoxObj = {
417
		size: "small",
448
		size : "small",
418
		title: "Choose Warehouse", 
449
		title : "Choose Warehouse",
419
		callback: callback,
450
		callback : callback,
420
		inputType:'select',
451
		inputType : 'select',
421
		inputOptions : typeof inputOptions == "undefined" ? undefined : inputOptions
452
		inputOptions : typeof inputOptions == "undefined" ? undefined
-
 
453
				: inputOptions
422
	}
454
	}
423
	if(typeof inputOptions=="undefined") {
455
	if (typeof inputOptions == "undefined") {
424
		doGetAjaxRequestHandler(context+"/authorisedWarehouses", function(response){
456
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
-
 
457
				response) {
425
			response = JSON.parse(response);
458
			response = JSON.parse(response);
426
			inputOptions = [];
459
			inputOptions = [];
427
			response.forEach(function(warehouse){
460
			response.forEach(function(warehouse) {
428
				inputOptions.push({
461
				inputOptions.push({
429
					text:warehouse.name,
462
					text : warehouse.name,
430
					value:warehouse.id,
463
					value : warehouse.id,
431
				});
464
				});
432
			});
465
			});
433
			bootBoxObj['inputOptions'] = inputOptions;
466
			bootBoxObj['inputOptions'] = inputOptions;
434
			bootbox.prompt(bootBoxObj);
467
			bootbox.prompt(bootBoxObj);
435
		});
468
		});
436
	} else if(inputOptions.length==1) {
469
	} else if (inputOptions.length == 1) {
437
		callback(inputOptions[0].warehouse.id);
470
		callback(inputOptions[0].warehouse.id);
438
	}
-
 
439
	else {
471
	} else {
440
		bootbox.prompt(bootBoxObj);
472
		bootbox.prompt(bootBoxObj);
441
	}
473
	}
442
	
474
 
443
}
475
}
444
function getColorsForItems(catalogId, itemId, description, callback) {
476
function getColorsForItems(catalogId, itemId, description, callback) {
445
	bootBoxObj = { 
477
	bootBoxObj = {
446
			size: "small",
478
		size : "small",
447
			className:"item-wrapper",
479
		className : "item-wrapper",
448
			title: description, 
480
		title : description,
449
			callback: callback,
481
		callback : callback,
450
			inputType:'checkbox',
482
		inputType : 'checkbox',
451
	}
483
	}
452
	doGetAjaxRequestHandler(context+"/itemsByCatalogId?catalogId="+catalogId +"&itemId=" + itemId, function(response){
484
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
-
 
485
			+ catalogId + "&itemId=" + itemId, function(response) {
453
		coloredItems = JSON.parse(response);
486
		coloredItems = JSON.parse(response);
-
 
487
		inputOptions = [ {
-
 
488
			text : "All",
-
 
489
			value : "0",
454
		inputOptions = [{text:"All", value:"0", onclick:"toggleAll('itemIds')"}];
490
			onclick : "toggleAll('itemIds')"
-
 
491
		} ];
455
		coloredItems.forEach(function(item){
492
		coloredItems.forEach(function(item) {
456
			inputOptions.push({
493
			inputOptions.push({
457
				text:item.color,
494
				text : item.color,
458
				value:item.id,
495
				value : item.id,
459
				selected:item.active
496
				selected : item.active
460
			});
497
			});
461
		});
498
		});
462
		bootBoxObj['inputOptions'] = inputOptions;
499
		bootBoxObj['inputOptions'] = inputOptions;
463
		bootbox.prompt(bootBoxObj);
500
		bootbox.prompt(bootBoxObj);
464
		$('.item-wrapper').find('input[type="checkbox"]').slice(1).each(function(index,checkbox){
501
		$('.item-wrapper').find('input[type="checkbox"]').slice(1).each(
-
 
502
				function(index, checkbox) {
465
			checkbox.checked=coloredItems[index].active;
503
					checkbox.checked = coloredItems[index].active;
466
		});
504
				});
467
	});
505
	});
468
}
506
}
469
$(".item-wrapper").find("input[type='checkbox']:first").live('change', function(){
507
$(".item-wrapper").find("input[type='checkbox']:first").live(
-
 
508
		'change',
-
 
509
		function() {
470
	if(this.value=="0") {
510
			if (this.value == "0") {
471
		$(this).closest('.item-wrapper').find("input[type='checkbox']").slice(1).prop('checked', $(this).prop('checked'));
511
				$(this).closest('.item-wrapper').find("input[type='checkbox']")
-
 
512
						.slice(1).prop('checked', $(this).prop('checked'));
472
	}
513
			}
473
});
514
		});
474
function getItemAheadOptions(jqElement, callback) {
515
function getItemAheadOptions(jqElement, callback) {
475
	jqElement.typeahead('destroy').typeahead({
516
	jqElement.typeahead('destroy').typeahead({
476
		source: function(q, process) {
517
		source : function(q, process) {
477
			if (q.length >= 3){
518
			if (q.length >= 3) {
478
				return $.ajax(context+"/item", {
519
				return $.ajax(context + "/item", {
479
					global:false,
520
					global : false,
-
 
521
					data : {
480
					data: {query : q}, 
522
						query : q
-
 
523
					},
481
					success: function(data){
524
					success : function(data) {
482
						queryData = JSON.parse(data);
525
						queryData = JSON.parse(data);
483
						process(queryData);
526
						process(queryData);
484
					},
527
					},
485
				});
528
				});
486
			}
529
			}
487
		},
530
		},
488
		delay: 400,
531
		delay : 400,
489
		items: 20,
532
		items : 20,
-
 
533
		displayText : function(item) {
490
		displayText: function(item){return item.itemDescription;},
534
			return item.itemDescription;
-
 
535
		},
491
		autoSelect: true,
536
		autoSelect : true,
492
		afterSelect: callback
537
		afterSelect : callback
493
	});
538
	});
494
}
539
}
495
function getPartnerAheadOptions(jqElement, callback) {
540
function getPartnerAheadOptions(jqElement, callback) {
496
	jqElement.typeahead('destroy').typeahead({
541
	jqElement.typeahead('destroy').typeahead({
497
		source: function(q, process) {
542
		source : function(q, process) {
498
			if (q.length >= 3){
543
			if (q.length >= 3) {
499
				return $.ajax(context+"/partners", {
544
				return $.ajax(context + "/partners", {
500
					global:false,
545
					global : false,
-
 
546
					data : {
501
					data: {query : q}, 
547
						query : q
-
 
548
					},
502
					success: function(data){
549
					success : function(data) {
503
						queryData = JSON.parse(data);
550
						queryData = JSON.parse(data);
504
						process(queryData);
551
						process(queryData);
505
					},
552
					},
506
				});
553
				});
507
			}
554
			}
508
		},
555
		},
509
		delay: 300,
556
		delay : 300,
510
		items: 20,
557
		items : 20,
511
		displayText: function(partner){return partner.displayName;},
558
		displayText : function(partner) {
-
 
559
			return partner.displayName;
-
 
560
		},
512
		autoSelect: true,
561
		autoSelect : true,
513
		afterSelect: callback
562
		afterSelect : callback
514
	});
563
	});
515
}
564
}
516
 
565
 
517
function loadPriceDrop(domId){
566
function loadPriceDrop(domId) {
518
	doGetAjaxRequestHandler(context+"/getItemDescription", function(response){
567
	doGetAjaxRequestHandler(context + "/getItemDescription",
-
 
568
			function(response) {
519
		$('#' + domId).html(response);
569
				$('#' + domId).html(response);
520
	});
570
			});
521
}
571
}
522
$(".price_drop").live('click', function() {
572
$(".price_drop").live('click', function() {
523
	loadPriceDrop("main-content");
573
	loadPriceDrop("main-content");
524
});
-
 
525
574
});
-
 
575
var stopInterval;
-
 
576
$(document).ready(function(){
-
 
577
	
-
 
578
	 stopInterval = setInterval(showAttendanceModal, 10000);
-
 
579
	
-
 
580
});
-
 
581
function showAttendanceModal() {
-
 
582
	var today = new Date().getTime();
-
 
583
	if ($.cookie("punchIn") == undefined) {
-
 
584
		document.cookie = "punchIn=" + today;
-
 
585
	}
-
 
586
	if (today >= parseInt($.cookie("punchIn"))) {
-
 
587
		doGetAjaxRequestHandler(context + "/getPunchInOutForModel", function(
-
 
588
				response) {
-
 
589
		      if(response == 'true'){
-
 
590
		    	  $('#punchInOutModal').modal('hide');
-
 
591
		    	  clearInterval(stopInterval);
-
 
592
		    	  console.log("hide");
-
 
593
		      }else{
-
 
594
		    	  $("#punch-in-out-model").html(response);
-
 
595
					$('#punchInOutModal').modal('show');
-
 
596
					var time = today + 30 * 60 * 1000
-
 
597
					document.cookie = "punchIn=" + time; 
-
 
598
					console.log("show");
-
 
599
		      }
-
 
600
			
-
 
601
			 
-
 
602
 
-
 
603
		});	}
-
 
604
}
-
 
605
526
606