Subversion Repositories SmartDukaan

Rev

Rev 30017 | Rev 30033 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27711 amit.gupta 1
const MAIN_CONTAINER = "#main-content";
24440 amit.gupta 2
var logosmapping = {
27618 tejbeer 3
	mobile_insurance_providers: {
4
		"0": context + '/resources/images/icons/provider-logos/iffco.png',
5
		"1": context + '/resources/images/icons/provider-logos/icici.jpg',
6
		"2": context + '/resources/images/icons/provider-logos/tataaig.png',
7
		"3": context + '/resources/images/icons/provider-logos/bharti.jpg'
24595 tejbeer 8
	}
24440 amit.gupta 9
}
24595 tejbeer 10
function badRequestAlert(response) {
22956 ashik.ali 11
	console.log(response.responseText);
12
	var errorObject = JSON.parse(response.responseText);
13
	errorObject = errorObject.response;
24595 tejbeer 14
	bootbox.alert('Bad Request\n' + 'rejectedType : '
27618 tejbeer 15
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
16
		+ errorObject.rejectedValue + '\n' + 'message : '
17
		+ errorObject.message);
22956 ashik.ali 18
}
24595 tejbeer 19
 
20
function internalServerErrorAlert(response) {
22956 ashik.ali 21
	console.log(response.responseText);
22
	var errorObject = JSON.parse(response.responseText);
23
	errorObject = errorObject.response;
24595 tejbeer 24
	bootbox.alert('Internal Server Error\n' + 'rejectedType : '
27618 tejbeer 25
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
26
		+ errorObject.rejectedValue + '\n' + 'message : '
27
		+ errorObject.message);
22956 ashik.ali 28
}
29
 
24595 tejbeer 30
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
27355 tejbeer 31
	if (typeof loaderDialogObj != "undefined") {
32
		loaderDialogObj.modal('hide');
33
		// $('div.modal-backdrop.fade').remove();
34
	}
24595 tejbeer 35
	if (jqxhr.status == 400) {
23872 amit.gupta 36
		// $('#error-prompt-model').modal();
24595 tejbeer 37
		badRequestAlert(jqxhr);
38
	} else {
22956 ashik.ali 39
		internalServerErrorAlert(jqxhr);
40
	}
41
});
42
 
30017 amit.gupta 43
$(document).ajaxComplete(function () {
26140 amit.gupta 44
	if (typeof loaderDialogObj != "undefined") {
24271 amit.gupta 45
		loaderDialogObj.modal('hide');
27355 tejbeer 46
		// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 47
	}
23946 amit.gupta 48
});
30017 amit.gupta 49
 
24992 tejbeer 50
function ajaxStartHandler() {
24976 amit.gupta 51
	if (typeof loaderDialogObj != "undefined")
52
		loaderDialogObj.modal('show');
27927 amit.gupta 53
	/*if (typeof isInvestmentOk != "undefined" && !isInvestmentOk
27618 tejbeer 54
		&& $('#order-details').length == 0) {
24992 tejbeer 55
		var investmentDialog = bootbox
27618 tejbeer 56
			.dialog({
57
				title: '<h3	class="text-danger">ATTENTION!! ORDERING THROUGH APP MAY BE BLOCKED DUE TO LOW INVESTMENTS!</h3>',
58
				message: "<h3>Dear Partner, your investments are low by "
59
					+ shortPercentage
60
					+ "%</h3>"
61
					+ "<dl>"
62
					+ "<dt>Investment Should be</dt><dd>- "
63
					+ minimumInvestmentAmount
64
					+ "</dd>"
65
					+ "<dt>Total Invested Amount</dt><dd>-"
66
					+ totalInvestedAmount
67
					+ "</dd>"
68
					+ '<dt>Investment Amount Short By</dt><dd class="text-danger lead">-  '
69
					+ shortAmount
70
					+ '</dd></dl>'
71
					+ '<pre class="text-danger" style="font-size:18px;"><strong>To unblock your Billing, please \nadd Rs.'
72
					+ minAmountToBeAdded
73
					+ ' to wallet immediately.</strong></pre>',
74
				buttons: {
75
					cancel: {
76
						label: "OK",
77
						className: 'btn-primary'
24595 tejbeer 78
					}
27618 tejbeer 79
				}
80
			});
24976 amit.gupta 81
		investmentDialog.on('shown.bs.modal', function() {
24992 tejbeer 82
			var dialogEl = investmentDialog.find('.modal-content')[0];
83
			var dialogRect = dialogEl.getBoundingClientRect();
84
			var height = window.innerHeight - dialogRect.height;
85
			var width = window.innerWidth - dialogRect.width;
86
			var left = Math.floor(Math.random() * width) - dialogRect.left
87
			var top = Math.floor(Math.random() * height) - dialogRect.top
88
			$(dialogEl).css("left", left).css("top", top);
27928 amit.gupta 89
		});
90
	}*/
24976 amit.gupta 91
}
30017 amit.gupta 92
 
