Subversion Repositories SmartDukaan

Rev

Rev 30587 | Rev 30694 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30587 Rev 30599
Line 26... Line 26...
26
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
26
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
27
		+ errorObject.rejectedValue + '\n' + 'message : '
27
		+ errorObject.rejectedValue + '\n' + 'message : '
28
		+ errorObject.message);
28
		+ errorObject.message);
29
}
29
}
30
 
30
 
31
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
31
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
32
	if (typeof loaderDialogObj != "undefined") {
32
	if (typeof loaderDialogObj != "undefined") {
33
		loaderDialogObj.modal('hide');
33
		loaderDialogObj.modal('hide');
34
		// $('div.modal-backdrop.fade').remove();
34
		// $('div.modal-backdrop.fade').remove();
35
	}
35
	}
36
	if (jqxhr.status == 400) {
36
	if (jqxhr.status == 400) {
Line 39... Line 39...
39
	} else {
39
	} else {
40
		internalServerErrorAlert(jqxhr);
40
		internalServerErrorAlert(jqxhr);
41
	}
41
	}
42
});
42
});
43
 
43
 
44
$(document).ajaxComplete(function() {
44
$(document).ajaxComplete(function () {
45
	if (typeof loaderDialogObj != "undefined") {
45
	if (typeof loaderDialogObj != "undefined") {
46
		loaderDialogObj.modal('hide');
46
		loaderDialogObj.modal('hide');
47
		// $('div.modal-backdrop.fade').remove();
47
		// $('div.modal-backdrop.fade').remove();
48
	}
48
	}
49
});
49
});
Line 54... Line 54...
54
}
54
}
55
 
55
 
56
$(document).ajaxStart(ajaxStartHandler);
56
$(document).ajaxStart(ajaxStartHandler);
57
 
57
 
