Subversion Repositories SmartDukaan

Rev

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