24976 amit.gupta 93
$(document).ajaxStart(ajaxStartHandler);
24595 tejbeer 94
 
95
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
30017 amit.gupta 96
										callback_function) {
24595 tejbeer 97
	$.ajax({
27618 tejbeer 98
		url: urlString,
99
		async: true,
100
		cache: false,
101
		data: params,
24595 tejbeer 102
		// dataType:'json',
27618 tejbeer 103
		type: httpType,
30017 amit.gupta 104
		success: function (response) {
24595 tejbeer 105
			callback_function(response);
30017 amit.gupta 106
			$('.currency').each(function (index, ele) {
24595 tejbeer 107
				if (!isNaN(parseInt($(ele).html()))) {
108
					$(ele).html(numberToComma($(ele).html()));
109
				}
23918 amit.gupta 110
			});
111
		}
112
	});
23193 ashik.ali 113
}
114
 
24595 tejbeer 115
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
23500 ashik.ali 116
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
117
}
118
 
24595 tejbeer 119
function doPostAjaxRequestWithParamsHandler(urlString, params,
30017 amit.gupta 120
											callback_function) {
23500 ashik.ali 121
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
122
}
123
 
24595 tejbeer 124
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
30017 amit.gupta 125
									  callback_function) {
23032 ashik.ali 126
	$.ajax({
27618 tejbeer 127
		url: urlString,
128
		async: true,
129
		cache: false,
130
		processData: false,
131
		data: json,
132
		contentType: 'application/json',
133
		type: httpType,
30017 amit.gupta 134
		success: function (response) {
24595 tejbeer 135
			// console.log("response"+JSON.stringify(data));
136
			callback_function(response);
30017 amit.gupta 137
			$('.currency').each(function (index, ele) {
24595 tejbeer 138
				if (!isNaN(parseInt($(ele).html()))) {
139
					$(ele).html(numberToComma($(ele).html()));
140
				}
141
			});
142
		}
23032 ashik.ali 143
	});
144
}
145
 
24595 tejbeer 146
function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function) {
23500 ashik.ali 147
	doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);
148
}
23032 ashik.ali 149
 
24595 tejbeer 150
function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function) {
23500 ashik.ali 151
	doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);
152
}
153
 
24595 tejbeer 154
function doAjaxRequestHandler(urlString, httpType, callback_function) {
22982 ashik.ali 155
	$.ajax({
27618 tejbeer 156
		url: urlString,
157
		async: true,
158
		cache: false,
159
		type: httpType,
30017 amit.gupta 160
		success: function (response) {
24595 tejbeer 161
			callback_function(response);
30017 amit.gupta 162
			$('.currency').each(function (index, ele) {
24595 tejbeer 163
				if (!isNaN(parseInt($(ele).html()))) {
164
					$(ele).html(numberToComma($(ele).html()));
165
				}
166
			});
167
		}
22982 ashik.ali 168
	});
169
}
170
 
24595 tejbeer 171
function doGetAjaxRequestHandler(urlString, callback_function) {
23500 ashik.ali 172
	doAjaxRequestHandler(urlString, "GET", callback_function);
173
}
174
 
24595 tejbeer 175
function doPutAjaxRequestHandler(urlString, callback_function) {
23500 ashik.ali 176
	doAjaxRequestHandler(urlString, "PUT", callback_function);
177
}
178
 
24595 tejbeer 179
function doPostAjaxRequestHandler(urlString, callback_function) {
23629 ashik.ali 180
	doAjaxRequestHandler(urlString, "POST", callback_function);
181
}
182
 
24595 tejbeer 183
function doDeleteAjaxRequestHandler(urlString, callback_function) {
23783 ashik.ali 184
	doAjaxRequestHandler(urlString, "DELETE", callback_function);
185
}
186
 
24595 tejbeer 187
function doAjaxUploadRequest(urlString, httpType, file) {
23347 ashik.ali 188
	var response;
24595 tejbeer 189
	doAjaxUploadRequestHandler(urlString, httpType, file,
30017 amit.gupta 190
		function (ajaxResponse) {
27618 tejbeer 191
			response = ajaxResponse;
192
		});
23347 ashik.ali 193
	return response;
194
}
195
 
24595 tejbeer 196
function doAjaxUploadRequestHandler(urlString, httpType, file,
30017 amit.gupta 197
									callback_function) {
22982 ashik.ali 198
	var formData = new FormData();
199
	formData.append("file", file);
200
	$.ajax({
27618 tejbeer 201
		url: urlString,
202
		type: httpType,
203
		data: formData,
204
		dataType: 'json',
205
		async: true,
206
		cache: false,
207
		contentType: false,
208
		enctype: 'multipart/form-data',
209
		processData: false,
30017 amit.gupta 210
		success: function (response) {
24595 tejbeer 211
			// console.log("response"+JSON.stringify(data));
212
			callback_function(response);
213
		}
22982 ashik.ali 214
	});
215
}
30017 amit.gupta 216
 