58
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
58
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
59
	callback_function) {
59
										callback_function) {
60
	$.ajax({
60
	$.ajax({
61
		url: urlString,
61
		url: urlString,
62
		async: true,
62
		async: true,
63
		cache: false,
63
		cache: false,
64
		data: params,
64
		data: params,
65
		// dataType:'json',
65
		// dataType:'json',
66
		type: httpType,
66
		type: httpType,
67
		success: function(response) {
67
		success: function (response) {
68
			callback_function(response);
68
			callback_function(response);
69
			$('.currency').each(function(index, ele) {
69
			$('.currency').each(function (index, ele) {
70
				if (!isNaN(parseInt($(ele).html()))) {
70
				if (!isNaN(parseInt($(ele).html()))) {
71
					$(ele).html(numberToComma($(ele).html()));
71
					$(ele).html(numberToComma($(ele).html()));
72
				}
72
				}
73
			});
73
			});
74
		}
74
		}
Line 78... Line 78...
78
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
78
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
79
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
79
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
80
}
80
}
81
 
81
 
82
function doPostAjaxRequestWithParamsHandler(urlString, params,
82
function doPostAjaxRequestWithParamsHandler(urlString, params,
83
	callback_function) {
83
											callback_function) {
84
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
84
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
85
}
85
}
86
 
86
 
87
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
87
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
88
	callback_function) {
88
									  callback_function) {
89
	$.ajax({
89
	$.ajax({
90
		url: urlString,
90
		url: urlString,
91
		async: true,
91
		async: true,
92
		cache: false,
92
		cache: false,
93
		processData: false,
93
		processData: false,
94
		data: json,
94
		data: json,
95
		contentType: 'application/json',
95
		contentType: 'application/json',
96
		type: httpType,
96
		type: httpType,
97
		success: function(response) {
97
		success: function (response) {
98
			// console.log("response"+JSON.stringify(data));
98
			// console.log("response"+JSON.stringify(data));
99
			callback_function(response);
99
			callback_function(response);
100
			$('.currency').each(function(index, ele) {
100
			$('.currency').each(function (index, ele) {
101
				if (!isNaN(parseInt($(ele).html()))) {
101
				if (!isNaN(parseInt($(ele).html()))) {
102
					$(ele).html(numberToComma($(ele).html()));
102
					$(ele).html(numberToComma($(ele).html()));
103
				}
103
				}
104
			});
104
			});
105
		}
105
		}
Line 118... Line 118...
118
	$.ajax({
118
	$.ajax({
119
		url: urlString,
119
		url: urlString,
120
		async: true,
120
		async: true,
121
		cache: false,
121
		cache: false,
122
		type: httpType,
122
		type: httpType,
123
		success: function(response) {
123
		success: function (response) {
124
			callback_function(response);
124
			callback_function(response);
125
			$('.currency').each(function(index, ele) {
125
			$('.currency').each(function (index, ele) {
126
				if (!isNaN(parseInt($(ele).html()))) {
126
				if (!isNaN(parseInt($(ele).html()))) {
127
					$(ele).html(numberToComma($(ele).html()));
127
					$(ele).html(numberToComma($(ele).html()));
128
				}
128
				}
129
			});
129
			});
130
		}
130
		}
Line 148... Line 148...
148
}
148
}
149
 
149
 
150
function doAjaxUploadRequest(urlString, httpType, file) {
150
function doAjaxUploadRequest(urlString, httpType, file) {
151
	var response;
151
	var response;
152
	doAjaxUploadRequestHandler(urlString, httpType, file,
152
	doAjaxUploadRequestHandler(urlString, httpType, file,
153
		function(ajaxResponse) {
153
		function (ajaxResponse) {
154
			response = ajaxResponse;
154
			response = ajaxResponse;
155
		});
155
		});
156
	return response;
156
	return response;
157
}
157
}
158
 
158
 
159
function doAjaxUploadRequestHandler(urlString, httpType, file,
159
function doAjaxUploadRequestHandler(urlString, httpType, file,
160
	callback_function) {
160
									callback_function) {
161
	var formData = new FormData();
161
	var formData = new FormData();
162
	formData.append("file", file);
162
	formData.append("file", file);
163
	$.ajax({
163
	$.ajax({
164
		url: urlString,
164
		url: urlString,
165
		type: httpType,
165
		type: httpType,
Line 168... Line 168...
168
		async: true,
168
		async: true,
169
		cache: false,
169
		cache: false,
170
		contentType: false,
170
		contentType: false,
171
		enctype: 'multipart/form-data',
171
		enctype: 'multipart/form-data',
172
		processData: false,
172
		processData: false,
173
		success: function(response) {
173
		success: function (response) {
174
			// console.log("response"+JSON.stringify(data));
174
			// console.log("response"+JSON.stringify(data));
175
			callback_function(response);
175
			callback_function(response);
176
		}
176
		}
177
	});
177
	});
178
}
178
}
179
 
179
 
180
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
180
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
181
	callback_function) {
181
										callback_function) {
182
	var formData = new FormData();
182
	var formData = new FormData();
183
	formData.append("file", file);
183
	formData.append("file", file);
184
	formData.append('json', new Blob([json]));
184
	formData.append('json', new Blob([json]));
185
	$.ajax({
185
	$.ajax({
186
		url: urlString,
186
		url: urlString,
187
		type: httpType,
187
		type: httpType,
188
		data: formData,
188
		data: formData,
189
		enctype: 'multipart/form-data',
189
		enctype: 'multipart/form-data',
190
		contentType: false,
190
		contentType: false,
191
		processData: false,
191
		processData: false,
192
		success: function(response) {
192
		success: function (response) {
193
			// console.log("response"+JSON.stringify(data));
193
			// console.log("response"+JSON.stringify(data));
194
			callback_function(response);
194
			callback_function(response);
195
		}
195
		}
196
	});
196
	});
197
}
197
}
198
 
198
 
199
function uploadDocument(file) {
199
function uploadDocument(file) {
200
	var url = context + '/document-upload';
200
	var url = context + '/document-upload';
201
	doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
201
	doAjaxUploadRequestHandler(url, 'POST', file, function (response) {
202
		var documentId = response.response.document_id;
202
		var documentId = response.response.document_id;
203
		console.log("documentId : " + documentId);
203
		console.log("documentId : " + documentId);
204
		return documentId;
204
		return documentId;
205
	});
205
	});
206
}
206
}
Line 216... Line 216...
216
 
216
 
217
function doAjaxDownload(urlString, httpType, data, fileName) {
217
function doAjaxDownload(urlString, httpType, data, fileName) {
218
	xhttp = new XMLHttpRequest();
218
	xhttp = new XMLHttpRequest();
219
	if (typeof loaderDialogObj != "undefined")
219
	if (typeof loaderDialogObj != "undefined")
220
		loaderDialogObj.modal('show');
220
		loaderDialogObj.modal('show');
221
	xhttp.onreadystatechange = function() {
221
	xhttp.onreadystatechange = function () {
222
		var a;
222
		var a;
223
		if (xhttp.readyState === 2) {
223
		if (xhttp.readyState === 2) {
224
			if (xhttp.status == 200) {
224
			if (xhttp.status == 200) {
225
				xhttp.responseType = "blob";
225
				xhttp.responseType = "blob";
226
			} else {
226
			} else {
Line 263... Line 263...
263
	// xhttp.responseType = 'blob';
263
	// xhttp.responseType = 'blob';
264
	xhttp.send(data);
264
	xhttp.send(data);
265
}
265
}
266
 
266
 
267
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
267
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
268
	tableIdentifier, detailsContainerIdentifier) {
268
									   tableIdentifier, detailsContainerIdentifier) {
269
	var start = $("#" + paginatedIdentifier + " .start").text();
269
	var start = $("#" + paginatedIdentifier + " .start").text();
270
 
270
 
271
	var end = $("#" + paginatedIdentifier + " .end").text();
271
	var end = $("#" + paginatedIdentifier + " .end").text();
272
 
272
 
273
	url = context + url + "?offset=" + end;
273
	url = context + url + "?offset=" + end;
Line 279... Line 279...
279
				url = url + "&" + key + "=" + params[key];
279
				url = url + "&" + key + "=" + params[key];
280
			}
280
			}
281
		}
281
		}
282
	}
282
	}
283
 
283
 
284
	doGetAjaxRequestHandler(url, function(response) {
284
	doGetAjaxRequestHandler(url, function (response) {
285
		var size = $("#" + paginatedIdentifier + " .size").text();
285
		var size = $("#" + paginatedIdentifier + " .size").text();
286
		if ((parseInt(end) + 20) > parseInt(size)) {
286
		if ((parseInt(end) + 20) > parseInt(size)) {
287
			// console.log("(end + 10) > size == true");
287
			// console.log("(end + 10) > size == true");
288
			$("#" + paginatedIdentifier + " .end").text(size);
288
			$("#" + paginatedIdentifier + " .end").text(size);
289
		} else {
289
		} else {
Line 306... Line 306...
306
	});
306
	});
307
 
307
 
308
}
308
}
309
 
309
 
310
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
310
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
311
	tableIdentifier, detailsContainerIdentifier) {
311
										  tableIdentifier, detailsContainerIdentifier) {
312
	var start = $("#" + paginatedIdentifier + " .start").text();
312
	var start = $("#" + paginatedIdentifier + " .start").text();
313
	console.log("start" + start);
313
	console.log("start" + start);
314
	var end = $("#" + paginatedIdentifier + " .end").text();
314
	var end = $("#" + paginatedIdentifier + " .end").text();
315
	console.log("Startend" + end);
315
	console.log("Startend" + end);
316
	var size = $("#" + paginatedIdentifier + " .size").text();
316
	var size = $("#" + paginatedIdentifier + " .size").text();
Line 331... Line 331...
331
				url = url + "&" + key + "=" + params[key];
331
				url = url + "&" + key + "=" + params[key];
332
			}
332
			}
333
		}
333
		}
334
	}
