Subversion Repositories SmartDukaan

Rev

Rev 27826 | Rev 27928 | 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
 
24595 tejbeer 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
});
24992 tejbeer 49
function ajaxStartHandler() {
24976 amit.gupta 50
	if (typeof loaderDialogObj != "undefined")
51
		loaderDialogObj.modal('show');
27927 amit.gupta 52
	/*if (typeof isInvestmentOk != "undefined" && !isInvestmentOk
27618 tejbeer 53
		&& $('#order-details').length == 0) {
24992 tejbeer 54
		var investmentDialog = bootbox
27618 tejbeer 55
			.dialog({
56
				title: '<h3	class="text-danger">ATTENTION!! ORDERING THROUGH APP MAY BE BLOCKED DUE TO LOW INVESTMENTS!</h3>',
57
				message: "<h3>Dear Partner, your investments are low by "
58
					+ shortPercentage
59
					+ "%</h3>"
60
					+ "<dl>"
61
					+ "<dt>Investment Should be</dt><dd>- "
62
					+ minimumInvestmentAmount
63
					+ "</dd>"
64
					+ "<dt>Total Invested Amount</dt><dd>-"
65
					+ totalInvestedAmount
66
					+ "</dd>"
67
					+ '<dt>Investment Amount Short By</dt><dd class="text-danger lead">-  '
68
					+ shortAmount
69
					+ '</dd></dl>'
70
					+ '<pre class="text-danger" style="font-size:18px;"><strong>To unblock your Billing, please \nadd Rs.'
71
					+ minAmountToBeAdded
72
					+ ' to wallet immediately.</strong></pre>',
73
				buttons: {
74
					cancel: {
75
						label: "OK",
76
						className: 'btn-primary'
24595 tejbeer 77
					}
27618 tejbeer 78
				}
79
			});
24976 amit.gupta 80
		investmentDialog.on('shown.bs.modal', function() {
24992 tejbeer 81
			var dialogEl = investmentDialog.find('.modal-content')[0];
82
			var dialogRect = dialogEl.getBoundingClientRect();
83
			var height = window.innerHeight - dialogRect.height;
84
			var width = window.innerWidth - dialogRect.width;
85
			var left = Math.floor(Math.random() * width) - dialogRect.left
86
			var top = Math.floor(Math.random() * height) - dialogRect.top
87
			$(dialogEl).css("left", left).css("top", top);
27927 amit.gupta 88
		});*/
24976 amit.gupta 89
	}
90
}
91
$(document).ajaxStart(ajaxStartHandler);
24595 tejbeer 92
 
93
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
27618 tejbeer 94
	callback_function) {
24595 tejbeer 95
	$.ajax({
27618 tejbeer 96
		url: urlString,
97
		async: true,
98
		cache: false,
99
		data: params,
24595 tejbeer 100
		// dataType:'json',
27618 tejbeer 101
		type: httpType,
102
		success: function(response) {
24595 tejbeer 103
			callback_function(response);
104
			$('.currency').each(function(index, ele) {
105
				if (!isNaN(parseInt($(ele).html()))) {
106
					$(ele).html(numberToComma($(ele).html()));
107
				}
23918 amit.gupta 108
			});
109
		}
110
	});
23193 ashik.ali 111
}
112
 
24595 tejbeer 113
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
23500 ashik.ali 114
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
115
}
116
 
24595 tejbeer 117
function doPostAjaxRequestWithParamsHandler(urlString, params,
27618 tejbeer 118
	callback_function) {
23500 ashik.ali 119
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
120
}
121
 
24595 tejbeer 122
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
27618 tejbeer 123
	callback_function) {
23032 ashik.ali 124
	$.ajax({
27618 tejbeer 125
		url: urlString,
126
		async: true,
127
		cache: false,
128
		processData: false,
129
		data: json,
130
		contentType: 'application/json',
131
		type: httpType,
132
		success: function(response) {
24595 tejbeer 133
			// console.log("response"+JSON.stringify(data));
134
			callback_function(response);
135
			$('.currency').each(function(index, ele) {
136
				if (!isNaN(parseInt($(ele).html()))) {
137
					$(ele).html(numberToComma($(ele).html()));
138
				}
139
			});
140
		}
23032 ashik.ali 141
	});
142
}
143
 