24595 tejbeer 217
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
30017 amit.gupta 218
										callback_function) {
24171 govind 219
	var formData = new FormData();
220
	formData.append("file", file);
27618 tejbeer 221
	formData.append('json', new Blob([json]));
24171 govind 222
	$.ajax({
27618 tejbeer 223
		url: urlString,
224
		type: httpType,
225
		data: formData,
226
		enctype: 'multipart/form-data',
227
		contentType: false,
228
		processData: false,
30017 amit.gupta 229
		success: function (response) {
24595 tejbeer 230
			// console.log("response"+JSON.stringify(data));
231
			callback_function(response);
232
		}
24171 govind 233
	});
234
}
22982 ashik.ali 235
 
24595 tejbeer 236
function uploadDocument(file) {
26389 amit.gupta 237
	var url = context + '/document-upload';
30017 amit.gupta 238
	doAjaxUploadRequestHandler(url, 'POST', file, function (response) {
24595 tejbeer 239
		var documentId = response.response.document_id;
240
		console.log("documentId : " + documentId);
23377 ashik.ali 241
		return documentId;
242
	});
23347 ashik.ali 243
}
244
 
24595 tejbeer 245
function doAjaxGetDownload(urlString, fileName) {
246
	console.log("fileName : " + fileName);
23343 ashik.ali 247
	doAjaxDownload(urlString, "GET", null, fileName);
22982 ashik.ali 248
}
249
 
24595 tejbeer 250
function doAjaxPostDownload(urlString, data, fileName) {
23343 ashik.ali 251
	doAjaxDownload(urlString, "POST", data, fileName);
21627 kshitij.so 252
}
253
 
24595 tejbeer 254
function doAjaxDownload(urlString, httpType, data, fileName) {
22488 ashik.ali 255
	xhttp = new XMLHttpRequest();
25093 amit.gupta 256
	if (typeof loaderDialogObj != "undefined")
257
		loaderDialogObj.modal('show');
30017 amit.gupta 258
	xhttp.onreadystatechange = function () {
24595 tejbeer 259
		var a;
260
		if (xhttp.readyState === 2) {
261
			if (xhttp.status == 200) {
262
				xhttp.responseType = "blob";
263
			} else {
264
				xhttp.responseType = "text";
265
			}
266
		} else if (xhttp.readyState === 4 && xhttp.status === 200) {
267
			// Trick for making downloadable link
26140 amit.gupta 268
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 269
				loaderDialogObj.modal('hide');
27355 tejbeer 270
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 271
			}
27355 tejbeer 272
 
24595 tejbeer 273
			a = document.createElement('a');
274
			a.href = window.URL.createObjectURL(xhttp.response);
275
			// Give filename you wish to download
276
			a.download = fileName;
277
			a.style.display = 'none';
278
			document.body.appendChild(a);
279
			a.click();
280
		} else if (xhttp.readyState == 4 && xhttp.status === 400) {
26140 amit.gupta 281
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 282
				loaderDialogObj.modal('hide');
27355 tejbeer 283
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 284
			}
24595 tejbeer 285
			badRequestAlert(xhttp);
286
		} else if (xhttp.readyState == 4 && xhttp.status === 500) {
26140 amit.gupta 287
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 288
				loaderDialogObj.modal('hide');
27355 tejbeer 289
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 290
			}
24595 tejbeer 291
			internalServerErrorAlert(xhttp);
292
		}
22488 ashik.ali 293
	};
294
	// Post data to URL which handles post request
23343 ashik.ali 295
	xhttp.open(httpType, urlString);
24595 tejbeer 296
	if (httpType == "POST") {
23343 ashik.ali 297
		xhttp.setRequestHeader("Content-Type", "application/json");
298
	}
22488 ashik.ali 299
	// You should set responseType as blob for binary responses
23872 amit.gupta 300
	// xhttp.responseType = 'blob';
22488 ashik.ali 301
	xhttp.send(data);
23405 amit.gupta 302
}
30017 amit.gupta 303
 