334
	}
335
 
335
 
336
	doGetAjaxRequestHandler(url, function(response) {
336
	doGetAjaxRequestHandler(url, function (response) {
337
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
337
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
338
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
338
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
339
		$('#' + tableIdentifier).html(response);
339
		$('#' + tableIdentifier).html(response);
340
		if (detailsContainerIdentifier != null) {
340
		if (detailsContainerIdentifier != null) {
341
			$('#' + detailsContainerIdentifier).html('');
341
			$('#' + detailsContainerIdentifier).html('');
Line 347... Line 347...
347
	});
347
	});
348
 
348
 
349
}
349
}
350
 
350
 
351
function loadPaginatedNextItems(url, params, paginatedIdentifier,
351
function loadPaginatedNextItems(url, params, paginatedIdentifier,
352
	tableIdentifier, detailsContainerIdentifier) {
352
								tableIdentifier, detailsContainerIdentifier) {
353
	var start = $("#" + paginatedIdentifier + " .start").text();
353
	var start = $("#" + paginatedIdentifier + " .start").text();
354
	var end = $("#" + paginatedIdentifier + " .end").text();
354
	var end = $("#" + paginatedIdentifier + " .end").text();
355
	url = context + url + "?offset=" + end;
355
	url = context + url + "?offset=" + end;
356
 
356
 
357
	if (params != null) {
357
	if (params != null) {
Line 361... Line 361...
361
				url = url + "&" + key + "=" + params[key];
361
				url = url + "&" + key + "=" + params[key];
362
			}
362
			}
363
		}
363
		}
364
	}
364
	}
365
 
365
 
366
	doGetAjaxRequestHandler(url, function(response) {
366
	doGetAjaxRequestHandler(url, function (response) {
367
		var size = $("#" + paginatedIdentifier + " .size").text();
367
		var size = $("#" + paginatedIdentifier + " .size").text();
368
		if ((parseInt(end) + 10) > parseInt(size)) {
368
		if ((parseInt(end) + 10) > parseInt(size)) {
369
			console.log("(end + 10) > size == true");
369
			console.log("(end + 10) > size == true");
370
			$("#" + paginatedIdentifier + " .end").text(size);
370
			$("#" + paginatedIdentifier + " .end").text(size);
371
		} else {
371
		} else {
Line 387... Line 387...
387
	});
387
	});
388
 
388
 
389
}
389
}
390
 
390
 
391
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
391
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
392
	tableIdentifier, detailsContainerIdentifier) {
392
									tableIdentifier, detailsContainerIdentifier) {
393
	var start = $("#" + paginatedIdentifier + " .start").text();
393
	var start = $("#" + paginatedIdentifier + " .start").text();
394
	var end = $("#" + paginatedIdentifier + " .end").text();
394
	var end = $("#" + paginatedIdentifier + " .end").text();
395
	var size = $("#" + paginatedIdentifier + " .size").text();
395
	var size = $("#" + paginatedIdentifier + " .size").text();
396
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
396
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
397
		var mod = parseInt(end) % 10;
397
		var mod = parseInt(end) % 10;
Line 407... Line 407...
407
				url = url + "&" + key + "=" + params[key];
407
				url = url + "&" + key + "=" + params[key];
408
			}
408
			}
409
		}
409
		}
410
	}
410
	}
411
 
411
 