24595 tejbeer 144
function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function) {
23500 ashik.ali 145
	doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);
146
}
23032 ashik.ali 147
 
24595 tejbeer 148
function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function) {
23500 ashik.ali 149
	doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);
150
}
151
 
24595 tejbeer 152
function doAjaxRequestHandler(urlString, httpType, callback_function) {
22982 ashik.ali 153
	$.ajax({
27618 tejbeer 154
		url: urlString,
155
		async: true,
156
		cache: false,
157
		type: httpType,
158
		success: function(response) {
24595 tejbeer 159
			callback_function(response);
160
			$('.currency').each(function(index, ele) {
161
				if (!isNaN(parseInt($(ele).html()))) {
162
					$(ele).html(numberToComma($(ele).html()));
163
				}
164
			});
165
		}
22982 ashik.ali 166
	});
167
}
168
 
24595 tejbeer 169
function doGetAjaxRequestHandler(urlString, callback_function) {
23500 ashik.ali 170
	doAjaxRequestHandler(urlString, "GET", callback_function);
171
}
172
 
24595 tejbeer 173
function doPutAjaxRequestHandler(urlString, callback_function) {
23500 ashik.ali 174
	doAjaxRequestHandler(urlString, "PUT", callback_function);
175
}
176
 
24595 tejbeer 177
function doPostAjaxRequestHandler(urlString, callback_function) {
23629 ashik.ali 178
	doAjaxRequestHandler(urlString, "POST", callback_function);
179
}
180
 
24595 tejbeer 181
function doDeleteAjaxRequestHandler(urlString, callback_function) {
23783 ashik.ali 182
	doAjaxRequestHandler(urlString, "DELETE", callback_function);
183
}
184
 
24595 tejbeer 185
function doAjaxUploadRequest(urlString, httpType, file) {
23347 ashik.ali 186
	var response;
24595 tejbeer 187
	doAjaxUploadRequestHandler(urlString, httpType, file,
27618 tejbeer 188
		function(ajaxResponse) {
189
			response = ajaxResponse;
190
		});
23347 ashik.ali 191
	return response;
192
}
193
 
24595 tejbeer 194
function doAjaxUploadRequestHandler(urlString, httpType, file,
27618 tejbeer 195
	callback_function) {
22982 ashik.ali 196
	var formData = new FormData();
197
	formData.append("file", file);
198
	$.ajax({
27618 tejbeer 199
		url: urlString,
200
		type: httpType,
201
		data: formData,
202
		dataType: 'json',
203
		async: true,
204
		cache: false,
205
		contentType: false,
206
		enctype: 'multipart/form-data',
207
		processData: false,
208
		success: function(response) {
24595 tejbeer 209
			// console.log("response"+JSON.stringify(data));
210
			callback_function(response);
211
		}
22982 ashik.ali 212
	});
213
}
24595 tejbeer 214
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
27618 tejbeer 215
	callback_function) {
24171 govind 216
	var formData = new FormData();
217
	formData.append("file", file);
27618 tejbeer 218
	formData.append('json', new Blob([json]));
24171 govind 219
	$.ajax({
27618 tejbeer 220
		url: urlString,
221
		type: httpType,
222
		data: formData,
223
		enctype: 'multipart/form-data',
224
		contentType: false,
225
		processData: false,
226
		success: function(response) {
24595 tejbeer 227
			// console.log("response"+JSON.stringify(data));
228
			callback_function(response);
229
		}
24171 govind 230
	});
231
}
22982 ashik.ali 232
 
24595 tejbeer 233
function uploadDocument(file) {
26389 amit.gupta 234
	var url = context + '/document-upload';
24595 tejbeer 235
	doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
236
		var documentId = response.response.document_id;
237
		console.log("documentId : " + documentId);
23377 ashik.ali 238
		return documentId;
239
	});
23347 ashik.ali 240
}
241
 
24595 tejbeer 242
function doAjaxGetDownload(urlString, fileName) {
243
	console.log("fileName : " + fileName);
23343 ashik.ali 244
	doAjaxDownload(urlString, "GET", null, fileName);
22982 ashik.ali 245
}
246
 