27618 tejbeer 304
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
30017 amit.gupta 305
									   tableIdentifier, detailsContainerIdentifier) {
27618 tejbeer 306
	var start = $("#" + paginatedIdentifier + " .start").text();
23405 amit.gupta 307
 
27618 tejbeer 308
	var end = $("#" + paginatedIdentifier + " .end").text();
309
 
310
	url = context + url + "?offset=" + end;
311
 
312
	if (params != null) {
313
		for (var key in params) {
314
			if (params.hasOwnProperty(key)) {
315
				//console.log(key + " -> " + params[key]);
316
				url = url + "&" + key + "=" + params[key];
317
			}
318
		}
319
	}
320
 
30017 amit.gupta 321
	doGetAjaxRequestHandler(url, function (response) {
27618 tejbeer 322
		var size = $("#" + paginatedIdentifier + " .size").text();
323
		if ((parseInt(end) + 20) > parseInt(size)) {
324
			// console.log("(end + 10) > size == true");
325
			$("#" + paginatedIdentifier + " .end").text(size);
326
		} else {
327
			// console.log("(end + 10) > size == false");
328
			$("#" + paginatedIdentifier + " .end").text(+end + +20);
329
		}
330
		$("#" + paginatedIdentifier + " .start").text(+start + +20);
331
		var last = $("#" + paginatedIdentifier + " .end").text();
332
		var temp = $("#" + paginatedIdentifier + " .size").text();
333
		console.log("last" + last);
334
		if (parseInt(last) >= parseInt(temp)) {
335
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
336
			// $( "#good-inventory-paginated .end" ).text(temp);
337
		}
338
		$('#' + tableIdentifier).html(response);
339
		if (detailsContainerIdentifier != null) {
340
			$('#' + detailsContainerIdentifier).html('');
341
		}
342
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
343
	});
344
 
345
}
30017 amit.gupta 346
 
27618 tejbeer 347
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
30017 amit.gupta 348
										  tableIdentifier, detailsContainerIdentifier) {
27618 tejbeer 349
	var start = $("#" + paginatedIdentifier + " .start").text();
350
	console.log("start" + start);
351
	var end = $("#" + paginatedIdentifier + " .end").text();
352
	console.log("Startend" + end);
353
	var size = $("#" + paginatedIdentifier + " .size").text();
354
	console.log("size" + size);
355
	if (parseInt(end) == parseInt(size) && parseInt(end) % 20 != 0) {
356
		var mod = parseInt(end) % 20;
357
		end = parseInt(end) + (20 - mod);
358
	}
359
	var pre = end - 20;
360
	var lat = pre - 20;
361
	//console.log("preCatalog" +pre);
362
 
363
	url = context + url + "?offset=" + pre;
364
 
365
	if (params != null) {
366
		for (var key in params) {
367
			if (params.hasOwnProperty(key)) {
368
				url = url + "&" + key + "=" + params[key];
369
			}
370
		}
371
	}
372
 
30017 amit.gupta 373
	doGetAjaxRequestHandler(url, function (response) {
27618 tejbeer 374
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
375
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
376
		$('#' + tableIdentifier).html(response);
377
		if (detailsContainerIdentifier != null) {
378
			$('#' + detailsContainerIdentifier).html('');
379
		}
380
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
381
		if (parseInt(lat) == 0) {
382
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
383
		}
384
	});
385
 
386
}
387
 
24595 tejbeer 388
function loadPaginatedNextItems(url, params, paginatedIdentifier,
30017 amit.gupta 389
								tableIdentifier, detailsContainerIdentifier) {
24595 tejbeer 390
	var start = $("#" + paginatedIdentifier + " .start").text();
391
	var end = $("#" + paginatedIdentifier + " .end").text();
23629 ashik.ali 392
	url = context + url + "?offset=" + end;
24595 tejbeer 393
 
394
	if (params != null) {
27618 tejbeer 395
		for (var key in params) {
23629 ashik.ali 396
			if (params.hasOwnProperty(key)) {
23872 amit.gupta 397
				// console.log(key + " -> " + p[key]);
24595 tejbeer 398
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 399
			}
400
		}
401
	}
24595 tejbeer 402
 
30017 amit.gupta 403
	doGetAjaxRequestHandler(url, function (response) {
24595 tejbeer 404
		var size = $("#" + paginatedIdentifier + " .size").text();
405
		if ((parseInt(end) + 10) > parseInt(size)) {
23629 ashik.ali 406
			console.log("(end + 10) > size == true");
24595 tejbeer 407
			$("#" + paginatedIdentifier + " .end").text(size);
408
		} else {
23629 ashik.ali 409
			console.log("(end + 10) > size == false");
24595 tejbeer 410
			$("#" + paginatedIdentifier + " .end").text(+end + +10);
23629 ashik.ali 411
		}
24595 tejbeer 412
		$("#" + paginatedIdentifier + " .start").text(+start + +10);
413
		var last = $("#" + paginatedIdentifier + " .end").text();
414
		var temp = $("#" + paginatedIdentifier + " .size").text();
415
		if (parseInt(last) >= parseInt(temp)) {
416
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
23872 amit.gupta 417
			// $( "#good-inventory-paginated .end" ).text(temp);
23629 ashik.ali 418
		}
24595 tejbeer 419
		$('#' + tableIdentifier).html(response);
420
		if (detailsContainerIdentifier != null) {
421
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 422
		}
24595 tejbeer 423
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
23629 ashik.ali 424
	});
24595 tejbeer 425
 
23629 ashik.ali 426
}
23405 amit.gupta 427
 