412
	doGetAjaxRequestHandler(url, function(response) {
412
	doGetAjaxRequestHandler(url, function (response) {
413
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
413
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
414
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
414
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
415
		$('#' + tableIdentifier).html(response);
415
		$('#' + tableIdentifier).html(response);
416
		if (detailsContainerIdentifier != null) {
416
		if (detailsContainerIdentifier != null) {
417
			$('#' + detailsContainerIdentifier).html('');
417
			$('#' + detailsContainerIdentifier).html('');
Line 441... Line 441...
441
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
441
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
442
		+ x2;
442
		+ x2;
443
 
443
 
444
}
444
}
445
 
445
 
446
function reporticoDRCallback(start, end) {
-
 
447
	startMoment = start;
-
 
448
	endMoment = end;
-
 
449
	startDate = start.format(moment.HTML5_FMT.DATE);
-
 
450
	endDate = end.format(moment.HTML5_FMT.DATE);
-
 
451
}
-
 
452
 
-
 
453
// Custom formatters should be handled specifically at the controller side
-
 
454
function dateRangeCallback(start, end) {
-
 
455
	startMoment = start;
-
 
456
	endMoment = end;
-
 
457
	startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
-
 
458
	endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
-
 
459
}
-
 
460
 
-
 
461
function dateRangeCallBackFn(identifier) {
-
 
462
	return function(start, end) {
-
 
463
		statMoment = startMoment || {};
-
 
464
		endMoment = endMoment || {};
-
 
465
		startDate = startDate || {};
-
 
466
		endDate = endDate || {};
-
 
467
		startMoment[identifier] = start;
-
 
468
		endMoment[identifier] = end;
-
 
469
		startDate[identifier] = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
-
 
470
		endDate[identifier] = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
-
 
471
	}
-
 
472
}
-
 
473
 
-
 
474
function getSingleDatePicker() {
446
function getSingleDatePicker(startMoment) {
475
	var singleDatePicker = {
447
	var singleDatePicker = {
476
		"todayHighlight": true,
448
		"todayHighlight": true,
477
		"startDate": startMoment || moment(),
449
		"startDate": startMoment || moment(),
478
		"autoclose": true,
450
		"autoclose": true,
479
		"autoUpdateInput": true,
451
		"autoUpdateInput": true,
Line 483... Line 455...
483
		}
455
		}
484
	};
456
	};
485
	return singleDatePicker;
457
	return singleDatePicker;
486
}
458
}
487
 
459
 
-
 
460
function getDatesFromPicker(pickerElement) {
-
 
461
	return {
-
 
462
		startDate: $(pickerElement).data('daterangepicker').startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS),
-
 
463
		endDate: $(pickerElement).data('daterangepicker').endDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS)
-
 
464
	}
-
 
465
}
-
 
466
 
-
 
467
function getReporticoDatesFromPicker(pickerElement) {
-
 
468
	let datePickerData = $(pickerElement).data('daterangepicker');
-
 
469
	let formattedEndDate = null;
-
 
470
	if (typeof datePickerData.endDate == "object") {
-
 
471
		formattedEndDate = datePickerData.endDate.format(moment.HTML5_FMT.DATE);
-
 
472
	}
-
 
473
	return {
-
 
474
		startDate: datePickerData.startDate.format(moment.HTML5_FMT.DATE),
-
 
475
		endDate: formattedEndDate
-
 
476
	};
-
 
477
}
-
 
478
 
-
 
479
 
488
function getRangedDatePicker(showRanges) {
480
function getRangedDatePicker(showRanges, startMoment, endMoment) {
489
	if (typeof showRanges == "undefined") {
481
	if (typeof showRanges == "undefined") {
490
		showRanges = false;
482
		showRanges = false;
491
	}
483
	}
492
	var rangedDatePicker = {
484
	var rangedDatePicker = {
493
		"todayHighlight": true,
485
		"todayHighlight": true,
494
		"opens": "right",
486
		"opens": "right",
495
		"startDate": moment().startOf('day'),
487
		"startDate": startMoment || moment().startOf('day'),
496
		"endDate": moment().endOf('day'),
488
		"endDate": endMoment || moment().endOf('day'),
497
		"autoclose": true,
489
		"autoclose": true,
498
		"alwaysShowCalendars": false,
490
		"alwaysShowCalendars": false,
499
		"autoUpdateInput": true,
491
		"autoUpdateInput": true,
500
		"locale": {
492
		"locale": {
501
			'format': 'DD/MM/YYYY'
493
			'format': 'DD/MM/YYYY'
Line 503... Line 495...
503
	};
495
	};
504
	if (showRanges) {
496
	if (showRanges) {
505
		rangedDatePicker['ranges'] = {
497
		rangedDatePicker['ranges'] = {
506
			'Today': [moment(), moment()],
498
			'Today': [moment(), moment()],
507
			'Yesterday': [moment().subtract(1, 'days'),
499
			'Yesterday': [moment().subtract(1, 'days'),
508
			moment().subtract(1, 'days')],
500
				moment().subtract(1, 'days')],
509
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
501
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
510
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
502
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
511
			'This Month': [moment().startOf('month'), moment().endOf('month')],
503
			'This Month': [moment().startOf('month'), moment().endOf('month')],
512
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
504
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
513
			moment()],
505
				moment()],
514
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
506
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
515
			moment()],
507
				moment()],
516
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
508
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
517
			moment()]
509
				moment()]
518
		}
510
		}
519
	}
511
	}
520
	return rangedDatePicker;
512
	return rangedDatePicker;
521
}
513
}
522
 
514
 
Line 525... Line 517...
525
		var coords = {
517
		var coords = {
526
			latitude: position.coords.latitude,
518
			latitude: position.coords.latitude,
527
			longitude: position.coords.longitude
519
			longitude: position.coords.longitude
528
		}
520
		}
529
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
521
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
530
			.stringify(coords), function() {
522
			.stringify(coords), function () {
531
				latitude = position.coords.latitude;
523
			latitude = position.coords.latitude;
532
				longitude = position.coords.longitude;
524
			longitude = position.coords.longitude;
533
			});