24595 tejbeer 247
function doAjaxPostDownload(urlString, data, fileName) {
23343 ashik.ali 248
	doAjaxDownload(urlString, "POST", data, fileName);
21627 kshitij.so 249
}
250
 
24595 tejbeer 251
function doAjaxDownload(urlString, httpType, data, fileName) {
22488 ashik.ali 252
	xhttp = new XMLHttpRequest();
25093 amit.gupta 253
	if (typeof loaderDialogObj != "undefined")
254
		loaderDialogObj.modal('show');
22488 ashik.ali 255
	xhttp.onreadystatechange = function() {
24595 tejbeer 256
		var a;
257
		if (xhttp.readyState === 2) {
258
			if (xhttp.status == 200) {
259
				xhttp.responseType = "blob";
260
			} else {
261
				xhttp.responseType = "text";
262
			}
263
		} else if (xhttp.readyState === 4 && xhttp.status === 200) {
264
			// Trick for making downloadable link
26140 amit.gupta 265
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 266
				loaderDialogObj.modal('hide');
27355 tejbeer 267
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 268
			}
27355 tejbeer 269
 
24595 tejbeer 270
			a = document.createElement('a');
271
			a.href = window.URL.createObjectURL(xhttp.response);
272
			// Give filename you wish to download
273
			a.download = fileName;
274
			a.style.display = 'none';
275
			document.body.appendChild(a);
276
			a.click();
277
		} else if (xhttp.readyState == 4 && xhttp.status === 400) {
26140 amit.gupta 278
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 279
				loaderDialogObj.modal('hide');
27355 tejbeer 280
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 281
			}
24595 tejbeer 282
			badRequestAlert(xhttp);
283
		} else if (xhttp.readyState == 4 && xhttp.status === 500) {
26140 amit.gupta 284
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 285
				loaderDialogObj.modal('hide');
27355 tejbeer 286
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 287
			}
24595 tejbeer 288
			internalServerErrorAlert(xhttp);
289
		}
22488 ashik.ali 290
	};
291
	// Post data to URL which handles post request
23343 ashik.ali 292
	xhttp.open(httpType, urlString);
24595 tejbeer 293
	if (httpType == "POST") {
23343 ashik.ali 294
		xhttp.setRequestHeader("Content-Type", "application/json");
295
	}
22488 ashik.ali 296
	// You should set responseType as blob for binary responses
23872 amit.gupta 297
	// xhttp.responseType = 'blob';
22488 ashik.ali 298
	xhttp.send(data);
23405 amit.gupta 299
}
27618 tejbeer 300
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
301
	tableIdentifier, detailsContainerIdentifier) {
302
	var start = $("#" + paginatedIdentifier + " .start").text();
23405 amit.gupta 303
 
27618 tejbeer 304
	var end = $("#" + paginatedIdentifier + " .end").text();
305
 
306
	url = context + url + "?offset=" + end;
307
 
308
	if (params != null) {
309
		for (var key in params) {
310
			if (params.hasOwnProperty(key)) {
311
				//console.log(key + " -> " + params[key]);
312
				url = url + "&" + key + "=" + params[key];
313
			}
314
		}
315
	}
316
 
317
	doGetAjaxRequestHandler(url, function(response) {
318
		var size = $("#" + paginatedIdentifier + " .size").text();
319
		if ((parseInt(end) + 20) > parseInt(size)) {
320
			// console.log("(end + 10) > size == true");
321
			$("#" + paginatedIdentifier + " .end").text(size);
322
		} else {
323
			// console.log("(end + 10) > size == false");
324
			$("#" + paginatedIdentifier + " .end").text(+end + +20);
325
		}
326
		$("#" + paginatedIdentifier + " .start").text(+start + +20);
327
		var last = $("#" + paginatedIdentifier + " .end").text();
328
		var temp = $("#" + paginatedIdentifier + " .size").text();
329
		console.log("last" + last);
330
		if (parseInt(last) >= parseInt(temp)) {
331
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
332
			// $( "#good-inventory-paginated .end" ).text(temp);
333
		}
334
		$('#' + tableIdentifier).html(response);
335
		if (detailsContainerIdentifier != null) {
336
			$('#' + detailsContainerIdentifier).html('');
337
		}
338
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
339
	});
340
 
341
}
342
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
343
	tableIdentifier, detailsContainerIdentifier) {
344
	var start = $("#" + paginatedIdentifier + " .start").text();
345
	console.log("start" + start);
346
	var end = $("#" + paginatedIdentifier + " .end").text();
347
	console.log("Startend" + end);
348
	var size = $("#" + paginatedIdentifier + " .size").text();
349
	console.log("size" + size);
350
	if (parseInt(end) == parseInt(size) && parseInt(end) % 20 != 0) {
351
		var mod = parseInt(end) % 20;
352
		end = parseInt(end) + (20 - mod);
353
	}
354
	var pre = end - 20;
355
	var lat = pre - 20;
356
	//console.log("preCatalog" +pre);
357
 
358
	url = context + url + "?offset=" + pre;
359
 
360
	if (params != null) {
361
		for (var key in params) {
362
			if (params.hasOwnProperty(key)) {
363
				url = url + "&" + key + "=" + params[key];
364
			}
365
		}
366
	}
367
 
368
	doGetAjaxRequestHandler(url, function(response) {
369
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
370
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
371
		$('#' + tableIdentifier).html(response);
372
		if (detailsContainerIdentifier != null) {
373
			$('#' + detailsContainerIdentifier).html('');
374
		}
375
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
376
		if (parseInt(lat) == 0) {
377
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
378
		}
379
	});
380
 
381
}
382
 
