Subversion Repositories SmartDukaan

Rev

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