Subversion Repositories SmartDukaan

Rev

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