Subversion Repositories SmartDukaan

Rev

Rev 26452 | Rev 27355 | 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');
27022 amit.gupta 33
			//$('div.modal-backdrop.fade').remove();
26140 amit.gupta 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');
27022 amit.gupta 46
		//$('div.modal-backdrop.fade').remove();
26140 amit.gupta 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) {
26389 amit.gupta 234
	var url = context + '/document-upload';
24595 tejbeer 235
	doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
236
		var documentId = response.response.document_id;
237
		console.log("documentId : " + documentId);
23377 ashik.ali 238
		return documentId;
239
	});
23347 ashik.ali 240
}
241
 
24595 tejbeer 242
function doAjaxGetDownload(urlString, fileName) {
243
	console.log("fileName : " + fileName);
23343 ashik.ali 244
	doAjaxDownload(urlString, "GET", null, fileName);
22982 ashik.ali 245
}
246
 
24595 tejbeer 247
function doAjaxPostDownload(urlString, data, fileName) {
23343 ashik.ali 248
	doAjaxDownload(urlString, "POST", data, fileName);
21627 kshitij.so 249
}
250
 
24595 tejbeer 251
function doAjaxDownload(urlString, httpType, data, fileName) {
22488 ashik.ali 252
	xhttp = new XMLHttpRequest();
25093 amit.gupta 253
	if (typeof loaderDialogObj != "undefined")
254
		loaderDialogObj.modal('show');
22488 ashik.ali 255
	xhttp.onreadystatechange = function() {
24595 tejbeer 256
		var a;
257
		if (xhttp.readyState === 2) {
258
			if (xhttp.status == 200) {
259
				xhttp.responseType = "blob";
260
			} else {
261
				xhttp.responseType = "text";
262
			}
263
		} else if (xhttp.readyState === 4 && xhttp.status === 200) {
264
			// Trick for making downloadable link
26140 amit.gupta 265
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 266
				loaderDialogObj.modal('hide');
27022 amit.gupta 267
				//$('div.modal-backdrop.fade').remove();
26140 amit.gupta 268
			}
269
 
24595 tejbeer 270
			a = document.createElement('a');
271
			a.href = window.URL.createObjectURL(xhttp.response);
272
			// Give filename you wish to download
273
			a.download = fileName;
274
			a.style.display = 'none';
275
			document.body.appendChild(a);
276
			a.click();
277
		} else if (xhttp.readyState == 4 && xhttp.status === 400) {
26140 amit.gupta 278
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 279
				loaderDialogObj.modal('hide');
27022 amit.gupta 280
				//$('div.modal-backdrop.fade').remove();
26140 amit.gupta 281
			}
24595 tejbeer 282
			badRequestAlert(xhttp);
283
		} else if (xhttp.readyState == 4 && xhttp.status === 500) {
26140 amit.gupta 284
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 285
				loaderDialogObj.modal('hide');
27022 amit.gupta 286
				//$('div.modal-backdrop.fade').remove();
26140 amit.gupta 287
			}
24595 tejbeer 288
			internalServerErrorAlert(xhttp);
289
		}
22488 ashik.ali 290
	};
291
	// Post data to URL which handles post request
23343 ashik.ali 292
	xhttp.open(httpType, urlString);
24595 tejbeer 293
	if (httpType == "POST") {
23343 ashik.ali 294
		xhttp.setRequestHeader("Content-Type", "application/json");
295
	}
22488 ashik.ali 296
	// You should set responseType as blob for binary responses
23872 amit.gupta 297
	// xhttp.responseType = 'blob';
22488 ashik.ali 298
	xhttp.send(data);
23405 amit.gupta 299
}
300
 
