Subversion Repositories SmartDukaan

Rev

Rev 27355 | Rev 27618 | 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) {
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
52
			&& $('#order-details').length == 0) {
24992 tejbeer 53
		var investmentDialog = bootbox
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'
76
						}
24595 tejbeer 77
					}
24992 tejbeer 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,
93
		callback_function) {
94
	$.ajax({
95
		url : urlString,
96
		async : true,
97
		cache : false,
98
		data : params,
99
		// dataType:'json',
100
		type : httpType,
101
		success : function(response) {
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,
117
		callback_function) {
23500 ashik.ali 118
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
119
}
120
 
24595 tejbeer 121
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
122
		callback_function) {
23032 ashik.ali 123
	$.ajax({
24595 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) {
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({
24595 tejbeer 153
		url : urlString,
154
		async : true,
155
		cache : false,
156
		type : httpType,
157
		success : function(response) {
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,
187
			function(ajaxResponse) {
188
				response = ajaxResponse;
189
			});
23347 ashik.ali 190
	return response;
191
}
192
 
24595 tejbeer 193
function doAjaxUploadRequestHandler(urlString, httpType, file,
194
		callback_function) {
22982 ashik.ali 195
	var formData = new FormData();
196
	formData.append("file", file);
197
	$.ajax({
24595 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) {
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,
214
		callback_function) {
24171 govind 215
	var formData = new FormData();
216
	formData.append("file", file);
24595 tejbeer 217
	formData.append('json', new Blob([ json ]));
24171 govind 218
	$.ajax({
24595 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) {
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
}
299
 
24595 tejbeer 300
function loadPaginatedNextItems(url, params, paginatedIdentifier,
301
		tableIdentifier, detailsContainerIdentifier) {
302
	var start = $("#" + paginatedIdentifier + " .start").text();
303
	var end = $("#" + paginatedIdentifier + " .end").text();
23629 ashik.ali 304
	url = context + url + "?offset=" + end;
24595 tejbeer 305
 
306
	if (params != null) {
307
		for ( var key in params) {
23629 ashik.ali 308
			if (params.hasOwnProperty(key)) {
23872 amit.gupta 309
				// console.log(key + " -> " + p[key]);
24595 tejbeer 310
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 311
			}
312
		}
313
	}
24595 tejbeer 314
 
315
	doGetAjaxRequestHandler(url, function(response) {
316
		var size = $("#" + paginatedIdentifier + " .size").text();
317
		if ((parseInt(end) + 10) > parseInt(size)) {
23629 ashik.ali 318
			console.log("(end + 10) > size == true");
24595 tejbeer 319
			$("#" + paginatedIdentifier + " .end").text(size);
320
		} else {
23629 ashik.ali 321
			console.log("(end + 10) > size == false");
24595 tejbeer 322
			$("#" + paginatedIdentifier + " .end").text(+end + +10);
23629 ashik.ali 323
		}
24595 tejbeer 324
		$("#" + paginatedIdentifier + " .start").text(+start + +10);
325
		var last = $("#" + paginatedIdentifier + " .end").text();
326
		var temp = $("#" + paginatedIdentifier + " .size").text();
327
		if (parseInt(last) >= parseInt(temp)) {
328
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
23872 amit.gupta 329
			// $( "#good-inventory-paginated .end" ).text(temp);
23629 ashik.ali 330
		}
24595 tejbeer 331
		$('#' + tableIdentifier).html(response);
332
		if (detailsContainerIdentifier != null) {
333
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 334
		}
24595 tejbeer 335
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
23629 ashik.ali 336
	});
24595 tejbeer 337
 
23629 ashik.ali 338
}
23405 amit.gupta 339
 
24595 tejbeer 340
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
341
		tableIdentifier, detailsContainerIdentifier) {
342
	var start = $("#" + paginatedIdentifier + " .start").text();
343
	var end = $("#" + paginatedIdentifier + " .end").text();
344
	var size = $("#" + paginatedIdentifier + " .size").text();
345
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
23629 ashik.ali 346
		var mod = parseInt(end) % 10;
24595 tejbeer 347
		end = parseInt(end) + (10 - mod);
23629 ashik.ali 348
	}
349
	var pre = end - 20;
24595 tejbeer 350
 
23629 ashik.ali 351
	url = context + url + "?offset=" + pre;
24595 tejbeer 352
 
353
	if (params != null) {
354
		for ( var key in params) {
23629 ashik.ali 355
			if (params.hasOwnProperty(key)) {
24595 tejbeer 356
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 357
			}
358
		}
359
	}
24595 tejbeer 360
 
361
	doGetAjaxRequestHandler(url, function(response) {
362
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
363
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
364
		$('#' + tableIdentifier).html(response);
365
		if (detailsContainerIdentifier != null) {
366
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 367
		}
24595 tejbeer 368
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
369
		if (parseInt(pre) == 0) {
370
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
23629 ashik.ali 371
		}
24595 tejbeer 372
	});
373
 
23629 ashik.ali 374
}
375
 
23405 amit.gupta 376
function numberToComma(x) {
24992 tejbeer 377
 
24595 tejbeer 378
	x = x.toString();
24992 tejbeer 379
	x = x.split('.');
380
	var x1 = x[0];
25649 tejbeer 381
	var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
24992 tejbeer 382
	var lastThree = x1.substring(x1.length - 3);
25066 tejbeer 383
	var otherNumbers = x1.substring(0, x1.length - 3);
25649 tejbeer 384
	if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
25144 amit.gupta 385
		console.log(lastThree)
25649 tejbeer 386
	} else {
387
		if (otherNumbers != '')
388
			lastThree = ',' + lastThree;
25066 tejbeer 389
	}
24992 tejbeer 390
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
391
			+ x2;
392
 
23786 amit.gupta 393
}
23870 amit.gupta 394
 
26063 amit.gupta 395
function reporticoDRCallback(start, end) {
396
	startMoment = start;
397
	endMoment = end;
398
	startDate = start.format(moment.HTML5_FMT.DATE);
399
	endDate = end.format(moment.HTML5_FMT.DATE);
400
}
27355 tejbeer 401
// Custom formatters should be handled specifically at the controller side
23870 amit.gupta 402
function dateRangeCallback(start, end) {
23886 amit.gupta 403
	startMoment = start;
404
	endMoment = end;
405
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
406
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
23872 amit.gupta 407
}
408
 
24595 tejbeer 409
function getSingleDatePicker() {
410
	var singleDatePicker = {
411
		"todayHighlight" : true,
412
		"startDate" : startMoment || moment(),
413
		"autoclose" : true,
414
		"autoUpdateInput" : true,
415
		"singleDatePicker" : true,
416
		"locale" : {
417
			'format' : 'DD/MM/YYYY'
418
		}
419
	};
23872 amit.gupta 420
	return singleDatePicker;
23886 amit.gupta 421
}
422
 
24595 tejbeer 423
function getRangedDatePicker(showRanges) {
424
	if (typeof showRanges == "undefined") {
23886 amit.gupta 425
		showRanges = false;
426
	}
24595 tejbeer 427
	var rangedDatePicker = {
428
		"todayHighlight" : true,
429
		"opens" : "right",
430
		"startDate" : startMoment || moment(),
431
		"endDate" : endMoment || moment(),
432
		"autoclose" : true,
433
		"alwaysShowCalendars" : false,
434
		"autoUpdateInput" : true,
435
		"locale" : {
436
			'format' : 'DD/MM/YYYY'
437
		}
23886 amit.gupta 438
	};
24595 tejbeer 439
	if (showRanges) {
440
		rangedDatePicker['ranges'] = {
441
			'Today' : [ moment(), moment() ],
442
			'Yesterday' : [ moment().subtract(1, 'days'),
443
					moment().subtract(1, 'days') ],
444
			'Last 7 Days' : [ moment().subtract(6, 'days'), moment() ],
445
			'Last 30 Days' : [ moment().subtract(29, 'days'), moment() ],
446
			'This Month' : [ moment().startOf('month'), moment().endOf('month') ],
447
			'Last Month' : [ moment().subtract(1, 'month').startOf('month'),
27355 tejbeer 448
					moment() ],
26274 amit.gupta 449
			'Last 3 Months' : [ moment().subtract(3, 'month').startOf('month'),
27355 tejbeer 450
					moment() ],
26274 amit.gupta 451
			'Last 6 Months' : [ moment().subtract(6, 'month').startOf('month'),
27355 tejbeer 452
					moment() ]
24595 tejbeer 453
		}
23886 amit.gupta 454
	}
455
	return rangedDatePicker;
23892 amit.gupta 456
}
23946 amit.gupta 457
function showPosition(position) {
24595 tejbeer 458
	if (typeof latitude == "undefined") {
459
		var coords = {
460
			latitude : position.coords.latitude,
461
			longitude : position.coords.longitude
462
		}
463
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
464
				.stringify(coords), function() {
24016 amit.gupta 465
			latitude = position.coords.latitude;
466
			longitude = position.coords.longitude;
24052 amit.gupta 467
		});
468
	}
24176 amit.gupta 469
	// distance = getDistance(latitude, longitude, position.coords.latitude,
470
	// position.coords.longitude);
24168 amit.gupta 471
}
472
 
24595 tejbeer 473
function getAuthorisedWarehouses(callback) {
474
	bootBoxObj = {
475
		size : "small",
476
		title : "Choose Warehouse",
477
		callback : callback,
478
		inputType : 'select',
479
		inputOptions : typeof inputOptions == "undefined" ? undefined
480
				: inputOptions
24168 amit.gupta 481
	}
24595 tejbeer 482
	if (typeof inputOptions == "undefined") {
483
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
484
				response) {
24168 amit.gupta 485
			response = JSON.parse(response);
486
			inputOptions = [];
24595 tejbeer 487
			response.forEach(function(warehouse) {
24168 amit.gupta 488
				inputOptions.push({
24595 tejbeer 489
					text : warehouse.name,
490
					value : warehouse.id,
24168 amit.gupta 491
				});
492
			});
493
			bootBoxObj['inputOptions'] = inputOptions;
494
			bootbox.prompt(bootBoxObj);
495
		});
24595 tejbeer 496
	} else if (inputOptions.length == 1) {
24168 amit.gupta 497
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 498
	} else {
24168 amit.gupta 499
		bootbox.prompt(bootBoxObj);
500
	}
24595 tejbeer 501
 
24176 amit.gupta 502
}
24410 amit.gupta 503
function getColorsForItems(catalogId, itemId, description, callback) {
24595 tejbeer 504
	bootBoxObj = {
505
		size : "small",
506
		className : "item-wrapper",
507
		title : description,
508
		callback : callback,
509
		inputType : 'checkbox',
24349 amit.gupta 510
	}
24595 tejbeer 511
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
512
			+ catalogId + "&itemId=" + itemId, function(response) {
24406 amit.gupta 513
		coloredItems = JSON.parse(response);
24595 tejbeer 514
		inputOptions = [ {
515
			text : "All",
516
			value : "0",
517
			onclick : "toggleAll('itemIds')"
518
		} ];
519
		coloredItems.forEach(function(item) {
24406 amit.gupta 520
			inputOptions.push({
24595 tejbeer 521
				text : item.color,
522
				value : item.id,
523
				selected : item.active
24349 amit.gupta 524
			});
525
		});
24406 amit.gupta 526
		bootBoxObj['inputOptions'] = inputOptions;
26452 amit.gupta 527
		promptObj = bootbox.prompt(bootBoxObj);
27022 amit.gupta 528
		promptObj.modal('show')
26451 amit.gupta 529
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
24595 tejbeer 530
				function(index, checkbox) {
531
					checkbox.checked = coloredItems[index].active;
532
				});
24406 amit.gupta 533
	});
534
}
24595 tejbeer 535
$(".item-wrapper").find("input[type='checkbox']:first").live(
536
		'change',
537
		function() {
538
			if (this.value == "0") {
539
				$(this).closest('.item-wrapper').find("input[type='checkbox']")
540
						.slice(1).prop('checked', $(this).prop('checked'));
541
			}
542
		});
24176 amit.gupta 543
function getItemAheadOptions(jqElement, callback) {
544
	jqElement.typeahead('destroy').typeahead({
24595 tejbeer 545
		source : function(q, process) {
546
			if (q.length >= 3) {
547
				return $.ajax(context + "/item", {
548
					global : false,
549
					data : {
550
						query : q
551
					},
552
					success : function(data) {
24191 amit.gupta 553
						queryData = JSON.parse(data);
554
						process(queryData);
24176 amit.gupta 555
					},
556
				});
24378 amit.gupta 557
			}
24176 amit.gupta 558
		},
27022 amit.gupta 559
		delay : 300,
24595 tejbeer 560
		items : 20,
561
		displayText : function(item) {
562
			return item.itemDescription;
563
		},
564
		autoSelect : true,
565
		afterSelect : callback
24176 amit.gupta 566
	});
567
}
25394 amit.gupta 568
function getEntityAheadOptions(jqElement, callback) {
569
	jqElement.typeahead('destroy').typeahead({
570
		source : function(q, process) {
571
			if (q.length >= 3) {
572
				return $.ajax(context + "/entity", {
573
					global : false,
574
					data : {
575
						query : q
576
					},
577
					success : function(data) {
578
						queryData = JSON.parse(data);
579
						process(queryData);
580
					},
581
				});
582
			}
583
		},
27022 amit.gupta 584
		delay : 300,
25394 amit.gupta 585
		items : 20,
586
		displayText : function(entity) {
587
			return entity.title_s + "(" + entity.catalogId_i + ")";
588
		},
589
		autoSelect : true,
590
		afterSelect : callback
591
	});
592
}
24349 amit.gupta 593
function getPartnerAheadOptions(jqElement, callback) {
594
	jqElement.typeahead('destroy').typeahead({
24595 tejbeer 595
		source : function(q, process) {
596
			if (q.length >= 3) {
597
				return $.ajax(context + "/partners", {
598
					global : false,
599
					data : {
600
						query : q
601
					},
602
					success : function(data) {
24349 amit.gupta 603
						queryData = JSON.parse(data);
604
						process(queryData);
605
					},
606
				});
607
			}
608
		},
24595 tejbeer 609
		delay : 300,
610
		items : 20,
611
		displayText : function(partner) {
612
			return partner.displayName;
613
		},
614
		autoSelect : true,
615
		afterSelect : callback
24349 amit.gupta 616
	});
617
}
24406 amit.gupta 618
 
24595 tejbeer 619
function loadPriceDrop(domId) {
620
	doGetAjaxRequestHandler(context + "/getItemDescription",
621
			function(response) {
622
				$('#' + domId).html(response);
623
			});
24406 amit.gupta 624
}
625
$(".price_drop").live('click', function() {
626
	loadPriceDrop("main-content");
24595 tejbeer 627
});
25649 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
}