Subversion Repositories SmartDukaan

Rev

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