Subversion Repositories SmartDukaan

Rev

Rev 27696 | Rev 27711 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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