Subversion Repositories SmartDukaan

Rev

Rev 30725 | Rev 30843 | 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) {
24992 tejbeer 430
 
24595 tejbeer 431
	x = x.toString();
24992 tejbeer 432
	x = x.split('.');
433
	var x1 = x[0];
25649 tejbeer 434
	var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
24992 tejbeer 435
	var lastThree = x1.substring(x1.length - 3);
25066 tejbeer 436
	var otherNumbers = x1.substring(0, x1.length - 3);
25649 tejbeer 437
	if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
25144 amit.gupta 438
		console.log(lastThree)
25649 tejbeer 439
	} else {
440
		if (otherNumbers != '')
441
			lastThree = ',' + lastThree;
25066 tejbeer 442
	}
24992 tejbeer 443
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
27618 tejbeer 444
		+ x2;
24992 tejbeer 445
 
23786 amit.gupta 446
}
23870 amit.gupta 447
 
30599 amit.gupta 448
function getSingleDatePicker(startMoment) {
24595 tejbeer 449
	var singleDatePicker = {
27618 tejbeer 450
		"todayHighlight": true,
451
		"startDate": startMoment || moment(),
452
		"autoclose": true,
453
		"autoUpdateInput": true,
454
		"singleDatePicker": true,
455
		"locale": {
456
			'format': 'DD/MM/YYYY'
24595 tejbeer 457
		}
458
	};
23872 amit.gupta 459
	return singleDatePicker;
23886 amit.gupta 460
}
461
 
30599 amit.gupta 462
function getDatesFromPicker(pickerElement) {
463
	return {
464
		startDate: $(pickerElement).data('daterangepicker').startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS),
465
		endDate: $(pickerElement).data('daterangepicker').endDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS)
466
	}
467
}
468
 
469
function getReporticoDatesFromPicker(pickerElement) {
470
	let datePickerData = $(pickerElement).data('daterangepicker');
471
	let formattedEndDate = null;
472
	if (typeof datePickerData.endDate == "object") {
473
		formattedEndDate = datePickerData.endDate.format(moment.HTML5_FMT.DATE);
474
	}
475
	return {
476
		startDate: datePickerData.startDate.format(moment.HTML5_FMT.DATE),
477
		endDate: formattedEndDate
478
	};
479
}
480
 
481
 
482
function getRangedDatePicker(showRanges, startMoment, endMoment) {
24595 tejbeer 483
	if (typeof showRanges == "undefined") {
23886 amit.gupta 484
		showRanges = false;
485
	}
24595 tejbeer 486
	var rangedDatePicker = {
27618 tejbeer 487
		"todayHighlight": true,
488
		"opens": "right",
30599 amit.gupta 489
		"startDate": startMoment || moment().startOf('day'),
490
		"endDate": endMoment || moment().endOf('day'),
27618 tejbeer 491
		"autoclose": true,
492
		"alwaysShowCalendars": false,
30075 amit.gupta 493
		"autoUpdateInput": true,
27618 tejbeer 494
		"locale": {
495
			'format': 'DD/MM/YYYY'
24595 tejbeer 496
		}
23886 amit.gupta 497
	};
24595 tejbeer 498
	if (showRanges) {
499
		rangedDatePicker['ranges'] = {
27618 tejbeer 500
			'Today': [moment(), moment()],
501
			'Yesterday': [moment().subtract(1, 'days'),
30599 amit.gupta 502
				moment().subtract(1, 'days')],
27618 tejbeer 503
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
504
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
505
			'This Month': [moment().startOf('month'), moment().endOf('month')],
506
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
30599 amit.gupta 507
				moment()],
27618 tejbeer 508
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
30599 amit.gupta 509
				moment()],
27618 tejbeer 510
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
30599 amit.gupta 511
				moment()]
24595 tejbeer 512
		}
23886 amit.gupta 513
	}
514
	return rangedDatePicker;
23892 amit.gupta 515
}
30017 amit.gupta 516
 
