Subversion Repositories SmartDukaan

Rev

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