525
		});
534
	}
526
	}
535
	// distance = getDistance(latitude, longitude, position.coords.latitude,
527
	// distance = getDistance(latitude, longitude, position.coords.latitude,
536
	// position.coords.longitude);
528
	// position.coords.longitude);
537
}
529
}
538
 
530
 
Line 544... Line 536...
544
		inputType: 'select',
536
		inputType: 'select',
545
		inputOptions: typeof inputOptions == "undefined" ? undefined
537
		inputOptions: typeof inputOptions == "undefined" ? undefined
546
			: inputOptions
538
			: inputOptions
547
	}
539
	}
548
	if (typeof inputOptions == "undefined") {
540
	if (typeof inputOptions == "undefined") {
549
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
541
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
550
			response) {
542
			response) {
551
			response = JSON.parse(response);
543
			response = JSON.parse(response);
552
			inputOptions = [];
544
			inputOptions = [];
553
			response.forEach(function(warehouse) {
545
			response.forEach(function (warehouse) {
554
				inputOptions.push({
546
				inputOptions.push({
555
					text: warehouse.name,
547
					text: warehouse.name,
556
					value: warehouse.id,
548
					value: warehouse.id,
557
				});
549
				});
558
			});
550
			});
Line 571... Line 563...
571
	colorCheckboxHandler(catalogId, itemId, description, callback);
563
	colorCheckboxHandler(catalogId, itemId, description, callback);
572
}
564
}
573
 
565
 
574
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
566
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
575
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
567
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
576
		+ catalogId + "&itemId=" + itemId, function(response) {
568
		+ catalogId + "&itemId=" + itemId, function (response) {
577
			let coloredItems = JSON.parse(response);
569
		let coloredItems = JSON.parse(response);
578
			let modalBody = [];
570
		let modalBody = [];
579
			coloredItems.forEach(function(item) {
571
		coloredItems.forEach(function (item) {
580
				modalBody.push(`
572
			modalBody.push(`
581
                <div class="row">
573
                <div class="row">
582
                    <div class="col-sm-2">
574
                    <div class="col-sm-2">
583
                        ${item.color}
575
                        ${item.color}
584
                    </div>
576
                    </div>
585
                    <div class="col-sm-2">
577
                    <div class="col-sm-2">
586
                            <input data-itemid="${item.id}" type="text" class="form-control" />
578
                            <input data-itemid="${item.id}" type="text" class="form-control" />
587
                    </div>
579
                    </div>
588
                </div>
580
                </div>
589
            `);
581
            `);
590
			});
582
		});
591
			let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
583
		let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
592
                              <div class="modal-dialog" >
584
                              <div class="modal-dialog" >
593
                                <div class="modal-content">
585
                                <div class="modal-content">
594
                                  <div class="modal-header">
586
                                  <div class="modal-header">
595
                                    <h5 class="modal-title">${title}</h5>
587
                                    <h5 class="modal-title">${title}</h5>
596
                                  </div>
588
                                  </div>
Line 601... Line 593...
601
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
593
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
602
                                  </div>
594
                                  </div>
603
                                </div>
595
                                </div>
604
                              </div>
596
                              </div>
605
                            </div>`;
597
                            </div>`;
606
			let $dialog = $(dialogBoxHtml);
598
		let $dialog = $(dialogBoxHtml);
607
			let modalObj = $dialog.modal('show');
599
		let modalObj = $dialog.modal('show');
608
			modalObj.on('hidden.bs.modal', function(e) {
600
		modalObj.on('hidden.bs.modal', function (e) {
609
				$dialog.remove();
601
			$dialog.remove();
610
			});
602
		});
611
			$('button.number_dialog').on('click', function() {
603
		$('button.number_dialog').on('click', function () {
612
				let itemQty = [];
604
			let itemQty = [];
613
				let anySelected = false;
605
			let anySelected = false;
614
				$(modalObj).find('.modal-body').find('input').each(function() {
606
			$(modalObj).find('.modal-body').find('input').each(function () {
615
					$input = $(this);
607
				$input = $(this);
616
					if ($input.val() > 0) {
608
				if ($input.val() > 0) {
617
						itemQty.push({
609
					itemQty.push({
618
							itemId: $input.data("itemid"),
610
						itemId: $input.data("itemid"),
619
							quantity: $input.val()
611
						quantity: $input.val()
620
						});
-
 
621
						anySelected = true;
-
 
622
					}
-
 
623
				});
-
 
624
				if (anySelected && confirm("Are you sure want to notify?")) {
-
 
625
					$that = $(this);
-
 
626
					callback(itemQty, function() {
-
 
627
						$that.off('click');
-
 
628
						modalObj.hide();
-
 
629
					});
612
					});
630
				} else {
-
 
631
					alert("Pls mention quantity");
613
					anySelected = true;
632
				}
614
				}
633
			});
615
			});
-
 
616
			if (anySelected && confirm("Are you sure want to notify?")) {
-
 
617
				$that = $(this);
-
 
618
				callback(itemQty, function () {
-
 
619
					$that.off('click');
-
 
620
					modalObj.hide();
-
 
621
				});
-
 
622
			} else {
-
 
623
				alert("Pls mention quantity");
-
 
624
			}
634
		});
625
		});