24595 tejbeer 428
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
30017 amit.gupta 429
									tableIdentifier, detailsContainerIdentifier) {
24595 tejbeer 430
	var start = $("#" + paginatedIdentifier + " .start").text();
431
	var end = $("#" + paginatedIdentifier + " .end").text();
432
	var size = $("#" + paginatedIdentifier + " .size").text();
433
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
23629 ashik.ali 434
		var mod = parseInt(end) % 10;
24595 tejbeer 435
		end = parseInt(end) + (10 - mod);
23629 ashik.ali 436
	}
27618 tejbeer 437
	var pre = end - 10;
24595 tejbeer 438
 
23629 ashik.ali 439
	url = context + url + "?offset=" + pre;
24595 tejbeer 440
 
441
	if (params != null) {
27618 tejbeer 442
		for (var key in params) {
23629 ashik.ali 443
			if (params.hasOwnProperty(key)) {
24595 tejbeer 444
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 445
			}
446
		}
447
	}
24595 tejbeer 448
 
30017 amit.gupta 449
	doGetAjaxRequestHandler(url, function (response) {
24595 tejbeer 450
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
451
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
452
		$('#' + tableIdentifier).html(response);
453
		if (detailsContainerIdentifier != null) {
454
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 455
		}
24595 tejbeer 456
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
457
		if (parseInt(pre) == 0) {
458
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
23629 ashik.ali 459
		}
24595 tejbeer 460
	});
461
 
23629 ashik.ali 462
}
463
 
23405 amit.gupta 464
function numberToComma(x) {
24992 tejbeer 465
 
24595 tejbeer 466
	x = x.toString();
24992 tejbeer 467
	x = x.split('.');
468
	var x1 = x[0];
25649 tejbeer 469
	var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
24992 tejbeer 470
	var lastThree = x1.substring(x1.length - 3);
25066 tejbeer 471
	var otherNumbers = x1.substring(0, x1.length - 3);
25649 tejbeer 472
	if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
25144 amit.gupta 473
		console.log(lastThree)
25649 tejbeer 474
	} else {
475
		if (otherNumbers != '')
476
			lastThree = ',' + lastThree;
25066 tejbeer 477
	}
24992 tejbeer 478
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
27618 tejbeer 479
		+ x2;
24992 tejbeer 480
 
23786 amit.gupta 481
}
23870 amit.gupta 482
 
26063 amit.gupta 483
function reporticoDRCallback(start, end) {
484
	startMoment = start;
485
	endMoment = end;
486
	startDate = start.format(moment.HTML5_FMT.DATE);
487
	endDate = end.format(moment.HTML5_FMT.DATE);
488
}
30017 amit.gupta 489
 
27355 tejbeer 490
// Custom formatters should be handled specifically at the controller side
23870 amit.gupta 491
function dateRangeCallback(start, end) {
23886 amit.gupta 492
	startMoment = start;
493
	endMoment = end;
494
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
495
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
23872 amit.gupta 496
}
497
 
24595 tejbeer 498
function getSingleDatePicker() {
499
	var singleDatePicker = {
27618 tejbeer 500
		"todayHighlight": true,
501
		"startDate": startMoment || moment(),
502
		"autoclose": true,
503
		"autoUpdateInput": true,
504
		"singleDatePicker": true,
505
		"locale": {
506
			'format': 'DD/MM/YYYY'
24595 tejbeer 507
		}
508
	};
23872 amit.gupta 509
	return singleDatePicker;
23886 amit.gupta 510
}
511
 
24595 tejbeer 512
function getRangedDatePicker(showRanges) {
513
	if (typeof showRanges == "undefined") {
23886 amit.gupta 514
		showRanges = false;
515
	}
24595 tejbeer 516
	var rangedDatePicker = {
27618 tejbeer 517
		"todayHighlight": true,
518
		"opens": "right",
519
		"startDate": startMoment || moment(),
520
		"endDate": endMoment || moment(),
521
		"autoclose": true,
522
		"alwaysShowCalendars": false,
523
		"autoUpdateInput": true,
524
		"locale": {
525
			'format': 'DD/MM/YYYY'
24595 tejbeer 526
		}
23886 amit.gupta 527
	};
24595 tejbeer 528
	if (showRanges) {
529
		rangedDatePicker['ranges'] = {
27618 tejbeer 530
			'Today': [moment(), moment()],
531
			'Yesterday': [moment().subtract(1, 'days'),
30017 amit.gupta 532
				moment().subtract(1, 'days')],
27618 tejbeer 533
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
534
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
535
			'This Month': [moment().startOf('month'), moment().endOf('month')],
536
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
30017 amit.gupta 537
				moment()],
27618 tejbeer 538
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
30017 amit.gupta 539
				moment()],
27618 tejbeer 540
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
30017 amit.gupta 541
				moment()]
24595 tejbeer 542
		}
