Subversion Repositories SmartDukaan

Rev

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