Subversion Repositories SmartDukaan

Rev

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