23946 amit.gupta 517
function showPosition(position) {
24595 tejbeer 518
	if (typeof latitude == "undefined") {
519
		var coords = {
27618 tejbeer 520
			latitude: position.coords.latitude,
521
			longitude: position.coords.longitude
24595 tejbeer 522
		}
523
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
30599 amit.gupta 524
			.stringify(coords), function () {
525
			latitude = position.coords.latitude;
526
			longitude = position.coords.longitude;
527
		});
24052 amit.gupta 528
	}
24176 amit.gupta 529
	// distance = getDistance(latitude, longitude, position.coords.latitude,
530
	// position.coords.longitude);
24168 amit.gupta 531
}
532
 
24595 tejbeer 533
function getAuthorisedWarehouses(callback) {
534
	bootBoxObj = {
27618 tejbeer 535
		size: "small",
536
		title: "Choose Warehouse",
537
		callback: callback,
538
		inputType: 'select',
539
		inputOptions: typeof inputOptions == "undefined" ? undefined
540
			: inputOptions
24168 amit.gupta 541
	}
24595 tejbeer 542
	if (typeof inputOptions == "undefined") {
30599 amit.gupta 543
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
27618 tejbeer 544
			response) {
24168 amit.gupta 545
			response = JSON.parse(response);
546
			inputOptions = [];
30599 amit.gupta 547
			response.forEach(function (warehouse) {
24168 amit.gupta 548
				inputOptions.push({
27618 tejbeer 549
					text: warehouse.name,
550
					value: warehouse.id,
24168 amit.gupta 551
				});
552
			});
553
			bootBoxObj['inputOptions'] = inputOptions;
554
			bootbox.prompt(bootBoxObj);
555
		});
24595 tejbeer 556
	} else if (inputOptions.length == 1) {
24168 amit.gupta 557
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 558
	} else {
24168 amit.gupta 559
		bootbox.prompt(bootBoxObj);
560
	}
24595 tejbeer 561
 
24176 amit.gupta 562
}
30017 amit.gupta 563
 
24410 amit.gupta 564
function getColorsForItems(catalogId, itemId, description, callback) {
30017 amit.gupta 565
	colorCheckboxHandler(catalogId, itemId, description, callback);
566
}
567
 