24595 tejbeer 301
function loadPaginatedNextItems(url, params, paginatedIdentifier,
302
		tableIdentifier, detailsContainerIdentifier) {
303
	var start = $("#" + paginatedIdentifier + " .start").text();
304
	var end = $("#" + paginatedIdentifier + " .end").text();
23629 ashik.ali 305
	url = context + url + "?offset=" + end;
24595 tejbeer 306
 
307
	if (params != null) {
308
		for ( var key in params) {
23629 ashik.ali 309
			if (params.hasOwnProperty(key)) {
23872 amit.gupta 310
				// console.log(key + " -> " + p[key]);
24595 tejbeer 311
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 312
			}
313
		}
314
	}
24595 tejbeer 315
 
316
	doGetAjaxRequestHandler(url, function(response) {
317
		var size = $("#" + paginatedIdentifier + " .size").text();
318
		if ((parseInt(end) + 10) > parseInt(size)) {
23629 ashik.ali 319
			console.log("(end + 10) > size == true");
24595 tejbeer 320
			$("#" + paginatedIdentifier + " .end").text(size);
321
		} else {
23629 ashik.ali 322
			console.log("(end + 10) > size == false");
24595 tejbeer 323
			$("#" + paginatedIdentifier + " .end").text(+end + +10);
23629 ashik.ali 324
		}
24595 tejbeer 325
		$("#" + paginatedIdentifier + " .start").text(+start + +10);
326
		var last = $("#" + paginatedIdentifier + " .end").text();
327
		var temp = $("#" + paginatedIdentifier + " .size").text();
328
		if (parseInt(last) >= parseInt(temp)) {
329
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
23872 amit.gupta 330
			// $( "#good-inventory-paginated .end" ).text(temp);
23629 ashik.ali 331
		}
24595 tejbeer 332
		$('#' + tableIdentifier).html(response);
333
		if (detailsContainerIdentifier != null) {
334
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 335
		}
24595 tejbeer 336
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
23629 ashik.ali 337
	});
24595 tejbeer 338
 
23629 ashik.ali 339
}
23405 amit.gupta 340
 
24595 tejbeer 341
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
342
		tableIdentifier, detailsContainerIdentifier) {
343
	var start = $("#" + paginatedIdentifier + " .start").text();
344
	var end = $("#" + paginatedIdentifier + " .end").text();
345
	var size = $("#" + paginatedIdentifier + " .size").text();
346
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
23629 ashik.ali 347
		var mod = parseInt(end) % 10;
24595 tejbeer 348
		end = parseInt(end) + (10 - mod);
23629 ashik.ali 349
	}
350
	var pre = end - 20;
24595 tejbeer 351
 
23629 ashik.ali 352
	url = context + url + "?offset=" + pre;
24595 tejbeer 353
 
354
	if (params != null) {
355
		for ( var key in params) {
23629 ashik.ali 356
			if (params.hasOwnProperty(key)) {
24595 tejbeer 357
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 358
			}
359
		}
360
	}
24595 tejbeer 361
 
362
	doGetAjaxRequestHandler(url, function(response) {
363
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
364
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
365
		$('#' + tableIdentifier).html(response);
366
		if (detailsContainerIdentifier != null) {
367
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 368
		}
24595 tejbeer 369
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
370
		if (parseInt(pre) == 0) {
371
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
23629 ashik.ali 372
		}
24595 tejbeer 373
	});
374
 
23629 ashik.ali 375
}
376
 
23405 amit.gupta 377
function numberToComma(x) {
24992 tejbeer 378
 
24595 tejbeer 379
	x = x.toString();
24992 tejbeer 380
	x = x.split('.');
381
	var x1 = x[0];
25649 tejbeer 382
	var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
24992 tejbeer 383
	var lastThree = x1.substring(x1.length - 3);
25066 tejbeer 384
	var otherNumbers = x1.substring(0, x1.length - 3);
25649 tejbeer 385
	if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
25144 amit.gupta 386
		console.log(lastThree)
25649 tejbeer 387
	} else {
388
		if (otherNumbers != '')
389
			lastThree = ',' + lastThree;
25066 tejbeer 390
	}
24992 tejbeer 391
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
392
			+ x2;
393
 
23786 amit.gupta 394
}
23870 amit.gupta 395
 
26063 amit.gupta 396
function reporticoDRCallback(start, end) {
397
	startMoment = start;
398
	endMoment = end;
399
	startDate = start.format(moment.HTML5_FMT.DATE);
400
	endDate = end.format(moment.HTML5_FMT.DATE);
401
}
402
//Custom formatters should be handled specifically at the controller side
23870 amit.gupta 403
function dateRangeCallback(start, end) {
23886 amit.gupta 404
	startMoment = start;
405
	endMoment = end;
406
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
407
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
23872 amit.gupta 408
}
409
 
24595 tejbeer 410
function getSingleDatePicker() {
411
	var singleDatePicker = {
412
		"todayHighlight" : true,
413
		"startDate" : startMoment || moment(),
414
		"autoclose" : true,
415
		"autoUpdateInput" : true,
416
		"singleDatePicker" : true,
417
		"locale" : {
418
			'format' : 'DD/MM/YYYY'
419
		}
420
	};
23872 amit.gupta 421
	return singleDatePicker;
23886 amit.gupta 422
}
423
 