24595 tejbeer 383
function loadPaginatedNextItems(url, params, paginatedIdentifier,
27618 tejbeer 384
	tableIdentifier, detailsContainerIdentifier) {
24595 tejbeer 385
	var start = $("#" + paginatedIdentifier + " .start").text();
386
	var end = $("#" + paginatedIdentifier + " .end").text();
23629 ashik.ali 387
	url = context + url + "?offset=" + end;
24595 tejbeer 388
 
389
	if (params != null) {
27618 tejbeer 390
		for (var key in params) {
23629 ashik.ali 391
			if (params.hasOwnProperty(key)) {
23872 amit.gupta 392
				// console.log(key + " -> " + p[key]);
24595 tejbeer 393
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 394
			}
395
		}
396
	}
24595 tejbeer 397
 
398
	doGetAjaxRequestHandler(url, function(response) {
399
		var size = $("#" + paginatedIdentifier + " .size").text();
400
		if ((parseInt(end) + 10) > parseInt(size)) {
23629 ashik.ali 401
			console.log("(end + 10) > size == true");
24595 tejbeer 402
			$("#" + paginatedIdentifier + " .end").text(size);
403
		} else {
23629 ashik.ali 404
			console.log("(end + 10) > size == false");
24595 tejbeer 405
			$("#" + paginatedIdentifier + " .end").text(+end + +10);
23629 ashik.ali 406
		}
24595 tejbeer 407
		$("#" + paginatedIdentifier + " .start").text(+start + +10);
408
		var last = $("#" + paginatedIdentifier + " .end").text();
409
		var temp = $("#" + paginatedIdentifier + " .size").text();
410
		if (parseInt(last) >= parseInt(temp)) {
411
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
23872 amit.gupta 412
			// $( "#good-inventory-paginated .end" ).text(temp);
23629 ashik.ali 413
		}
24595 tejbeer 414
		$('#' + tableIdentifier).html(response);
415
		if (detailsContainerIdentifier != null) {
416
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 417
		}
24595 tejbeer 418
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
23629 ashik.ali 419
	});
24595 tejbeer 420
 
23629 ashik.ali 421
}
23405 amit.gupta 422
 
24595 tejbeer 423
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
27618 tejbeer 424
	tableIdentifier, detailsContainerIdentifier) {
24595 tejbeer 425
	var start = $("#" + paginatedIdentifier + " .start").text();
426
	var end = $("#" + paginatedIdentifier + " .end").text();
427
	var size = $("#" + paginatedIdentifier + " .size").text();
428
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
23629 ashik.ali 429
		var mod = parseInt(end) % 10;
24595 tejbeer 430
		end = parseInt(end) + (10 - mod);
23629 ashik.ali 431
	}