-
 
626
	});
635
}
627
}
636
 
628
 
637
 
629
 
638
function colorCheckboxHandler(catalogId, itemId, description, callback) {
630
function colorCheckboxHandler(catalogId, itemId, description, callback) {
639
	let bootBoxObj = {
631
	let bootBoxObj = {
Line 642... Line 634...
642
		title: description,
634
		title: description,
643
		callback: callback,
635
		callback: callback,
644
		inputType: 'checkbox',
636
		inputType: 'checkbox',
645
	}
637
	}
646
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
638
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
647
		+ catalogId + "&itemId=" + itemId, function(response) {
639
		+ catalogId + "&itemId=" + itemId, function (response) {
648
			coloredItems = JSON.parse(response);
640
		coloredItems = JSON.parse(response);
649
			inputOptions = [{
641
		inputOptions = [{
650
				text: "All",
642
			text: "All",
651
				value: "0",
643
			value: "0",
652
				onclick: "toggleAll('itemIds')"
644
			onclick: "toggleAll('itemIds')"
653
			}];
645
		}];
654
			coloredItems.forEach(function(item) {
646
		coloredItems.forEach(function (item) {
655
				inputOptions.push({
647
			inputOptions.push({
656
					text: item.color,
648
				text: item.color,
657
					value: item.id,
649
				value: item.id,
658
					selected: item.active
650
				selected: item.active
659
				});
-
 
660
			});
651
			});
661
			bootBoxObj['inputOptions'] = inputOptions;
-
 
662
			promptObj = bootbox.prompt(bootBoxObj);
-
 
663
			promptObj.modal('show')
-
 
664
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
665
				function(index, checkbox) {
-
 
666
					checkbox.checked = coloredItems[index].active;
-
 
667
				});
-
 
668
		});
652
		});
-
 
653
		bootBoxObj['inputOptions'] = inputOptions;
-
 
654
		promptObj = bootbox.prompt(bootBoxObj);
-
 
655
		promptObj.modal('show')
-
 
656
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
657
			function (index, checkbox) {
-
 
658
				checkbox.checked = coloredItems[index].active;
-
 
659
			});
-
 
660
	});
669
}
661
}
670
 
662
 
671
function getHotdealsForItems(catalogId, itemId, description, callback) {
663
function getHotdealsForItems(catalogId, itemId, description, callback) {
672
	bootBoxObj = {
664
	bootBoxObj = {
673
		size: "small",
665
		size: "small",
Line 675... Line 667...
675
		title: description,
667
		title: description,
676
		callback: callback,
668
		callback: callback,
677
		inputType: 'checkbox',
669
		inputType: 'checkbox',
678
	}
670
	}
679
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
671
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
680
		+ catalogId + "&itemId=" + itemId, function(response) {
672
		+ catalogId + "&itemId=" + itemId, function (response) {
681
			coloredItems = JSON.parse(response);
673
		coloredItems = JSON.parse(response);
682
			inputOptions = [{
674
		inputOptions = [{
683
				text: "All",
675
			text: "All",
684
				value: "0",
676
			value: "0",
685
				onclick: "toggleAll('itemIds')"
677
			onclick: "toggleAll('itemIds')"
686
			}];
678
		}];
687
			coloredItems.forEach(function(item) {
679
		coloredItems.forEach(function (item) {
688
				inputOptions.push({
680
			inputOptions.push({
689
					text: item.color,
681
				text: item.color,
690
					value: item.id,
682
				value: item.id,
691
					selected: item.hotDeals
683
				selected: item.hotDeals
692
				});
-
 
693
			});
684
			});
694
			bootBoxObj['inputOptions'] = inputOptions;
-
 
695
			promptObj = bootbox.prompt(bootBoxObj);
-
 
696
			promptObj.modal('show')
-
 
697
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
698
				function(index, checkbox) {
-
 
699
					checkbox.checked = coloredItems[index].hotDeals;
-
 
700
				});
-
 
701
		});
685
		});
-
 
686
		bootBoxObj['inputOptions'] = inputOptions;
-
 
687
		promptObj = bootbox.prompt(bootBoxObj);
-
 
688
		promptObj.modal('show')
-
 
689
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
690
			function (index, checkbox) {
-
 
691
				checkbox.checked = coloredItems[index].hotDeals;
-
 
692
			});
-
 
693
	});
702
}
694
}
703
 
695
 
704
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
696
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
705
	function() {
697
	function () {
706
		if (this.value == "0") {
698
		if (this.value == "0") {
707
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
699
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
708
				.slice(1).prop('checked', $(this).prop('checked'));
700
				.slice(1).prop('checked', $(this).prop('checked'));
709
		}
701
		}
710
	});
702
	});
711
 
703
 
