Subversion Repositories SmartDukaan

Rev

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