27618 tejbeer 432
	var pre = end - 10;
24595 tejbeer 433
 
23629 ashik.ali 434
	url = context + url + "?offset=" + pre;
24595 tejbeer 435
 
436
	if (params != null) {
27618 tejbeer 437
		for (var key in params) {
23629 ashik.ali 438
			if (params.hasOwnProperty(key)) {
24595 tejbeer 439
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 440
			}
441
		}
442
	}
24595 tejbeer 443
 
444
	doGetAjaxRequestHandler(url, function(response) {
445
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
446
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
447
		$('#' + tableIdentifier).html(response);
448
		if (detailsContainerIdentifier != null) {
449
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 450
		}
24595 tejbeer 451
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
452
		if (parseInt(pre) == 0) {
453
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
23629 ashik.ali 454
		}
24595 tejbeer 455
	});
456
 
23629 ashik.ali 457
}
458
 
23405 amit.gupta 459
function numberToComma(x) {
24992 tejbeer 460
 
24595 tejbeer 461
	x = x.toString();
24992 tejbeer 462
	x = x.split('.');
463
	var x1 = x[0];
25649 tejbeer 464
	var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
24992 tejbeer 465
	var lastThree = x1.substring(x1.length - 3);
25066 tejbeer 466
	var otherNumbers = x1.substring(0, x1.length - 3);
25649 tejbeer 467
	if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
25144 amit.gupta 468
		console.log(lastThree)
25649 tejbeer 469
	} else {
470
		if (otherNumbers != '')
471
			lastThree = ',' + lastThree;
25066 tejbeer 472
	}
24992 tejbeer 473
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
27618 tejbeer 474
		+ x2;
24992 tejbeer 475
 
23786 amit.gupta 476
}
23870 amit.gupta 477
 
26063 amit.gupta 478
function reporticoDRCallback(start, end) {
479
	startMoment = start;
480
	endMoment = end;
481
	startDate = start.format(moment.HTML5_FMT.DATE);
482
	endDate = end.format(moment.HTML5_FMT.DATE);
483
}
27355 tejbeer 484
// Custom formatters should be handled specifically at the controller side
23870 amit.gupta 485
function dateRangeCallback(start, end) {
23886 amit.gupta 486
	startMoment = start;
487
	endMoment = end;
488
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
489
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
23872 amit.gupta 490
}
491
 
24595 tejbeer 492
function getSingleDatePicker() {
493
	var singleDatePicker = {
27618 tejbeer 494
		"todayHighlight": true,
495
		"startDate": startMoment || moment(),
496
		"autoclose": true,
497
		"autoUpdateInput": true,
498
		"singleDatePicker": true,
499
		"locale": {
500
			'format': 'DD/MM/YYYY'
24595 tejbeer 501
		}
502
	};
23872 amit.gupta 503
	return singleDatePicker;
23886 amit.gupta 504
}
505
 
24595 tejbeer 506
function getRangedDatePicker(showRanges) {
507
	if (typeof showRanges == "undefined") {
23886 amit.gupta 508
		showRanges = false;
509
	}
24595 tejbeer 510
	var rangedDatePicker = {
27618 tejbeer 511
		"todayHighlight": true,
512
		"opens": "right",
513
		"startDate": startMoment || moment(),
514
		"endDate": endMoment || moment(),
515
		"autoclose": true,
516
		"alwaysShowCalendars": false,
517
		"autoUpdateInput": true,
518
		"locale": {
519
			'format': 'DD/MM/YYYY'
24595 tejbeer 520
		}
23886 amit.gupta 521
	};
24595 tejbeer 522
	if (showRanges) {
523
		rangedDatePicker['ranges'] = {
27618 tejbeer 524
			'Today': [moment(), moment()],
525
			'Yesterday': [moment().subtract(1, 'days'),
526
			moment().subtract(1, 'days')],
527
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
528
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
529
			'This Month': [moment().startOf('month'), moment().endOf('month')],
530
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
531
			moment()],
532
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
533
			moment()],
534
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
535
			moment()]
24595 tejbeer 536
		}