712
function getItemAheadOptions(jqElement, anyColor, callback) {
704
function getItemAheadOptions(jqElement, anyColor, callback) {
713
	console.log(anyColor)
705
	console.log(anyColor)
714
	jqElement.typeahead('destroy').typeahead({
706
	jqElement.typeahead('destroy').typeahead({
715
		source: function(q, process) {
707
		source: function (q, process) {
716
			if (q.length >= 3) {
708
			if (q.length >= 3) {
717
				return $.ajax(context + "/item?anyColor=" + anyColor, {
709
				return $.ajax(context + "/item?anyColor=" + anyColor, {
718
					global: false,
710
					global: false,
719
					data: {
711
					data: {
720
						query: q
712
						query: q
721
					},
713
					},
722
					success: function(data) {
714
					success: function (data) {
723
						queryData = JSON.parse(data);
715
						queryData = JSON.parse(data);
724
						process(queryData);
716
						process(queryData);
725
					},
717
					},
726
				});
718
				});
727
			}
719
			}
728
		},
720
		},
729
		delay: 300,
721
		delay: 300,
730
		items: 20,
722
		items: 20,
731
		displayText: function(item) {
723
		displayText: function (item) {
732
			return item.itemDescription;
724
			return item.itemDescription;
733
		},
725
		},
734
		autoSelect: true,
726
		autoSelect: true,
735
		afterSelect: callback
727
		afterSelect: callback
736
	});
728
	});
737
}
729
}
738
 
730
 
739
 
731
 
740
function getImeiAheadOptions(jqElement, fofoId, callback) {
732
function getImeiAheadOptions(jqElement, fofoId, callback) {
741
	jqElement.typeahead('destroy').typeahead({
733
	jqElement.typeahead('destroy').typeahead({
742
		source: function(q, process) {
734
		source: function (q, process) {
743
			if (q.length >= 3) {
735
			if (q.length >= 3) {
744
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
736
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
745
					global: false,
737
					global: false,
746
					data: {
738
					data: {
747
						query: q
739
						query: q
748
					},
740
					},
749
					success: function(data) {
741
					success: function (data) {
750
						queryData = JSON.parse(data);
742
						queryData = JSON.parse(data);
751
						process(queryData);
743
						process(queryData);
752
					},
744
					},
753
				});
745
				});
754
			}
746
			}
755
		},
747
		},
756
		delay: 300,
748
		delay: 300,
757
		items: 20,
749
		items: 20,
758
		displayText: function(imei) {
750
		displayText: function (imei) {
759
			return imei;
751
			return imei;
760
		},
752
		},
761
		autoSelect: true,
753
		autoSelect: true,
762
		afterSelect: callback
754
		afterSelect: callback
763
	});
755
	});
764
}
756
}
765
 
757
 
766
 
758
 
767
function getEntityAheadOptions(jqElement, callback) {
759
function getEntityAheadOptions(jqElement, callback) {
768
	jqElement.typeahead('destroy').typeahead({
760
	jqElement.typeahead('destroy').typeahead({
769
		source: function(q, process) {
761
		source: function (q, process) {
770
			if (q.length >= 3) {
762
			if (q.length >= 3) {
771
				return $.ajax(context + "/entity", {
763
				return $.ajax(context + "/entity", {
772
					global: false,
764
					global: false,
773
					data: {
765
					data: {
774
						query: q
766
						query: q
775
					},
767
					},
776
					success: function(data) {
768
					success: function (data) {
777
						queryData = JSON.parse(data);
769
						queryData = JSON.parse(data);
778
						process(queryData);
770
						process(queryData);
779
					},
771
					},
780
				});
772
				});
781
			}
773
			}
782
		},
774
		},
783
		delay: 300,
775
		delay: 300,
784
		items: 30,
776
		items: 30,
785
		displayText: function(entity) {
777
		displayText: function (entity) {
786
			return entity.title_s + "(" + entity.catalogId_i + ")";
778
			return entity.title_s + "(" + entity.catalogId_i + ")";
787
		},
779
		},
788
		autoSelect: true,
780
		autoSelect: true,
789
		afterSelect: callback
781
		afterSelect: callback
790
	});
782
	});
791
}
783
}
792
 
784
 
793
function getPartnerAheadOptions(jqElement, callback) {
785
function getPartnerAheadOptions(jqElement, callback) {
794
	jqElement.typeahead('destroy').typeahead({
786
	jqElement.typeahead('destroy').typeahead({
795
		source: function(q, process) {
787
		source: function (q, process) {
796
			if (q.length >= 3) {
788
			if (q.length >= 3) {
797
				return $.ajax(context + "/partners", {
789
				return $.ajax(context + "/partners", {
798
					global: false,
790
					global: false,
799
					data: {
791
					data: {
800
						query: q
792
						query: q
801
					},
793
					},
802
					success: function(data) {
794
					success: function (data) {
803
						queryData = JSON.parse(data);
795
						queryData = JSON.parse(data);
804
						process(queryData);
796
						process(queryData);
805
					},
797
					},
806
				});
798
				});
807
			}
799
			}
808
		},
800
		},
809
		delay: 300,
801
		delay: 300,
810
		items: 20,
802
		items: 20,
811
		displayText: function(partner) {
803
		displayText: function (partner) {
812
			return partner.displayName;
804
			return partner.displayName;
813
		},
805
		},
814
		autoSelect: true,
806
		autoSelect: true,
815
		afterSelect: callback
807
		afterSelect: callback
816
	});
808
	});
817
}
809
}
818
 
810
 
819
function loadPriceDrop(domId) {
811
function loadPriceDrop(domId) {
820
	doGetAjaxRequestHandler(context + "/getItemDescription",
812
	doGetAjaxRequestHandler(context + "/getItemDescription",
821
		function(response) {
813
		function (response) {
822
			$('#' + domId).html(response);
814
			$('#' + domId).html(response);
823
		});
815
		});
824
}
816
}
825
 