23886 amit.gupta 543
	}
544
	return rangedDatePicker;
23892 amit.gupta 545
}
30017 amit.gupta 546
 
23946 amit.gupta 547
function showPosition(position) {
24595 tejbeer 548
	if (typeof latitude == "undefined") {
549
		var coords = {
27618 tejbeer 550
			latitude: position.coords.latitude,
551
			longitude: position.coords.longitude
24595 tejbeer 552
		}
553
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
30017 amit.gupta 554
			.stringify(coords), function () {
555
			latitude = position.coords.latitude;
556
			longitude = position.coords.longitude;
557
		});
24052 amit.gupta 558
	}
24176 amit.gupta 559
	// distance = getDistance(latitude, longitude, position.coords.latitude,
560
	// position.coords.longitude);
24168 amit.gupta 561
}
562
 
24595 tejbeer 563
function getAuthorisedWarehouses(callback) {
564
	bootBoxObj = {
27618 tejbeer 565
		size: "small",
566
		title: "Choose Warehouse",
567
		callback: callback,
568
		inputType: 'select',
569
		inputOptions: typeof inputOptions == "undefined" ? undefined
570
			: inputOptions
24168 amit.gupta 571
	}
24595 tejbeer 572
	if (typeof inputOptions == "undefined") {
30017 amit.gupta 573
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
27618 tejbeer 574
			response) {
24168 amit.gupta 575
			response = JSON.parse(response);
576
			inputOptions = [];
30017 amit.gupta 577
			response.forEach(function (warehouse) {
24168 amit.gupta 578
				inputOptions.push({
27618 tejbeer 579
					text: warehouse.name,
580
					value: warehouse.id,
24168 amit.gupta 581
				});
582
			});
583
			bootBoxObj['inputOptions'] = inputOptions;
584
			bootbox.prompt(bootBoxObj);
585
		});
24595 tejbeer 586
	} else if (inputOptions.length == 1) {
24168 amit.gupta 587
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 588
	} else {
24168 amit.gupta 589
		bootbox.prompt(bootBoxObj);
590
	}
24595 tejbeer 591
 
24176 amit.gupta 592
}
30017 amit.gupta 593
 
24410 amit.gupta 594
function getColorsForItems(catalogId, itemId, description, callback) {
30017 amit.gupta 595
	colorCheckboxHandler(catalogId, itemId, description, callback);
596
}
597
 