568
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
569
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
30599 amit.gupta 570
		+ catalogId + "&itemId=" + itemId, function (response) {
571
		let coloredItems = JSON.parse(response);
572
		let modalBody = [];
573
		coloredItems.forEach(function (item) {
574
			modalBody.push(`
30017 amit.gupta 575
                <div class="row">
576
                    <div class="col-sm-2">
577
                        ${item.color}
578
                    </div>
579
                    <div class="col-sm-2">
580
                            <input data-itemid="${item.id}" type="text" class="form-control" />
581
                    </div>
582
                </div>
583
            `);
30599 amit.gupta 584
		});
585
		let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
30017 amit.gupta 586
                              <div class="modal-dialog" >
587
                                <div class="modal-content">
588
                                  <div class="modal-header">
589
                                    <h5 class="modal-title">${title}</h5>
590
                                  </div>
591
                                  <div class="modal-body">
592
                                        ${modalBody.join('')}
593
                                  </div>
594
                                  <div class="modal-footer">
595
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
596
                                  </div>
597
                                </div>
598
                              </div>
599
                            </div>`;
30599 amit.gupta 600
		let $dialog = $(dialogBoxHtml);
601
		let modalObj = $dialog.modal('show');
602
		modalObj.on('hidden.bs.modal', function (e) {
603
			$dialog.remove();
604
		});
605
		$('button.number_dialog').on('click', function () {
606
			let itemQty = [];
607
			let anySelected = false;
608
			$(modalObj).find('.modal-body').find('input').each(function () {
609
				$input = $(this);
610
				if ($input.val() > 0) {
611
					itemQty.push({
612
						itemId: $input.data("itemid"),
613
						quantity: $input.val()
30017 amit.gupta 614
					});
30599 amit.gupta 615
					anySelected = true;
30017 amit.gupta 616
				}
617
			});
30599 amit.gupta 618
			if (anySelected && confirm("Are you sure want to notify?")) {
619
				$that = $(this);
620
				callback(itemQty, function () {
621
					$that.off('click');
622
					modalObj.hide();
623
				});
624
			} else {
625
				alert("Pls mention quantity");
626
			}
30017 amit.gupta 627
		});
30599 amit.gupta 628
	});
30017 amit.gupta 629
}
630
 
631
 
30021 amit.gupta 632
function colorCheckboxHandler(catalogId, itemId, description, callback) {
30017 amit.gupta 633
	let bootBoxObj = {
27618 tejbeer 634
		size: "small",
635
		className: "item-wrapper",
636
		title: description,
637
		callback: callback,
638
		inputType: 'checkbox',
24349 amit.gupta 639
	}
24595 tejbeer 640
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
30599 amit.gupta 641
		+ catalogId + "&itemId=" + itemId, function (response) {
642
		coloredItems = JSON.parse(response);
643
		inputOptions = [{
644
			text: "All",
645
			value: "0",
646
			onclick: "toggleAll('itemIds')"
647
		}];
648
		coloredItems.forEach(function (item) {
649
			inputOptions.push({
650
				text: item.color,
651
				value: item.id,
652
				selected: item.active
24349 amit.gupta 653
			});
27618 tejbeer 654
		});
30599 amit.gupta 655
		bootBoxObj['inputOptions'] = inputOptions;
656
		promptObj = bootbox.prompt(bootBoxObj);
657
		promptObj.modal('show')
658
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
659
			function (index, checkbox) {
660
				checkbox.checked = coloredItems[index].active;
661
			});
662
	});
24406 amit.gupta 663
}
28055 tejbeer 664
 
665
function getHotdealsForItems(catalogId, itemId, description, callback) {
666
	bootBoxObj = {
667
		size: "small",
668
		className: "item-wrapper",
669
		title: description,
670
		callback: callback,
671
		inputType: 'checkbox',
672
	}
673
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
30599 amit.gupta 674
		+ catalogId + "&itemId=" + itemId, function (response) {
675
		coloredItems = JSON.parse(response);
676
		inputOptions = [{
677
			text: "All",
678
			value: "0",
679
			onclick: "toggleAll('itemIds')"
680
		}];
681
		coloredItems.forEach(function (item) {
682
			inputOptions.push({
683
				text: item.color,
684
				value: item.id,
685
				selected: item.hotDeals
28055 tejbeer 686
			});
687
		});
30599 amit.gupta 688
		bootBoxObj['inputOptions'] = inputOptions;
689
		promptObj = bootbox.prompt(bootBoxObj);
690
		promptObj.modal('show')
691
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
692
			function (index, checkbox) {
693
				checkbox.checked = coloredItems[index].hotDeals;
694
			});
695
	});
28055 tejbeer 696
}
30017 amit.gupta 697
 
27763 tejbeer 698
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
30599 amit.gupta 699
	function () {
27618 tejbeer 700
		if (this.value == "0") {
701
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
702
				.slice(1).prop('checked', $(this).prop('checked'));
703
		}
704
	});
30017 amit.gupta 705
 
27618 tejbeer 706
function getItemAheadOptions(jqElement, anyColor, callback) {
707
	console.log(anyColor)
24176 amit.gupta 708
	jqElement.typeahead('destroy').typeahead({
30599 amit.gupta 709
		source: function (q, process) {
24595 tejbeer 710
			if (q.length >= 3) {
27618 tejbeer 711
				return $.ajax(context + "/item?anyColor=" + anyColor, {
712
					global: false,
713
					data: {
714
						query: q
24595 tejbeer 715
					},
30599 amit.gupta 716
					success: function (data) {
24191 amit.gupta 717
						queryData = JSON.parse(data);
718
						process(queryData);
24176 amit.gupta 719
					},
720
				});
24378 amit.gupta 721
			}
24176 amit.gupta 722
		},
27618 tejbeer 723
		delay: 300,
724
		items: 20,
30599 amit.gupta 725
		displayText: function (item) {
24595 tejbeer 726
			return item.itemDescription;
727
		},
27618 tejbeer 728
		autoSelect: true,
729
		afterSelect: callback
24176 amit.gupta 730
	});
731
}
28795 tejbeer 732
 
733
 
734
function getImeiAheadOptions(jqElement, fofoId, callback) {
735
	jqElement.typeahead('destroy').typeahead({
30599 amit.gupta 736
		source: function (q, process) {
28795 tejbeer 737
			if (q.length >= 3) {
738
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
739
					global: false,
740
					data: {
741
						query: q
742
					},
30599 amit.gupta 743
					success: function (data) {
28795 tejbeer 744
						queryData = JSON.parse(data);
745
						process(queryData);
746
					},
747
				});
748
			}
749
		},
750
		delay: 300,
751
		items: 20,
30599 amit.gupta 752
		displayText: function (imei) {
28795 tejbeer 753
			return imei;
754
		},
755
		autoSelect: true,
756
		afterSelect: callback
757
	});
758
}
759
 
760
 
25394 amit.gupta 761
function getEntityAheadOptions(jqElement, callback) {
762
	jqElement.typeahead('destroy').typeahead({
30599 amit.gupta 763
		source: function (q, process) {
25394 amit.gupta 764
			if (q.length >= 3) {
765
				return $.ajax(context + "/entity", {
27618 tejbeer 766
					global: false,
767
					data: {
768
						query: q
25394 amit.gupta 769
					},
30599 amit.gupta 770
					success: function (data) {
25394 amit.gupta 771
						queryData = JSON.parse(data);
772
						process(queryData);
773
					},
774
				});
775
			}
776
		},
27618 tejbeer 777
		delay: 300,
30067 amit.gupta 778
		items: 30,
30599 amit.gupta 779
		displayText: function (entity) {
25394 amit.gupta 780
			return entity.title_s + "(" + entity.catalogId_i + ")";
781
		},
27618 tejbeer 782
		autoSelect: true,
783
		afterSelect: callback
25394 amit.gupta 784
	});
785
}
30017 amit.gupta 786
 
24349 amit.gupta 787
function getPartnerAheadOptions(jqElement, callback) {
788
	jqElement.typeahead('destroy').typeahead({
30599 amit.gupta 789
		source: function (q, process) {
24595 tejbeer 790
			if (q.length >= 3) {
791
				return $.ajax(context + "/partners", {
27618 tejbeer 792
					global: false,
793
					data: {
794
						query: q
24595 tejbeer 795
					},
30599 amit.gupta 796
					success: function (data) {
24349 amit.gupta 797
						queryData = JSON.parse(data);
798
						process(queryData);
799
					},
800
				});
801
			}
802
		},
27618 tejbeer 803
		delay: 300,
804
		items: 20,
30599 amit.gupta 805
		displayText: function (partner) {
24595 tejbeer 806
			return partner.displayName;
807
		},
27618 tejbeer 808
		autoSelect: true,
809
		afterSelect: callback
24349 amit.gupta 810
	});
811
}
24406 amit.gupta 812
 
24595 tejbeer 813
function loadPriceDrop(domId) {
814
	doGetAjaxRequestHandler(context + "/getItemDescription",
30599 amit.gupta 815
		function (response) {
27618 tejbeer 816
			$('#' + domId).html(response);
817
		});
24406 amit.gupta 818
}
30017 amit.gupta 819
 
30599 amit.gupta 820
$(document).on('click', ".price_drop", function () {
24406 amit.gupta 821
	loadPriceDrop("main-content");
24595 tejbeer 822
});
25649 tejbeer 823
 
27618 tejbeer 824
 
30599 amit.gupta 825
$(document).on('click', ".closed_pricedrop", function () {
28569 amit.gupta 826
	loadClosedPriceDrop("main-content");
827
});
828
 
829
function loadClosedPriceDrop(domId) {
830
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
30599 amit.gupta 831
		function (response) {
28569 amit.gupta 832
			$('#' + domId).html(response);
833
		});
834
}
835
 
27696 tejbeer 836
function notifyTypeChange(messageType, $container) {
25683 tejbeer 837
	var messageQueryString = "?messageType=" + messageType;
25721 tejbeer 838
	if (messageType == null) {
25680 amit.gupta 839
		messageQueryString = "";
840
	}
30599 amit.gupta 841
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function (response) {
27711 amit.gupta 842
		if ($container != null) {
30599 amit.gupta 843
			loaderDialogObj.one('hidden.bs.modal', function () {
27696 tejbeer 844
				$container.popover({
845
					container: $container,
27824 amit.gupta 846
					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 847
					content: response,
848
					html: true,
849
					placement: "bottom",
27824 amit.gupta 850
					trigger: "manual",
851
					sanitize: false
27711 amit.gupta 852
				}).popover('show');
30599 amit.gupta 853
				setTimeout(function () {
854
					$container.focus().one('blur', function () {
27711 amit.gupta 855
						$container.popover('destroy');
856
					});
27826 amit.gupta 857
				}, 100);
27711 amit.gupta 858
			});
859
		}
860
	});
25649 tejbeer 861
}
25651 tejbeer 862
 
25689 amit.gupta 863
function downloadNotifyDocument(documentId, cid, documentName) {
25721 tejbeer 864
	doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
27618 tejbeer 865
		documentName);
25651 tejbeer 866
}
28051 amit.gupta 867
 
868
 
869
/* Create an array with the values of all the input boxes in a column */
30599 amit.gupta 870
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
871
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 872
		return $('input', td).val();
873
	});
28051 amit.gupta 874
}
28795 tejbeer 875
 
28063 amit.gupta 876
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
30599 amit.gupta 877
$.fn.dataTable.ext.order['dom-text-numeric'] = function (settings, col) {
878
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 879
		return $('input', td).val() * 1;
880
	});
28051 amit.gupta 881
}
28795 tejbeer 882
 
30599 amit.gupta 883
$.fn.dataTable.ext.order['dom-stock-numeric'] = function (settings, col) {
884
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28870 tejbeer 885
		return $(td).html().split("/")[0] * 1;
886
	});
887
}
28051 amit.gupta 888
/* Create an array with the values of all the select options in a column */
30599 amit.gupta 889
$.fn.dataTable.ext.order['dom-select'] = function (settings, col) {
890
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
28795 tejbeer 891
		return $('select', td).val();
892
	});
28051 amit.gupta 893
}
28795 tejbeer 894
 
28051 amit.gupta 895
/* Create an array with the values of all the checkboxes in a column */
30599 amit.gupta 896
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
30587 tejbeer 897
	return this.api().column(col, {
898
		order: 'index'
30599 amit.gupta 899
	}).nodes().map(function (td, i) {
28795 tejbeer 900
		return $('input', td).prop('checked') ? '1' : '0';
901
	});
30414 amit.gupta 902
}
903
 
30599 amit.gupta 904
$.fn.dataTable.Api.register('sum()', function () {
905
	return this.flatten().reduce(function (a, b) {
30414 amit.gupta 906
		if (typeof a === 'string') {
907
			a = a.replace(/[^\d.-]/g, '') * 1;
908
			a = isNaN(a) ? 0 : a;
909
		}
910
		if (typeof b === 'string') {
911
			b = b.replace(/[^\d.-]/g, '') * 1;
912
			b = isNaN(b) ? 0 : b;
913
		}
914
 
915
		return a + b;
916
	}, 0);
30694 amit.gupta 917
});
918
 
919
const debounce = (func, delay) => {
920
	let debounceTimer
921
	return function () {
922
		const context = this
923
		const args = arguments
924
		clearTimeout(debounceTimer)
925
		debounceTimer
926
			= setTimeout(() => func.apply(context, args), delay)
927
	}
928
}