817
 
826
$(document).on('click', ".price_drop", function() {
818
$(document).on('click', ".price_drop", function () {
827
	loadPriceDrop("main-content");
819
	loadPriceDrop("main-content");
828
});
820
});
829
 
821
 
830
 
822
 
831
$(document).on('click', ".closed_pricedrop", function() {
823
$(document).on('click', ".closed_pricedrop", function () {
832
	loadClosedPriceDrop("main-content");
824
	loadClosedPriceDrop("main-content");
833
});
825
});
834
 
826
 
835
function loadClosedPriceDrop(domId) {
827
function loadClosedPriceDrop(domId) {
836
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
828
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
837
		function(response) {
829
		function (response) {
838
			$('#' + domId).html(response);
830
			$('#' + domId).html(response);
839
		});
831
		});
840
}
832
}
841
 
833
 
842
function notifyTypeChange(messageType, $container) {
834
function notifyTypeChange(messageType, $container) {
843
	var messageQueryString = "?messageType=" + messageType;
835
	var messageQueryString = "?messageType=" + messageType;
844
	if (messageType == null) {
836
	if (messageType == null) {
845
		messageQueryString = "";
837
		messageQueryString = "";
846
	}
838
	}
847
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function(response) {
839
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function (response) {
848
		if ($container != null) {
840
		if ($container != null) {
849
			loaderDialogObj.one('hidden.bs.modal', function() {
841
			loaderDialogObj.one('hidden.bs.modal', function () {
850
				$container.popover({
842
				$container.popover({
851
					container: $container,
843
					container: $container,
852
					template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
844
					template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
853
					content: response,
845
					content: response,
854
					html: true,
846
					html: true,
855
					placement: "bottom",
847
					placement: "bottom",
856
					trigger: "manual",
848
					trigger: "manual",
857
					sanitize: false
849
					sanitize: false
858
				}).popover('show');
850
				}).popover('show');
859
				setTimeout(function() {
851
				setTimeout(function () {
860
					$container.focus().one('blur', function() {
852
					$container.focus().one('blur', function () {
861
						$container.popover('destroy');
853
						$container.popover('destroy');
862
					});
854
					});
863
				}, 100);
855
				}, 100);
864
			});
856
			});
865
		}
857
		}
Line 871... Line 863...
871
		documentName);
863
		documentName);
872
}
864
}
873
 
865
 
874
 
866
 
875
/* Create an array with the values of all the input boxes in a column */
867
/* Create an array with the values of all the input boxes in a column */
876
$.fn.dataTable.ext.order['dom-text'] = function(settings, col) {
868
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
877
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
869
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
878
		return $('input', td).val();
870
		return $('input', td).val();
879
	});
871
	});
880
}
872
}
881
 
873
 
882
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
874
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
883
$.fn.dataTable.ext.order['dom-text-numeric'] = function(settings, col) {
875
$.fn.dataTable.ext.order['dom-text-numeric'] = function (settings, col) {
884
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
876
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
885
		return $('input', td).val() * 1;
877
		return $('input', td).val() * 1;
886
	});
878
	});
887
}
879
}
888
 
880
 
889
$.fn.dataTable.ext.order['dom-stock-numeric'] = function(settings, col) {
881
$.fn.dataTable.ext.order['dom-stock-numeric'] = function (settings, col) {
890
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
882
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
891
		return $(td).html().split("/")[0] * 1;
883
		return $(td).html().split("/")[0] * 1;
892
	});
884
	});
893
}
885
}
894
/* Create an array with the values of all the select options in a column */
886
/* Create an array with the values of all the select options in a column */
895
$.fn.dataTable.ext.order['dom-select'] = function(settings, col) {
887
$.fn.dataTable.ext.order['dom-select'] = function (settings, col) {
896
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
888
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
897
		return $('select', td).val();
889
		return $('select', td).val();
898
	});
890
	});
899
}
891
}
900
 
892
 
901
/* Create an array with the values of all the checkboxes in a column */
893
/* Create an array with the values of all the checkboxes in a column */
902
$.fn.dataTable.ext.order['dom-checkbox'] = function(settings, col) {
894
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
903
	return this.api().column(col, {
895
	return this.api().column(col, {
904
		order: 'index'
896
		order: 'index'
905
	}).nodes().map(function(td, i) {
897
	}).nodes().map(function (td, i) {
906
		return $('input', td).prop('checked') ? '1' : '0';
898
		return $('input', td).prop('checked') ? '1' : '0';
907
	});
899
	});
908
}
900
}
909
 
901
 
910
$.fn.dataTable.Api.register('sum()', function() {
902
$.fn.dataTable.Api.register('sum()', function () {
911
	return this.flatten().reduce(function(a, b) {
903
	return this.flatten().reduce(function (a, b) {
912
		if (typeof a === 'string') {
904
		if (typeof a === 'string') {
913
			a = a.replace(/[^\d.-]/g, '') * 1;
905
			a = a.replace(/[^\d.-]/g, '') * 1;
914
			a = isNaN(a) ? 0 : a;
906
			a = isNaN(a) ? 0 : a;
915
		}
907
		}
916
		if (typeof b === 'string') {
908
		if (typeof b === 'string') {