598
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
599
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
600
		+ catalogId + "&itemId=" + itemId, function (response) {
601
		let coloredItems = JSON.parse(response);
602
		let modalBody = [];
603
		coloredItems.forEach(function (item) {
604
			modalBody.push(`
605
                <div class="row">
606
                    <div class="col-sm-2">
607
                        ${item.color}
608
                    </div>
609
                    <div class="col-sm-2">
610
                            <input data-itemid="${item.id}" type="text" class="form-control" />
611
                    </div>
612
                </div>
613
            `);
614
		});
615
		let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
616
                              <div class="modal-dialog" >
617
                                <div class="modal-content">
618
                                  <div class="modal-header">
619
                                    <h5 class="modal-title">${title}</h5>
620
                                  </div>
621
                                  <div class="modal-body">
622
                                        ${modalBody.join('')}
623
                                  </div>
624
                                  <div class="modal-footer">
625
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
626
                                  </div>
627
                                </div>
628
                              </div>
629
                            </div>`;
630
		let $dialog = $(dialogBoxHtml);
631
		let modalObj = $dialog.modal('show');
632
		modalObj.on('hidden.bs.modal', function (e) {
633
			$dialog.remove();
634
		});
635
		$('button.number_dialog').on('click', function () {
636
			let itemQty = [];
637
			let anySelected = false;
638
			$(modalObj).find('.modal-body').find('input').each(function () {
639
				$input = $(this);
640
				if ($input.val() > 0) {
641
					itemQty.push({
642
						itemId: $input.data("itemid"),
643
						quantity: $input.val()
644
					});
645
					anySelected = true;
646
				}
647
			});
648
			if (anySelected) {
649
				$that = $(this);
650
				callback(itemQty, function () {
651
					$that.off('click');
652
					modalObj.hide();
653
				});
654
			} else {
655
				alert("Pls mention quantity");
656
			}
657
		});
658
	});
659
}
660
 
661
 
30021 amit.gupta 662
function colorCheckboxHandler(catalogId, itemId, description, callback) {
30017 amit.gupta 663
	let bootBoxObj = {
27618 tejbeer 664
		size: "small",
665
		className: "item-wrapper",
666
		title: description,
667
		callback: callback,
668
		inputType: 'checkbox',
24349 amit.gupta 669
	}
24595 tejbeer 670
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
30017 amit.gupta 671
		+ catalogId + "&itemId=" + itemId, function (response) {
672
		coloredItems = JSON.parse(response);
673
		inputOptions = [{
674
			text: "All",
675
			value: "0",
676
			onclick: "toggleAll('itemIds')"
677
		}];
678
		coloredItems.forEach(function (item) {
679
			inputOptions.push({
680
				text: item.color,
681
				value: item.id,
682
				selected: item.active
24349 amit.gupta 683
			});
27618 tejbeer 684
		});
30017 amit.gupta 685
		bootBoxObj['inputOptions'] = inputOptions;
686
		promptObj = bootbox.prompt(bootBoxObj);
687
		promptObj.modal('show')
688
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
689
			function (index, checkbox) {
690
				checkbox.checked = coloredItems[index].active;
691
			});
692
	});
24406 amit.gupta 693
}
28055 tejbeer 694
 
695
function getHotdealsForItems(catalogId, itemId, description, callback) {
696
	bootBoxObj = {
697
		size: "small",
698
		className: "item-wrapper",
699
		title: description,
700
		callback: callback,
701
		inputType: 'checkbox',
702
	}
703
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
30017 amit.gupta 704
		+ catalogId + "&itemId=" + itemId, function (response) {
705
		coloredItems = JSON.parse(response);
706
		inputOptions = [{
707
			text: "All",
708
			value: "0",
709
			onclick: "toggleAll('itemIds')"
710
		}];
711
		coloredItems.forEach(function (item) {
712
			inputOptions.push({
713
				text: item.color,
714
				value: item.id,
715
				selected: item.hotDeals
28055 tejbeer 716
			});
717
		});
30017 amit.gupta 718
		bootBoxObj['inputOptions'] = inputOptions;
719
		promptObj = bootbox.prompt(bootBoxObj);
720
		promptObj.modal('show')
721
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
722
			function (index, checkbox) {
723
				checkbox.checked = coloredItems[index].hotDeals;
724
			});
725
	});
28055 tejbeer 726
}
30017 amit.gupta 727
 
27763 tejbeer 728
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
30017 amit.gupta 729
	function () {
27618 tejbeer 730
		if (this.value == "0") {
731
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
732
				.slice(1).prop('checked', $(this).prop('checked'));
733
		}
734
	});
30017 amit.gupta 735
 
27618 tejbeer 736
function getItemAheadOptions(jqElement, anyColor, callback) {
737
	console.log(anyColor)
24176 amit.gupta 738
	jqElement.typeahead('destroy').typeahead({
30017 amit.gupta 739
		source: function (q, process) {
24595 tejbeer 740
			if (q.length >= 3) {
27618 tejbeer 741
				return $.ajax(context + "/item?anyColor=" + anyColor, {
742
					global: false,
743
					data: {
744
						query: q
24595 tejbeer 745
					},
30017 amit.gupta 746
					success: function (data) {
24191 amit.gupta 747
						queryData = JSON.parse(data);
748
						process(queryData);
24176 amit.gupta 749
					},
750
				});
24378 amit.gupta 751
			}
24176 amit.gupta 752
		},
27618 tejbeer 753
		delay: 300,
754
		items: 20,
30017 amit.gupta 755
		displayText: function (item) {
24595 tejbeer 756
			return item.itemDescription;
757
		},
27618 tejbeer 758
		autoSelect: true,
759
		afterSelect: callback
24176 amit.gupta 760
	});
761
}
28795 tejbeer 762
 
763
 
764
function getImeiAheadOptions(jqElement, fofoId, callback) {
765
	jqElement.typeahead('destroy').typeahead({
30017 amit.gupta 766
		source: function (q, process) {
28795 tejbeer 767
			if (q.length >= 3) {
768
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
769
					global: false,
770
					data: {
771
						query: q
772
					},
30017 amit.gupta 773
					success: function (data) {
28795 tejbeer 774
						queryData = JSON.parse(data);
775
						process(queryData);
776
					},
777
				});
778
			}
779
		},
780
		delay: 300,
781
		items: 20,
30017 amit.gupta 782
		displayText: function (imei) {
28795 tejbeer 783
			return imei;
784
		},
785
		autoSelect: true,
786
		afterSelect: callback
787
	});
788
}
789
 
790
 
25394 amit.gupta 791
function getEntityAheadOptions(jqElement, callback) {
792
	jqElement.typeahead('destroy').typeahead({
30017 amit.gupta 793
		source: function (q, process) {
25394 amit.gupta 794
			if (q.length >= 3) {
795
				return $.ajax(context + "/entity", {
27618 tejbeer 796
					global: false,
797
					data: {
798
						query: q
25394 amit.gupta 799
					},
30017 amit.gupta 800
					success: function (data) {
25394 amit.gupta 801
						queryData = JSON.parse(data);
802
						process(queryData);
803
					},
804
				});
805
			}
806
		},
27618 tejbeer 807
		delay: 300,
808
		items: 20,
30017 amit.gupta 809
		displayText: function (entity) {
25394 amit.gupta 810
			return entity.title_s + "(" + entity.catalogId_i + ")";
811
		},
27618 tejbeer 812
		autoSelect: true,
813
		afterSelect: callback
25394 amit.gupta 814
	});
815
}
30017 amit.gupta 816
 
24349 amit.gupta 817
function getPartnerAheadOptions(jqElement, callback) {
818
	jqElement.typeahead('destroy').typeahead({
30017 amit.gupta 819
		source: function (q, process) {
24595 tejbeer 820
			if (q.length >= 3) {
821
				return $.ajax(context + "/partners", {
27618 tejbeer 822
					global: false,
823
					data: {
824
						query: q
24595 tejbeer 825
					},
30017 amit.gupta 826
					success: function (data) {
24349 amit.gupta 827
						queryData = JSON.parse(data);
828
						process(queryData);
829
					},
830
				});
831
			}
832
		},
27618 tejbeer 833
		delay: 300,
834
		items: 20,
30017 amit.gupta 835
		displayText: function (partner) {
24595 tejbeer 836
			return partner.displayName;
837
		},
27618 tejbeer 838
		autoSelect: true,
839
		afterSelect: callback
24349 amit.gupta 840
	});
841
}
24406 amit.gupta 842
 
24595 tejbeer 843
function loadPriceDrop(domId) {
844
	doGetAjaxRequestHandler(context + "/getItemDescription",
30017 amit.gupta 845
		function (response) {
27618 tejbeer 846
			$('#' + domId).html(response);
847
		});
24406 amit.gupta 848
}
30017 amit.gupta 849
 
850
$(document).on('click', ".price_drop", function () {
24406 amit.gupta 851
	loadPriceDrop("main-content");
24595 tejbeer 852
});
25649 tejbeer 853
 
27618 tejbeer 854
 
30017 amit.gupta 855
$(document).on('click', ".closed_pricedrop", function () {
28569 amit.gupta 856
	loadClosedPriceDrop("main-content");
857
});
858
 
859
function loadClosedPriceDrop(domId) {
860
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
30017 amit.gupta 861
		function (response) {
28569 amit.gupta 862
			$('#' + domId).html(response);
863
		});
864
}
865
 
27696 tejbeer 866
function notifyTypeChange(messageType, $container) {
25683 tejbeer 867
	var messageQueryString = "?messageType=" + messageType;
25721 tejbeer 868
	if (messageType == null) {
25680 amit.gupta 869
		messageQueryString = "";
870
	}
30017 amit.gupta 871
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function (response) {
27711 amit.gupta 872
		if ($container != null) {
30017 amit.gupta 873
			loaderDialogObj.one('hidden.bs.modal', function () {
27696 tejbeer 874
				$container.popover({
875
					container: $container,
27824 amit.gupta 876
					template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
27696 tejbeer 877
					content: response,
878
					html: true,
879
					placement: "bottom",
27824 amit.gupta 880
					trigger: "manual",
881
					sanitize: false
27711 amit.gupta 882
				}).popover('show');
30017 amit.gupta 883
				setTimeout(function () {
884
					$container.focus().one('blur', function () {
27711 amit.gupta 885
						$container.popover('destroy');
886
					});
27826 amit.gupta 887
				}, 100);
27711 amit.gupta 888
			});
889
		}
890
	});
25649 tejbeer 891
}
25651 tejbeer 892
 
25689 amit.gupta 893
function downloadNotifyDocument(documentId, cid, documentName) {
25721 tejbeer 894
	doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
27618 tejbeer 895
		documentName);
25651 tejbeer 896
}
28051 amit.gupta 897
 
898
 
899
/* Create an array with the values of all the input boxes in a column */
30017 amit.gupta 900
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
901
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 902
		return $('input', td).val();
903
	});
28051 amit.gupta 904
}
28795 tejbeer 905
 
28063 amit.gupta 906
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
30017 amit.gupta 907
$.fn.dataTable.ext.order['dom-text-numeric'] = function (settings, col) {
908
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 909
		return $('input', td).val() * 1;
910
	});
28051 amit.gupta 911
}
28795 tejbeer 912
 
30017 amit.gupta 913
$.fn.dataTable.ext.order['dom-stock-numeric'] = function (settings, col) {
914
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28870 tejbeer 915
		return $(td).html().split("/")[0] * 1;
916
	});
917
}
28051 amit.gupta 918
/* Create an array with the values of all the select options in a column */
30017 amit.gupta 919
$.fn.dataTable.ext.order['dom-select'] = function (settings, col) {
920
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 921
		return $('select', td).val();
922
	});
28051 amit.gupta 923
}
28795 tejbeer 924
 
28051 amit.gupta 925
/* Create an array with the values of all the checkboxes in a column */
30017 amit.gupta 926
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
927
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 928
		return $('input', td).prop('checked') ? '1' : '0';
929
	});
28051 amit.gupta 930
}