23886 amit.gupta 537
	}
538
	return rangedDatePicker;
23892 amit.gupta 539
}
23946 amit.gupta 540
function showPosition(position) {
24595 tejbeer 541
	if (typeof latitude == "undefined") {
542
		var coords = {
27618 tejbeer 543
			latitude: position.coords.latitude,
544
			longitude: position.coords.longitude
24595 tejbeer 545
		}
546
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
27618 tejbeer 547
			.stringify(coords), function() {
548
				latitude = position.coords.latitude;
549
				longitude = position.coords.longitude;
550
			});
24052 amit.gupta 551
	}
24176 amit.gupta 552
	// distance = getDistance(latitude, longitude, position.coords.latitude,
553
	// position.coords.longitude);
24168 amit.gupta 554
}
555
 
24595 tejbeer 556
function getAuthorisedWarehouses(callback) {
557
	bootBoxObj = {
27618 tejbeer 558
		size: "small",
559
		title: "Choose Warehouse",
560
		callback: callback,
561
		inputType: 'select',
562
		inputOptions: typeof inputOptions == "undefined" ? undefined
563
			: inputOptions
24168 amit.gupta 564
	}
24595 tejbeer 565
	if (typeof inputOptions == "undefined") {
566
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
27618 tejbeer 567
			response) {
24168 amit.gupta 568
			response = JSON.parse(response);
569
			inputOptions = [];
24595 tejbeer 570
			response.forEach(function(warehouse) {
24168 amit.gupta 571
				inputOptions.push({
27618 tejbeer 572
					text: warehouse.name,
573
					value: warehouse.id,
24168 amit.gupta 574
				});
575
			});
576
			bootBoxObj['inputOptions'] = inputOptions;
577
			bootbox.prompt(bootBoxObj);
578
		});
24595 tejbeer 579
	} else if (inputOptions.length == 1) {
24168 amit.gupta 580
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 581
	} else {
24168 amit.gupta 582
		bootbox.prompt(bootBoxObj);
583
	}
24595 tejbeer 584
 
24176 amit.gupta 585
}
24410 amit.gupta 586
function getColorsForItems(catalogId, itemId, description, callback) {
24595 tejbeer 587
	bootBoxObj = {
27618 tejbeer 588
		size: "small",
589
		className: "item-wrapper",
590
		title: description,
591
		callback: callback,
592
		inputType: 'checkbox',
24349 amit.gupta 593
	}
24595 tejbeer 594
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
27618 tejbeer 595
		+ catalogId + "&itemId=" + itemId, function(response) {
596
			coloredItems = JSON.parse(response);
597
			inputOptions = [{
598
				text: "All",
599
				value: "0",
600
				onclick: "toggleAll('itemIds')"
601
			}];
602
			coloredItems.forEach(function(item) {
603
				inputOptions.push({
604
					text: item.color,
605
					value: item.id,
606
					selected: item.active
607
				});
24349 amit.gupta 608
			});
27618 tejbeer 609
			bootBoxObj['inputOptions'] = inputOptions;
610
			promptObj = bootbox.prompt(bootBoxObj);
611
			promptObj.modal('show')
612
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
24595 tejbeer 613
				function(index, checkbox) {
614
					checkbox.checked = coloredItems[index].active;
615
				});
27618 tejbeer 616
		});
24406 amit.gupta 617
}
27763 tejbeer 618
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
27618 tejbeer 619
	function() {
620
		if (this.value == "0") {
621
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
622
				.slice(1).prop('checked', $(this).prop('checked'));
623
		}
624
	});
