Subversion Repositories SmartDukaan

Rev

Rev 25740 | Rev 26140 | 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
 
26063 amit.gupta 385
function reporticoDRCallback(start, end) {
386
	startMoment = start;
387
	endMoment = end;
388
	startDate = start.format(moment.HTML5_FMT.DATE);
389
	endDate = end.format(moment.HTML5_FMT.DATE);
390
}
391
//Custom formatters should be handled specifically at the controller side
23870 amit.gupta 392
function dateRangeCallback(start, end) {
23886 amit.gupta 393
	startMoment = start;
394
	endMoment = end;
395
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
396
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
23872 amit.gupta 397
}
398
 
24595 tejbeer 399
function getSingleDatePicker() {
400
	var singleDatePicker = {
401
		"todayHighlight" : true,
402
		"startDate" : startMoment || moment(),
403
		"autoclose" : true,
404
		"autoUpdateInput" : true,
405
		"singleDatePicker" : true,
406
		"locale" : {
407
			'format' : 'DD/MM/YYYY'
408
		}
409
	};
23872 amit.gupta 410
	return singleDatePicker;
23886 amit.gupta 411
}
412
 
24595 tejbeer 413
function getRangedDatePicker(showRanges) {
414
	if (typeof showRanges == "undefined") {
23886 amit.gupta 415
		showRanges = false;
416
	}
24595 tejbeer 417
	var rangedDatePicker = {
418
		"todayHighlight" : true,
419
		"opens" : "right",
420
		"startDate" : startMoment || moment(),
421
		"endDate" : endMoment || moment(),
422
		"autoclose" : true,
423
		"alwaysShowCalendars" : false,
424
		"autoUpdateInput" : true,
425
		"locale" : {
426
			'format' : 'DD/MM/YYYY'
427
		}
23886 amit.gupta 428
	};
24595 tejbeer 429
	if (showRanges) {
430
		rangedDatePicker['ranges'] = {
431
			'Today' : [ moment(), moment() ],
432
			'Yesterday' : [ moment().subtract(1, 'days'),
433
					moment().subtract(1, 'days') ],
434
			'Last 7 Days' : [ moment().subtract(6, 'days'), moment() ],
435
			'Last 30 Days' : [ moment().subtract(29, 'days'), moment() ],
436
			'This Month' : [ moment().startOf('month'), moment().endOf('month') ],
437
			'Last Month' : [ moment().subtract(1, 'month').startOf('month'),
26063 amit.gupta 438
					moment().subtract(1, 'month').endOf('month') ],
439
			'Last 3 Months' : [ moment().subtract(1, 'month').startOf('month'),
440
			moment().subtract(3, 'month').endOf('month') ],
441
			'Last 6 Months' : [ moment().subtract(1, 'month').startOf('month'),
442
				moment().subtract(6, 'month').endOf('month') ]
24595 tejbeer 443
		}
23886 amit.gupta 444
	}
445
	return rangedDatePicker;
23892 amit.gupta 446
}
23946 amit.gupta 447
function showPosition(position) {
24595 tejbeer 448
	if (typeof latitude == "undefined") {
449
		var coords = {
450
			latitude : position.coords.latitude,
451
			longitude : position.coords.longitude
452
		}
453
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
454
				.stringify(coords), function() {
24016 amit.gupta 455
			latitude = position.coords.latitude;
456
			longitude = position.coords.longitude;
24052 amit.gupta 457
		});
458
	}
24176 amit.gupta 459
	// distance = getDistance(latitude, longitude, position.coords.latitude,
460
	// position.coords.longitude);
24168 amit.gupta 461
}
462
 
24595 tejbeer 463
function getAuthorisedWarehouses(callback) {
464
	bootBoxObj = {
465
		size : "small",
466
		title : "Choose Warehouse",
467
		callback : callback,
468
		inputType : 'select',
469
		inputOptions : typeof inputOptions == "undefined" ? undefined
470
				: inputOptions
24168 amit.gupta 471
	}
24595 tejbeer 472
	if (typeof inputOptions == "undefined") {
473
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
474
				response) {
24168 amit.gupta 475
			response = JSON.parse(response);
476
			inputOptions = [];
24595 tejbeer 477
			response.forEach(function(warehouse) {
24168 amit.gupta 478
				inputOptions.push({
24595 tejbeer 479
					text : warehouse.name,
480
					value : warehouse.id,
24168 amit.gupta 481
				});
482
			});
483
			bootBoxObj['inputOptions'] = inputOptions;
484
			bootbox.prompt(bootBoxObj);
485
		});
24595 tejbeer 486
	} else if (inputOptions.length == 1) {
24168 amit.gupta 487
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 488
	} else {
24168 amit.gupta 489
		bootbox.prompt(bootBoxObj);
490
	}
24595 tejbeer 491
 