24595 tejbeer 424
function getRangedDatePicker(showRanges) {
425
	if (typeof showRanges == "undefined") {
23886 amit.gupta 426
		showRanges = false;
427
	}
24595 tejbeer 428
	var rangedDatePicker = {
429
		"todayHighlight" : true,
430
		"opens" : "right",
431
		"startDate" : startMoment || moment(),
432
		"endDate" : endMoment || moment(),
433
		"autoclose" : true,
434
		"alwaysShowCalendars" : false,
435
		"autoUpdateInput" : true,
436
		"locale" : {
437
			'format' : 'DD/MM/YYYY'
438
		}
23886 amit.gupta 439
	};
24595 tejbeer 440
	if (showRanges) {
441
		rangedDatePicker['ranges'] = {
442
			'Today' : [ moment(), moment() ],
443
			'Yesterday' : [ moment().subtract(1, 'days'),
444
					moment().subtract(1, 'days') ],
445
			'Last 7 Days' : [ moment().subtract(6, 'days'), moment() ],
446
			'Last 30 Days' : [ moment().subtract(29, 'days'), moment() ],
447
			'This Month' : [ moment().startOf('month'), moment().endOf('month') ],
448
			'Last Month' : [ moment().subtract(1, 'month').startOf('month'),
26274 amit.gupta 449
					moment()],
450
			'Last 3 Months' : [ moment().subtract(3, 'month').startOf('month'),
451
			moment()],
452
			'Last 6 Months' : [ moment().subtract(6, 'month').startOf('month'),
453
				moment()]
24595 tejbeer 454
		}
23886 amit.gupta 455
	}
456
	return rangedDatePicker;
23892 amit.gupta 457
}
23946 amit.gupta 458
function showPosition(position) {
24595 tejbeer 459
	if (typeof latitude == "undefined") {
460
		var coords = {
461
			latitude : position.coords.latitude,
462
			longitude : position.coords.longitude
463
		}
464
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
465
				.stringify(coords), function() {
24016 amit.gupta 466
			latitude = position.coords.latitude;
467
			longitude = position.coords.longitude;
24052 amit.gupta 468
		});
469
	}
24176 amit.gupta 470
	// distance = getDistance(latitude, longitude, position.coords.latitude,
471
	// position.coords.longitude);
24168 amit.gupta 472
}
473
 
24595 tejbeer 474
function getAuthorisedWarehouses(callback) {
475
	bootBoxObj = {
476
		size : "small",
477
		title : "Choose Warehouse",
478
		callback : callback,
479
		inputType : 'select',
480
		inputOptions : typeof inputOptions == "undefined" ? undefined
481
				: inputOptions
24168 amit.gupta 482
	}
24595 tejbeer 483
	if (typeof inputOptions == "undefined") {
484
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
485
				response) {
24168 amit.gupta 486
			response = JSON.parse(response);
487
			inputOptions = [];
24595 tejbeer 488
			response.forEach(function(warehouse) {
24168 amit.gupta 489
				inputOptions.push({
24595 tejbeer 490
					text : warehouse.name,
491
					value : warehouse.id,
24168 amit.gupta 492
				});
493
			});
494
			bootBoxObj['inputOptions'] = inputOptions;
495
			bootbox.prompt(bootBoxObj);
496
		});
24595 tejbeer 497
	} else if (inputOptions.length == 1) {
24168 amit.gupta 498
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 499
	} else {
24168 amit.gupta 500
		bootbox.prompt(bootBoxObj);
501
	}
24595 tejbeer 502
 
24176 amit.gupta 503
}
24410 amit.gupta 504
function getColorsForItems(catalogId, itemId, description, callback) {
24595 tejbeer 505
	bootBoxObj = {
506
		size : "small",
507
		className : "item-wrapper",
508
		title : description,
509
		callback : callback,
510
		inputType : 'checkbox',
24349 amit.gupta 511
	}
24595 tejbeer 512
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
513
			+ catalogId + "&itemId=" + itemId, function(response) {
24406 amit.gupta 514
		coloredItems = JSON.parse(response);
24595 tejbeer 515
		inputOptions = [ {
516
			text : "All",
517
			value : "0",
518
			onclick : "toggleAll('itemIds')"
519
		} ];
520
		coloredItems.forEach(function(item) {
24406 amit.gupta 521
			inputOptions.push({
24595 tejbeer 522
				text : item.color,
523
				value : item.id,
524
				selected : item.active
24349 amit.gupta 525
			});
526
		});
24406 amit.gupta 527
		bootBoxObj['inputOptions'] = inputOptions;
26452 amit.gupta 528
		promptObj = bootbox.prompt(bootBoxObj);
27022 amit.gupta 529
		promptObj.modal('show')
26451 amit.gupta 530
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
24595 tejbeer 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
		},
27022 amit.gupta 560
		delay : 300,
24595 tejbeer 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
		},
27022 amit.gupta 585
		delay : 300,
25394 amit.gupta 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
}