625
function getItemAheadOptions(jqElement, anyColor, callback) {
626
	console.log(anyColor)
24176 amit.gupta 627
	jqElement.typeahead('destroy').typeahead({
27618 tejbeer 628
		source: function(q, process) {
24595 tejbeer 629
			if (q.length >= 3) {
27618 tejbeer 630
				return $.ajax(context + "/item?anyColor=" + anyColor, {
631
					global: false,
632
					data: {
633
						query: q
24595 tejbeer 634
					},
27618 tejbeer 635
					success: function(data) {
24191 amit.gupta 636
						queryData = JSON.parse(data);
637
						process(queryData);
24176 amit.gupta 638
					},
639
				});
24378 amit.gupta 640
			}
24176 amit.gupta 641
		},
27618 tejbeer 642
		delay: 300,
643
		items: 20,
644
		displayText: function(item) {
24595 tejbeer 645
			return item.itemDescription;
646
		},
27618 tejbeer 647
		autoSelect: true,
648
		afterSelect: callback
24176 amit.gupta 649
	});
650
}
25394 amit.gupta 651
function getEntityAheadOptions(jqElement, callback) {
652
	jqElement.typeahead('destroy').typeahead({
27618 tejbeer 653
		source: function(q, process) {
25394 amit.gupta 654
			if (q.length >= 3) {
655
				return $.ajax(context + "/entity", {
27618 tejbeer 656
					global: false,
657
					data: {
658
						query: q
25394 amit.gupta 659
					},
27618 tejbeer 660
					success: function(data) {
25394 amit.gupta 661
						queryData = JSON.parse(data);
662
						process(queryData);
663
					},
664
				});
665
			}
666
		},
27618 tejbeer 667
		delay: 300,
668
		items: 20,
669
		displayText: function(entity) {
25394 amit.gupta 670
			return entity.title_s + "(" + entity.catalogId_i + ")";
671
		},
27618 tejbeer 672
		autoSelect: true,
673
		afterSelect: callback
25394 amit.gupta 674
	});
675
}
24349 amit.gupta 676
function getPartnerAheadOptions(jqElement, callback) {
677
	jqElement.typeahead('destroy').typeahead({
27618 tejbeer 678
		source: function(q, process) {
24595 tejbeer 679
			if (q.length >= 3) {
680
				return $.ajax(context + "/partners", {
27618 tejbeer 681
					global: false,
682
					data: {
683
						query: q
24595 tejbeer 684
					},
27618 tejbeer 685
					success: function(data) {
24349 amit.gupta 686
						queryData = JSON.parse(data);
687
						process(queryData);
688
					},
689
				});
690
			}
691
		},
27618 tejbeer 692
		delay: 300,
693
		items: 20,
694
		displayText: function(partner) {
24595 tejbeer 695
			return partner.displayName;
696
		},
27618 tejbeer 697
		autoSelect: true,
698
		afterSelect: callback
24349 amit.gupta 699
	});
700
}
24406 amit.gupta 701
 
24595 tejbeer 702
function loadPriceDrop(domId) {
703
	doGetAjaxRequestHandler(context + "/getItemDescription",
27618 tejbeer 704
		function(response) {
705
			$('#' + domId).html(response);
706
		});
24406 amit.gupta 707
}
27754 amit.gupta 708
$(document).on('click', ".price_drop", function() {
24406 amit.gupta 709
	loadPriceDrop("main-content");
24595 tejbeer 710
});
25649 tejbeer 711
 
27618 tejbeer 712
 
27696 tejbeer 713
function notifyTypeChange(messageType, $container) {
25683 tejbeer 714
	var messageQueryString = "?messageType=" + messageType;
25721 tejbeer 715
	if (messageType == null) {
25680 amit.gupta 716
		messageQueryString = "";
717
	}
27711 amit.gupta 718
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function(response) {
719
		if ($container != null) {
720
			loaderDialogObj.one('hidden.bs.modal', function(){
27696 tejbeer 721
				$container.popover({
722
					container: $container,
27824 amit.gupta 723
					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 724
					content: response,
725
					html: true,
726
					placement: "bottom",
27824 amit.gupta 727
					trigger: "manual",
728
					sanitize: false
27711 amit.gupta 729
				}).popover('show');
27826 amit.gupta 730
				setTimeout(function() {
27711 amit.gupta 731
					$container.focus().one('blur', function() {
732
						$container.popover('destroy');
733
					});
27826 amit.gupta 734
				}, 100);
27711 amit.gupta 735
			});
736
		}
737
	});
25649 tejbeer 738
}
25651 tejbeer 739
 
25689 amit.gupta 740
function downloadNotifyDocument(documentId, cid, documentName) {
25721 tejbeer 741
	doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
27618 tejbeer 742
		documentName);
25651 tejbeer 743
}