24176 amit.gupta 492
}
24410 amit.gupta 493
function getColorsForItems(catalogId, itemId, description, callback) {
24595 tejbeer 494
	bootBoxObj = {
495
		size : "small",
496
		className : "item-wrapper",
497
		title : description,
498
		callback : callback,
499
		inputType : 'checkbox',
24349 amit.gupta 500
	}
24595 tejbeer 501
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
502
			+ catalogId + "&itemId=" + itemId, function(response) {
24406 amit.gupta 503
		coloredItems = JSON.parse(response);
24595 tejbeer 504
		inputOptions = [ {
505
			text : "All",
506
			value : "0",
507
			onclick : "toggleAll('itemIds')"
508
		} ];
509
		coloredItems.forEach(function(item) {
24406 amit.gupta 510
			inputOptions.push({
24595 tejbeer 511
				text : item.color,
512
				value : item.id,
513
				selected : item.active
24349 amit.gupta 514
			});
515
		});
24406 amit.gupta 516
		bootBoxObj['inputOptions'] = inputOptions;
24349 amit.gupta 517
		bootbox.prompt(bootBoxObj);
24595 tejbeer 518
		$('.item-wrapper').find('input[type="checkbox"]').slice(1).each(
519
				function(index, checkbox) {
520
					checkbox.checked = coloredItems[index].active;
521
				});
24406 amit.gupta 522
	});
523
}
24595 tejbeer 524
$(".item-wrapper").find("input[type='checkbox']:first").live(
525
		'change',
526
		function() {
527
			if (this.value == "0") {
528
				$(this).closest('.item-wrapper').find("input[type='checkbox']")
529
						.slice(1).prop('checked', $(this).prop('checked'));
530
			}
531
		});
24176 amit.gupta 532
function getItemAheadOptions(jqElement, callback) {
533
	jqElement.typeahead('destroy').typeahead({
24595 tejbeer 534
		source : function(q, process) {
535
			if (q.length >= 3) {
536
				return $.ajax(context + "/item", {
537
					global : false,
538
					data : {
539
						query : q
540
					},
541
					success : function(data) {
24191 amit.gupta 542
						queryData = JSON.parse(data);
543
						process(queryData);
24176 amit.gupta 544
					},
545
				});
24378 amit.gupta 546
			}
24176 amit.gupta 547
		},
24595 tejbeer 548
		delay : 400,
549
		items : 20,
550
		displayText : function(item) {
551
			return item.itemDescription;
552
		},
553
		autoSelect : true,
554
		afterSelect : callback
24176 amit.gupta 555
	});
556
}
25394 amit.gupta 557
function getEntityAheadOptions(jqElement, callback) {
558
	jqElement.typeahead('destroy').typeahead({
559
		source : function(q, process) {
560
			if (q.length >= 3) {
561
				return $.ajax(context + "/entity", {
562
					global : false,
563
					data : {
564
						query : q
565
					},
566
					success : function(data) {
567
						queryData = JSON.parse(data);
568
						process(queryData);
569
					},
570
				});
571
			}
572
		},
573
		delay : 400,
574
		items : 20,
575
		displayText : function(entity) {
576
			return entity.title_s + "(" + entity.catalogId_i + ")";
577
		},
578
		autoSelect : true,
579
		afterSelect : callback
580
	});
581
}
24349 amit.gupta 582
function getPartnerAheadOptions(jqElement, callback) {
583
	jqElement.typeahead('destroy').typeahead({
24595 tejbeer 584
		source : function(q, process) {
585
			if (q.length >= 3) {
586
				return $.ajax(context + "/partners", {
587
					global : false,
588
					data : {
589
						query : q
590
					},
591
					success : function(data) {
24349 amit.gupta 592
						queryData = JSON.parse(data);
593
						process(queryData);
594
					},
595
				});
596
			}
597
		},
24595 tejbeer 598
		delay : 300,
599
		items : 20,
600
		displayText : function(partner) {
601
			return partner.displayName;
602
		},
603
		autoSelect : true,
604
		afterSelect : callback
24349 amit.gupta 605
	});
606
}
24406 amit.gupta 607
 
24595 tejbeer 608
function loadPriceDrop(domId) {
609
	doGetAjaxRequestHandler(context + "/getItemDescription",
610
			function(response) {
611
				$('#' + domId).html(response);
612
			});
24406 amit.gupta 613
}
614
$(".price_drop").live('click', function() {
615
	loadPriceDrop("main-content");
24595 tejbeer 616
});
25649 tejbeer 617
 
25680 amit.gupta 618
function notifyTypeChange(messageType) {
25683 tejbeer 619
	var messageQueryString = "?messageType=" + messageType;
25721 tejbeer 620
	if (messageType == null) {
25680 amit.gupta 621
		messageQueryString = "";
622
	}
25721 tejbeer 623
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString,
624
			function(response) {
625
				$('.notification-container').html(response);
626
			});
25649 tejbeer 627
}
25651 tejbeer 628
 
25689 amit.gupta 629
function downloadNotifyDocument(documentId, cid, documentName) {
25721 tejbeer 630
	doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
631
			documentName);
25651 tejbeer 632
}