Subversion Repositories SmartDukaan

Rev

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

Rev 31702 Rev 31762
Line 28... Line 28...
28
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
28
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
29
		+ errorObject.rejectedValue + '\n' + 'message : '
29
		+ errorObject.rejectedValue + '\n' + 'message : '
30
		+ errorObject.message);
30
		+ errorObject.message);
31
}
31
}
32
 
32
 
33
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
33
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
34
	if (typeof loaderDialogObj != "undefined") {
34
	if (typeof loaderDialogObj != "undefined") {
35
		loaderDialogObj.modal('hide');
35
		loaderDialogObj.modal('hide');
36
		// $('div.modal-backdrop.fade').remove();
36
		// $('div.modal-backdrop.fade').remove();
37
	}
37
	}
38
	if (jqxhr.status == 400) {
38
	if (jqxhr.status == 400) {
Line 41... Line 41...
41
	} else {
41
	} else {
42
		internalServerErrorAlert(jqxhr);
42
		internalServerErrorAlert(jqxhr);
43
	}
43
	}
44
});
44
});
45
 
45
 
46
$(document).ajaxComplete(function () {
46
$(document).ajaxComplete(function() {
47
	if (typeof loaderDialogObj != "undefined") {
47
	if (typeof loaderDialogObj != "undefined") {
48
		loaderDialogObj.modal('hide');
48
		loaderDialogObj.modal('hide');
49
		// $('div.modal-backdrop.fade').remove();
49
		// $('div.modal-backdrop.fade').remove();
50
	}
50
	}
51
});
51
});
Line 56... Line 56...
56
}
56
}
57
 
57
 
58
$(document).ajaxStart(ajaxStartHandler);
58
$(document).ajaxStart(ajaxStartHandler);
59
 
59
 
60
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
60
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
61
										callback_function) {
61
	callback_function) {
62
	$.ajax({
62
	$.ajax({
63
		url: urlString,
63
		url: urlString,
64
		async: true,
64
		async: true,
65
		cache: false,
65
		cache: false,
66
		data: params,
66
		data: params,
67
		// dataType:'json',
67
		// dataType:'json',
68
		type: httpType,
68
		type: httpType,
69
		success: function (response) {
69
		success: function(response) {
70
			callback_function(response);
70
			callback_function(response);
71
			$('.currency').each(function (index, ele) {
71
			$('.currency').each(function(index, ele) {
72
				if (!isNaN(parseInt($(ele).html()))) {
72
				if (!isNaN(parseInt($(ele).html()))) {
73
					$(ele).html(numberToComma($(ele).html()));
73
					$(ele).html(numberToComma($(ele).html()));
74
				}
74
				}
75
			});
75
			});
76
		}
76
		}
Line 80... Line 80...
80
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
80
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
81
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
81
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
82
}
82
}
83
 
83
 
84
function doPostAjaxRequestWithParamsHandler(urlString, params,
84
function doPostAjaxRequestWithParamsHandler(urlString, params,
85
											callback_function) {
85
	callback_function) {
86
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
86
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
87
}
87
}
88
 
88
 
89
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
89
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
90
									  callback_function) {
90
	callback_function) {
91
	$.ajax({
91
	$.ajax({
92
		url: urlString,
92
		url: urlString,
93
		async: true,
93
		async: true,
94
		cache: false,
94
		cache: false,
95
		processData: false,
95
		processData: false,
96
		data: json,
96
		data: json,
97
		contentType: 'application/json',
97
		contentType: 'application/json',
98
		type: httpType,
98
		type: httpType,
99
		success: function (response) {
99
		success: function(response) {
100
			// console.log("response"+JSON.stringify(data));
100
			// console.log("response"+JSON.stringify(data));
101
			callback_function(response);
101
			callback_function(response);
102
			$('.currency').each(function (index, ele) {
102
			$('.currency').each(function(index, ele) {
103
				if (!isNaN(parseInt($(ele).html()))) {
103
				if (!isNaN(parseInt($(ele).html()))) {
104
					$(ele).html(numberToComma($(ele).html()));
104
					$(ele).html(numberToComma($(ele).html()));
105
				}
105
				}
106
			});
106
			});
107
		}
107
		}
Line 120... Line 120...
120
	$.ajax({
120
	$.ajax({
121
		url: urlString,
121
		url: urlString,
122
		async: true,
122
		async: true,
123
		cache: false,
123
		cache: false,
124
		type: httpType,
124
		type: httpType,
125
		success: function (response) {
125
		success: function(response) {
126
			callback_function(response);
126
			callback_function(response);
127
			$('.currency').each(function (index, ele) {
127
			$('.currency').each(function(index, ele) {
128
				if (!isNaN(parseInt($(ele).html()))) {
128
				if (!isNaN(parseInt($(ele).html()))) {
129
					$(ele).html(numberToComma($(ele).html()));
129
					$(ele).html(numberToComma($(ele).html()));
130
				}
130
				}
131
			});
131
			});
132
		}
132
		}
Line 150... Line 150...
150
}
150
}
151
 
151
 
152
function doAjaxUploadRequest(urlString, httpType, file) {
152
function doAjaxUploadRequest(urlString, httpType, file) {
153
	var response;
153
	var response;
154
	doAjaxUploadRequestHandler(urlString, httpType, file,
154
	doAjaxUploadRequestHandler(urlString, httpType, file,
155
		function (ajaxResponse) {
155
		function(ajaxResponse) {
156
			response = ajaxResponse;
156
			response = ajaxResponse;
157
		});
157
		});
158
	return response;
158
	return response;
159
}
159
}
160
 
160
 
161
function doAjaxUploadRequestHandler(urlString, httpType, file,
161
function doAjaxUploadRequestHandler(urlString, httpType, file,
162
									callback_function) {
162
	callback_function) {
163
	var formData = new FormData();
163
	var formData = new FormData();
164
	formData.append("file", file);
164
	formData.append("file", file);
165
	$.ajax({
165
	$.ajax({
166
		url: urlString,
166
		url: urlString,
167
		type: httpType,
167
		type: httpType,
Line 170... Line 170...
170
		async: true,
170
		async: true,
171
		cache: false,
171
		cache: false,
172
		contentType: false,
172
		contentType: false,
173
		enctype: 'multipart/form-data',
173
		enctype: 'multipart/form-data',
174
		processData: false,
174
		processData: false,
175
		success: function (response) {
175
		success: function(response) {
176
			// console.log("response"+JSON.stringify(data));
176
			// console.log("response"+JSON.stringify(data));
177
			callback_function(response);
177
			callback_function(response);
178
		}
178
		}
179
	});
179
	});
180
}
180
}
181
 
181
 
182
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
182
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
183
										callback_function) {
183
	callback_function) {
184
	var formData = new FormData();
184
	var formData = new FormData();
185
	formData.append("file", file);
185
	formData.append("file", file);
186
	formData.append('json', new Blob([json]));
186
	formData.append('json', new Blob([json]));
187
	$.ajax({
187
	$.ajax({
188
		url: urlString,
188
		url: urlString,
189
		type: httpType,
189
		type: httpType,
190
		data: formData,
190
		data: formData,
191
		enctype: 'multipart/form-data',
191
		enctype: 'multipart/form-data',
192
		contentType: false,
192
		contentType: false,
193
		processData: false,
193
		processData: false,
194
		success: function (response) {
194
		success: function(response) {
195
			// console.log("response"+JSON.stringify(data));
195
			// console.log("response"+JSON.stringify(data));
196
			callback_function(response);
196
			callback_function(response);
197
		}
197
		}
198
	});
198
	});
199
}
199
}
200
 
200
 
201
function uploadDocument(file) {
201
function uploadDocument(file) {
202
	var url = context + '/document-upload';
202
	var url = context + '/document-upload';
203
	doAjaxUploadRequestHandler(url, 'POST', file, function (response) {
203
	doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
204
		var documentId = response.response.document_id;
204
		var documentId = response.response.document_id;
205
		console.log("documentId : " + documentId);
205
		console.log("documentId : " + documentId);
206
		return documentId;
206
		return documentId;
207
	});
207
	});
208
}
208
}
Line 218... Line 218...
218
 
218
 
219
function doAjaxDownload(urlString, httpType, data, fileName, callback) {
219
function doAjaxDownload(urlString, httpType, data, fileName, callback) {
220
	xhttp = new XMLHttpRequest();
220
	xhttp = new XMLHttpRequest();
221
	if (typeof loaderDialogObj != "undefined")
221
	if (typeof loaderDialogObj != "undefined")
222
		loaderDialogObj.modal('show');
222
		loaderDialogObj.modal('show');
223
	xhttp.onreadystatechange = function () {
223
	xhttp.onreadystatechange = function() {
224
		var a;
224
		var a;
225
		if (xhttp.readyState === 2) {
225
		if (xhttp.readyState === 2) {
226
			if (xhttp.status == 200) {
226
			if (xhttp.status == 200) {
227
				xhttp.responseType = "blob";
227
				xhttp.responseType = "blob";
228
			} else {
228
			} else {
Line 265... Line 265...
265
	// xhttp.responseType = 'blob';
265
	// xhttp.responseType = 'blob';
266
	xhttp.send(data);
266
	xhttp.send(data);
267
}
267
}
268
 
268
 
269
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
269
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
270
									   tableIdentifier, detailsContainerIdentifier) {
270
	tableIdentifier, detailsContainerIdentifier) {
271
	var start = $("#" + paginatedIdentifier + " .start").text();
271
	var start = $("#" + paginatedIdentifier + " .start").text();
272
 
272
 
273
	var end = $("#" + paginatedIdentifier + " .end").text();
273
	var end = $("#" + paginatedIdentifier + " .end").text();
274
 
274
 
275
	url = context + url + "?offset=" + end;
275
	url = context + url + "?offset=" + end;
Line 281... Line 281...
281
				url = url + "&" + key + "=" + params[key];
281
				url = url + "&" + key + "=" + params[key];
282
			}
282
			}
283
		}
283
		}
284
	}
284
	}
285
 
285
 
286
	doGetAjaxRequestHandler(url, function (response) {
286
	doGetAjaxRequestHandler(url, function(response) {
287
		var size = $("#" + paginatedIdentifier + " .size").text();
287
		var size = $("#" + paginatedIdentifier + " .size").text();
288
		if ((parseInt(end) + 20) > parseInt(size)) {
288
		if ((parseInt(end) + 20) > parseInt(size)) {
289
			// console.log("(end + 10) > size == true");
289
			// console.log("(end + 10) > size == true");
290
			$("#" + paginatedIdentifier + " .end").text(size);
290
			$("#" + paginatedIdentifier + " .end").text(size);
291
		} else {
291
		} else {
Line 308... Line 308...
308
	});
308
	});
309
 
309
 
310
}
310
}
311
 
311
 
312
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
312
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
313
										  tableIdentifier, detailsContainerIdentifier) {
313
	tableIdentifier, detailsContainerIdentifier) {
314
	var start = $("#" + paginatedIdentifier + " .start").text();
314
	var start = $("#" + paginatedIdentifier + " .start").text();
315
	console.log("start" + start);
315
	console.log("start" + start);
316
	var end = $("#" + paginatedIdentifier + " .end").text();
316
	var end = $("#" + paginatedIdentifier + " .end").text();
317
	console.log("Startend" + end);
317
	console.log("Startend" + end);
318
	var size = $("#" + paginatedIdentifier + " .size").text();
318
	var size = $("#" + paginatedIdentifier + " .size").text();
Line 333... Line 333...
333
				url = url + "&" + key + "=" + params[key];
333
				url = url + "&" + key + "=" + params[key];
334
			}
334
			}
335
		}
335
		}
336
	}
336
	}
337
 
337
 
338
	doGetAjaxRequestHandler(url, function (response) {
338
	doGetAjaxRequestHandler(url, function(response) {
339
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
339
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
340
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
340
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
341
		$('#' + tableIdentifier).html(response);
341
		$('#' + tableIdentifier).html(response);
342
		if (detailsContainerIdentifier != null) {
342
		if (detailsContainerIdentifier != null) {
343
			$('#' + detailsContainerIdentifier).html('');
343
			$('#' + detailsContainerIdentifier).html('');
Line 349... Line 349...
349
	});
349
	});
350
 
350
 
351
}
351
}
352
 
352
 
353
function loadPaginatedNextItems(url, params, paginatedIdentifier,
353
function loadPaginatedNextItems(url, params, paginatedIdentifier,
354
								tableIdentifier, detailsContainerIdentifier) {
354
	tableIdentifier, detailsContainerIdentifier) {
355
	var start = $("#" + paginatedIdentifier + " .start").text();
355
	var start = $("#" + paginatedIdentifier + " .start").text();
356
	var end = $("#" + paginatedIdentifier + " .end").text();
356
	var end = $("#" + paginatedIdentifier + " .end").text();
357
	url = context + url + "?offset=" + end;
357
	url = context + url + "?offset=" + end;
358
 
358
 
359
	if (params != null) {
359
	if (params != null) {
Line 363... Line 363...
363
				url = url + "&" + key + "=" + params[key];
363
				url = url + "&" + key + "=" + params[key];
364
			}
364
			}
365
		}
365
		}
366
	}
366
	}
367
 
367
 
368
	doGetAjaxRequestHandler(url, function (response) {
368
	doGetAjaxRequestHandler(url, function(response) {
369
		var size = $("#" + paginatedIdentifier + " .size").text();
369
		var size = $("#" + paginatedIdentifier + " .size").text();
370
		if ((parseInt(end) + 10) > parseInt(size)) {
370
		if ((parseInt(end) + 10) > parseInt(size)) {
371
			console.log("(end + 10) > size == true");
371
			console.log("(end + 10) > size == true");
372
			$("#" + paginatedIdentifier + " .end").text(size);
372
			$("#" + paginatedIdentifier + " .end").text(size);
373
		} else {
373
		} else {
Line 389... Line 389...
389
	});
389
	});
390
 
390
 
391
}
391
}
392
 
392
 
393
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
393
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
394
									tableIdentifier, detailsContainerIdentifier) {
394
	tableIdentifier, detailsContainerIdentifier) {
395
	var start = $("#" + paginatedIdentifier + " .start").text();
395
	var start = $("#" + paginatedIdentifier + " .start").text();
396
	var end = $("#" + paginatedIdentifier + " .end").text();
396
	var end = $("#" + paginatedIdentifier + " .end").text();
397
	var size = $("#" + paginatedIdentifier + " .size").text();
397
	var size = $("#" + paginatedIdentifier + " .size").text();
398
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
398
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
399
		var mod = parseInt(end) % 10;
399
		var mod = parseInt(end) % 10;
Line 409... Line 409...
409
				url = url + "&" + key + "=" + params[key];
409
				url = url + "&" + key + "=" + params[key];
410
			}
410
			}
411
		}
411
		}
412
	}
412
	}
413
 
413
 
414
	doGetAjaxRequestHandler(url, function (response) {
414
	doGetAjaxRequestHandler(url, function(response) {
415
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
415
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
416
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
416
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
417
		$('#' + tableIdentifier).html(response);
417
		$('#' + tableIdentifier).html(response);
418
		if (detailsContainerIdentifier != null) {
418
		if (detailsContainerIdentifier != null) {
419
			$('#' + detailsContainerIdentifier).html('');
419
			$('#' + detailsContainerIdentifier).html('');
Line 501... Line 501...
501
	};
501
	};
502
	if (showRanges) {
502
	if (showRanges) {
503
		rangedDatePicker['ranges'] = {
503
		rangedDatePicker['ranges'] = {
504
			'Today': [moment(), moment()],
504
			'Today': [moment(), moment()],
505
			'Yesterday': [moment().subtract(1, 'days'),
505
			'Yesterday': [moment().subtract(1, 'days'),
506
				moment().subtract(1, 'days')],
506
			moment().subtract(1, 'days')],
507
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
507
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
508
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
508
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
509
			'This Month': [moment().startOf('month'), moment().endOf('month')],
509
			'This Month': [moment().startOf('month'), moment().endOf('month')],
510
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
510
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
511
				moment()],
511
			moment()],
512
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
512
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
513
				moment()],
513
			moment()],
514
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
514
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
515
				moment()]
515
			moment()]
516
		}
516
		}
517
	}
517
	}
518
	return rangedDatePicker;
518
	return rangedDatePicker;
519
}
519
}
520
 
520
 
Line 523... Line 523...
523
		var coords = {
523
		var coords = {
524
			latitude: position.coords.latitude,
524
			latitude: position.coords.latitude,
525
			longitude: position.coords.longitude
525
			longitude: position.coords.longitude
526
		}
526
		}
527
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
527
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
528
			.stringify(coords), function () {
528
			.stringify(coords), function() {
529
			latitude = position.coords.latitude;
529
				latitude = position.coords.latitude;
530
			longitude = position.coords.longitude;
530
				longitude = position.coords.longitude;
531
		});
531
			});
532
	}
532
	}
533
	// distance = getDistance(latitude, longitude, position.coords.latitude,
533
	// distance = getDistance(latitude, longitude, position.coords.latitude,
534
	// position.coords.longitude);
534
	// position.coords.longitude);
535
}
535
}
536
 
536
 
Line 542... Line 542...
542
		inputType: 'select',
542
		inputType: 'select',
543
		inputOptions: typeof inputOptions == "undefined" ? undefined
543
		inputOptions: typeof inputOptions == "undefined" ? undefined
544
			: inputOptions
544
			: inputOptions
545
	}
545
	}
546
	if (typeof inputOptions == "undefined") {
546
	if (typeof inputOptions == "undefined") {
547
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
547
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
548
			response) {
548
			response) {
549
			response = JSON.parse(response);
549
			response = JSON.parse(response);
550
			inputOptions = [];
550
			inputOptions = [];
551
			response.forEach(function (warehouse) {
551
			response.forEach(function(warehouse) {
552
				inputOptions.push({
552
				inputOptions.push({
553
					text: warehouse.name,
553
					text: warehouse.name,
554
					value: warehouse.id,
554
					value: warehouse.id,
555
				});
555
				});
556
			});
556
			});
Line 569... Line 569...
569
	colorCheckboxHandler(catalogId, itemId, description, callback);
569
	colorCheckboxHandler(catalogId, itemId, description, callback);
570
}
570
}
571
 
571
 
572
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
572
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
573
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
573
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
574
		+ catalogId + "&itemId=" + itemId, function (response) {
574
		+ catalogId + "&itemId=" + itemId, function(response) {
575
		let coloredItems = JSON.parse(response);
575
			let coloredItems = JSON.parse(response);
576
		let modalBody = [];
576
			let modalBody = [];
577
		coloredItems.forEach(function (item) {
577
			coloredItems.forEach(function(item) {
578
			modalBody.push(`
578
				modalBody.push(`
579
                <div class="row">
579
                <div class="row">
580
                    <div class="col-sm-2">
580
                    <div class="col-sm-2">
581
                        ${item.color}
581
                        ${item.color}
582
                    </div>
582
                    </div>
583
                    <div class="col-sm-2">
583
                    <div class="col-sm-2">
584
                            <input data-itemid="${item.id}" type="text" class="form-control" />
584
                            <input data-itemid="${item.id}" type="text" class="form-control" />
585
                    </div>
585
                    </div>
586
                </div>
586
                </div>
587
            `);
587
            `);
588
		});
588
			});
589
		let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
589
			let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
590
                              <div class="modal-dialog" >
590
                              <div class="modal-dialog" >
591
                                <div class="modal-content">
591
                                <div class="modal-content">
592
                                  <div class="modal-header">
592
                                  <div class="modal-header">
593
                                    <h5 class="modal-title">${title}</h5>
593
                                    <h5 class="modal-title">${title}</h5>
594
                                  </div>
594
                                  </div>
Line 599... Line 599...
599
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
599
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
600
                                  </div>
600
                                  </div>
601
                                </div>
601
                                </div>
602
                              </div>
602
                              </div>
603
                            </div>`;
603
                            </div>`;
604
		let $dialog = $(dialogBoxHtml);
604
			let $dialog = $(dialogBoxHtml);
605
		let modalObj = $dialog.modal('show');
605
			let modalObj = $dialog.modal('show');
606
		modalObj.on('hidden.bs.modal', function (e) {
606
			modalObj.on('hidden.bs.modal', function(e) {
607
			$dialog.remove();
607
				$dialog.remove();
608
		});
608
			});
609
		$('button.number_dialog').on('click', function () {
609
			$('button.number_dialog').on('click', function() {
610
			let itemQty = [];
610
				let itemQty = [];
611
			let anySelected = false;
611
				let anySelected = false;
612
			$(modalObj).find('.modal-body').find('input').each(function () {
612
				$(modalObj).find('.modal-body').find('input').each(function() {
613
				$input = $(this);
613
					$input = $(this);
614
				if ($input.val() > 0) {
614
					if ($input.val() > 0) {
615
					itemQty.push({
615
						itemQty.push({
616
						itemId: $input.data("itemid"),
616
							itemId: $input.data("itemid"),
617
						quantity: $input.val()
617
							quantity: $input.val()
-
 
618
						});
-
 
619
						anySelected = true;
-
 
620
					}
-
 
621
				});
-
 
622
				if (anySelected && confirm("Are you sure want to notify?")) {
-
 
623
					$that = $(this);
-
 
624
					callback(itemQty, function() {
-
 
625
						$that.off('click');
-
 
626
						modalObj.hide();
618
					});
627
					});
-
 
628
				} else {
619
					anySelected = true;
629
					alert("Pls mention quantity");
620
				}
630
				}
621
			});
631
			});
622
			if (anySelected && confirm("Are you sure want to notify?")) {
-
 
623
				$that = $(this);
-
 
624
				callback(itemQty, function () {
-
 
625
					$that.off('click');
-
 
626
					modalObj.hide();
-
 
627
				});
-
 
628
			} else {
-
 
629
				alert("Pls mention quantity");
-
 
630
			}
-
 
631
		});
632
		});
632
	});
-
 
633
}
633
}
634
 
634
 
635
 
635
 
636
function colorCheckboxHandler(catalogId, itemId, description, callback) {
636
function colorCheckboxHandler(catalogId, itemId, description, callback) {
637
	let bootBoxObj = {
637
	let bootBoxObj = {
Line 640... Line 640...
640
		title: description,
640
		title: description,
641
		callback: callback,
641
		callback: callback,
642
		inputType: 'checkbox',
642
		inputType: 'checkbox',
643
	}
643
	}
644
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
644
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
645
		+ catalogId + "&itemId=" + itemId, function (response) {
645
		+ catalogId + "&itemId=" + itemId, function(response) {
646
		coloredItems = JSON.parse(response);
646
			coloredItems = JSON.parse(response);
647
		inputOptions = [{
647
			inputOptions = [{
648
			text: "All",
648
				text: "All",
649
			value: "0",
649
				value: "0",
650
			onclick: "toggleAll('itemIds')"
650
				onclick: "toggleAll('itemIds')"
651
		}];
651
			}];
652
		coloredItems.forEach(function (item) {
652
			coloredItems.forEach(function(item) {
653
			inputOptions.push({
653
				inputOptions.push({
654
				text: item.color,
654
					text: item.color,
655
				value: item.id,
655
					value: item.id,
656
				selected: item.active
656
					selected: item.active
-
 
657
				});
657
			});
658
			});
-
 
659
			bootBoxObj['inputOptions'] = inputOptions;
-
 
660
			promptObj = bootbox.prompt(bootBoxObj);
-
 
661
			promptObj.modal('show')
-
 
662
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
663
				function(index, checkbox) {
-
 
664
					checkbox.checked = coloredItems[index].active;
-
 
665
				});
658
		});
666
		});
659
		bootBoxObj['inputOptions'] = inputOptions;
-
 
660
		promptObj = bootbox.prompt(bootBoxObj);
-
 
661
		promptObj.modal('show')
-
 
662
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
663
			function (index, checkbox) {
-
 
664
				checkbox.checked = coloredItems[index].active;
-
 
665
			});
-
 
666
	});
-
 
667
}
667
}
668
 
668
 
669
function getHotdealsForItems(catalogId, itemId, description, callback) {
669
function getHotdealsForItems(catalogId, itemId, description, callback) {
670
	bootBoxObj = {
670
	bootBoxObj = {
671
		size: "small",
671
		size: "small",
Line 673... Line 673...
673
		title: description,
673
		title: description,
674
		callback: callback,
674
		callback: callback,
675
		inputType: 'checkbox',
675
		inputType: 'checkbox',
676
	}
676
	}
677
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
677
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
678
		+ catalogId + "&itemId=" + itemId, function (response) {
678
		+ catalogId + "&itemId=" + itemId, function(response) {
679
		coloredItems = JSON.parse(response);
679
			coloredItems = JSON.parse(response);
680
		inputOptions = [{
680
			inputOptions = [{
681
			text: "All",
681
				text: "All",
682
			value: "0",
682
				value: "0",
683
			onclick: "toggleAll('itemIds')"
683
				onclick: "toggleAll('itemIds')"
684
		}];
684
			}];
685
		coloredItems.forEach(function (item) {
685
			coloredItems.forEach(function(item) {
686
			inputOptions.push({
686
				inputOptions.push({
687
				text: item.color,
687
					text: item.color,
688
				value: item.id,
688
					value: item.id,
689
				selected: item.hotDeals
689
					selected: item.hotDeals
-
 
690
				});
690
			});
691
			});
-
 
692
			bootBoxObj['inputOptions'] = inputOptions;
-
 
693
			promptObj = bootbox.prompt(bootBoxObj);
-
 
694
			promptObj.modal('show')
-
 
695
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
696
				function(index, checkbox) {
-
 
697
					checkbox.checked = coloredItems[index].hotDeals;
-
 
698
				});
691
		});
699
		});
692
		bootBoxObj['inputOptions'] = inputOptions;
-
 
693
		promptObj = bootbox.prompt(bootBoxObj);
-
 
694
		promptObj.modal('show')
-
 
695
		$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
-
 
696
			function (index, checkbox) {
-
 
697
				checkbox.checked = coloredItems[index].hotDeals;
-
 
698
			});
-
 
699
	});
-
 
700
}
700
}
701
 
701
 
702
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
702
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
703
	function () {
703
	function() {
704
		if (this.value == "0") {
704
		if (this.value == "0") {
705
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
705
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
706
				.slice(1).prop('checked', $(this).prop('checked'));
706
				.slice(1).prop('checked', $(this).prop('checked'));
707
		}
707
		}
708
	});
708
	});
709
 
709
 
710
function getItemAheadOptions(jqElement, anyColor, callback) {
710
function getItemAheadOptions(jqElement, anyColor, callback) {
711
	console.log(anyColor)
711
	console.log(anyColor)
712
	jqElement.typeahead('destroy').typeahead({
712
	jqElement.typeahead('destroy').typeahead({
713
		source: function (q, process) {
713
		source: function(q, process) {
714
			if (q.length >= 3) {
714
			if (q.length >= 3) {
715
				return $.ajax(context + "/item?anyColor=" + anyColor, {
715
				return $.ajax(context + "/item?anyColor=" + anyColor, {
716
					global: false,
716
					global: false,
717
					data: {
717
					data: {
718
						query: q
718
						query: q
719
					},
719
					},
720
					success: function (data) {
720
					success: function(data) {
721
						queryData = JSON.parse(data);
721
						queryData = JSON.parse(data);
722
						process(queryData);
722
						process(queryData);
723
					},
723
					},
724
				});
724
				});
725
			}
725
			}
726
		},
726
		},
727
		delay: 300,
727
		delay: 300,
728
		items: 20,
728
		items: 20,
729
		displayText: function (item) {
729
		displayText: function(item) {
730
			return item.itemDescription;
730
			return item.itemDescription;
731
		},
731
		},
732
		autoSelect: true,
732
		autoSelect: true,
733
		afterSelect: callback
733
		afterSelect: callback
734
	});
734
	});
735
}
735
}
736
 
736
 
737
 
737
 
738
function getImeiAheadOptions(jqElement, fofoId, callback) {
738
function getImeiAheadOptions(jqElement, fofoId, callback) {
739
	jqElement.typeahead('destroy').typeahead({
739
	jqElement.typeahead('destroy').typeahead({
740
		source: function (q, process) {
740
		source: function(q, process) {
741
			if (q.length >= 3) {
741
			if (q.length >= 3) {
742
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
742
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
743
					global: false,
743
					global: false,
744
					data: {
744
					data: {
745
						query: q
745
						query: q
746
					},
746
					},
747
					success: function (data) {
747
					success: function(data) {
-
 
748
						queryData = JSON.parse(data);
-
 
749
						process(queryData);
-
 
750
					},
-
 
751
				});
-
 
752
			}
-
 
753
		},
-
 
754
		delay: 300,
-
 
755
		items: 20,
-
 
756
		displayText: function(imei) {
-
 
757
			return imei;
-
 
758
		},
-
 
759
		autoSelect: true,
-
 
760
		afterSelect: callback
-
 
761
	}
-
 
762
 
-
 
763
	);
-
 
764
}
-
 
765
 
-
 
766
 
-
 
767
 
-
 
768
 
-
 
769
function getAllImeiAheadOptions(jqElement, callback) {
-
 
770
	jqElement.typeahead('destroy').typeahead({
-
 
771
		source: function(q, process) {
-
 
772
			if (q.length >= 3) {
-
 
773
				return $.ajax(context + "/allimei", {
-
 
774
					global: false,
-
 
775
					data: {
-
 
776
						query: q
-
 
777
					},
-
 
778
					success: function(data) {
748
						queryData = JSON.parse(data);
779
						queryData = JSON.parse(data);
749
						process(queryData);
780
						process(queryData);
750
					},
781
					},
751
				});
782
				});
752
			}
783
			}
753
		},
784
		},
754
		delay: 300,
785
		delay: 300,
755
		items: 20,
786
		items: 20,
756
		displayText: function (imei) {
787
		displayText: function(imei) {
757
			return imei;
788
			return imei;
758
		},
789
		},
759
		autoSelect: true,
790
		autoSelect: true,
760
		afterSelect: callback
791
		afterSelect: callback
761
	});
792
	});
762
}
793
}
763
 
794
 
764
 
795
 
765
function getEntityAheadOptions(jqElement, callback) {
796
function getEntityAheadOptions(jqElement, callback) {
766
	jqElement.typeahead('destroy').typeahead({
797
	jqElement.typeahead('destroy').typeahead({
767
		source: function (q, process) {
798
		source: function(q, process) {
768
			if (q.length >= 3) {
799
			if (q.length >= 3) {
769
				return $.ajax(context + "/entity", {
800
				return $.ajax(context + "/entity", {
770
					global: false,
801
					global: false,
771
					data: {
802
					data: {
772
						query: q
803
						query: q
773
					},
804
					},
774
					success: function (data) {
805
					success: function(data) {
775
						queryData = JSON.parse(data);
806
						queryData = JSON.parse(data);
776
						process(queryData);
807
						process(queryData);
777
					},
808
					},
778
				});
809
				});
779
			}
810
			}
780
		},
811
		},
781
		delay: 300,
812
		delay: 300,
782
		items: 30,
813
		items: 30,
783
		displayText: function (entity) {
814
		displayText: function(entity) {
784
			return entity.title_s + "(" + entity.catalogId_i + ")";
815
			return entity.title_s + "(" + entity.catalogId_i + ")";
785
		},
816
		},
786
		autoSelect: true,
817
		autoSelect: true,
787
		afterSelect: callback
818
		afterSelect: callback
788
	});
819
	});
789
}
820
}
790
 
821
 
791
function getPartnerAheadOptions(jqElement, callback) {
822
function getPartnerAheadOptions(jqElement, callback) {
792
	jqElement.typeahead('destroy').typeahead({
823
	jqElement.typeahead('destroy').typeahead({
793
		source: function (q, process) {
824
		source: function(q, process) {
794
			if (q.length >= 3) {
825
			if (q.length >= 3) {
795
				return $.ajax(context + "/partners", {
826
				return $.ajax(context + "/partners", {
796
					global: false,
827
					global: false,
797
					data: {
828
					data: {
798
						query: q
829
						query: q
799
					},
830
					},
800
					success: function (data) {
831
					success: function(data) {
801
						queryData = JSON.parse(data);
832
						queryData = JSON.parse(data);
802
						process(queryData);
833
						process(queryData);
803
					},
834
					},
804
				});
835
				});
805
			}
836
			}
806
		},
837
		},
807
		delay: 300,
838
		delay: 300,
808
		items: 20,
839
		items: 20,
809
		displayText: function (partner) {
840
		displayText: function(partner) {
810
			return partner.displayName;
841
			return partner.displayName;
811
		},
842
		},
812
		autoSelect: true,
843
		autoSelect: true,
813
		afterSelect: callback
844
		afterSelect: callback
814
	});
845
	});
815
}
846
}
816
 
847
 
817
function loadPriceDrop(domId) {
848
function loadPriceDrop(domId) {
818
	doGetAjaxRequestHandler(context + "/getItemDescription",
849
	doGetAjaxRequestHandler(context + "/getItemDescription",
819
		function (response) {
850
		function(response) {
820
			$('#' + domId).html(response);
851
			$('#' + domId).html(response);
821
		});
852
		});
822
}
853
}
823
 
854
 
824
$(document).on('click', ".price_drop", function () {
855
$(document).on('click', ".price_drop", function() {
825
	loadPriceDrop("main-content");
856
	loadPriceDrop("main-content");
826
});
857
});
827
 
858
 
828
 
859
 
829
$(document).on('click', ".closed_pricedrop", function () {
860
$(document).on('click', ".closed_pricedrop", function() {
830
	loadClosedPriceDrop("main-content");
861
	loadClosedPriceDrop("main-content");
831
});
862
});
832
 
863
 
833
function loadClosedPriceDrop(domId) {
864
function loadClosedPriceDrop(domId) {
834
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
865
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
835
		function (response) {
866
		function(response) {
836
			$('#' + domId).html(response);
867
			$('#' + domId).html(response);
837
		});
868
		});
838
}
869
}
839
 
870
 
840
function notifyTypeChange(messageType, $container) {
871
function notifyTypeChange(messageType, $container) {
841
	var messageQueryString = "?messageType=" + messageType;
872
	var messageQueryString = "?messageType=" + messageType;
842
	if (messageType == null) {
873
	if (messageType == null) {
843
		messageQueryString = "";
874
		messageQueryString = "";
844
	}
875
	}
845
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function (response) {
876
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function(response) {
846
		if ($container != null) {
877
		if ($container != null) {
847
			loaderDialogObj.one('hidden.bs.modal', function () {
878
			loaderDialogObj.one('hidden.bs.modal', function() {
848
				$container.popover({
879
				$container.popover({
849
					container: $container,
880
					container: $container,
850
					template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
881
					template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
851
					content: response,
882
					content: response,
852
					html: true,
883
					html: true,
853
					placement: "bottom",
884
					placement: "bottom",
854
					trigger: "manual",
885
					trigger: "manual",
855
					sanitize: false
886
					sanitize: false
856
				}).popover('show');
887
				}).popover('show');
857
				setTimeout(function () {
888
				setTimeout(function() {
858
					$container.focus().one('blur', function () {
889
					$container.focus().one('blur', function() {
859
						$container.popover('destroy');
890
						$container.popover('destroy');
860
					});
891
					});
861
				}, 100);
892
				}, 100);
862
			});
893
			});
863
		}
894
		}
Line 869... Line 900...
869
		documentName);
900
		documentName);
870
}
901
}
871
 
902
 
872
 
903
 
873
/* Create an array with the values of all the input boxes in a column */
904
/* Create an array with the values of all the input boxes in a column */
874
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
905
$.fn.dataTable.ext.order['dom-text'] = function(settings, col) {
875
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
906
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
876
		return $('input', td).val();
907
		return $('input', td).val();
877
	});
908
	});
878
}
909
}
879
 
910
 
880
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
911
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
881
$.fn.dataTable.ext.order['dom-text-numeric'] = function (settings, col) {
912
$.fn.dataTable.ext.order['dom-text-numeric'] = function(settings, col) {
882
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
913
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
883
		return $('input', td).val() * 1;
914
		return $('input', td).val() * 1;
884
	});
915
	});
885
}
916
}
886
 
917
 
887
$.fn.dataTable.ext.order['dom-stock-numeric'] = function (settings, col) {
918
$.fn.dataTable.ext.order['dom-stock-numeric'] = function(settings, col) {
888
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
919
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
889
		return $(td).html().split("/")[0] * 1;
920
		return $(td).html().split("/")[0] * 1;
890
	});
921
	});
891
}
922
}
892
/* Create an array with the values of all the select options in a column */
923
/* Create an array with the values of all the select options in a column */
893
$.fn.dataTable.ext.order['dom-select'] = function (settings, col) {
924
$.fn.dataTable.ext.order['dom-select'] = function(settings, col) {
894
	return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
925
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
895
		return $('select', td).val();
926
		return $('select', td).val();
896
	});
927
	});
897
}
928
}
898
 
929
 
899
/* Create an array with the values of all the checkboxes in a column */
930
/* Create an array with the values of all the checkboxes in a column */
900
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
931
$.fn.dataTable.ext.order['dom-checkbox'] = function(settings, col) {
901
	return this.api().column(col, {
932
	return this.api().column(col, {
902
		order: 'index'
933
		order: 'index'
903
	}).nodes().map(function (td, i) {
934
	}).nodes().map(function(td, i) {
904
		return $('input', td).prop('checked') ? '1' : '0';
935
		return $('input', td).prop('checked') ? '1' : '0';
905
	});
936
	});
906
}
937
}
907
 
938
 
908
$.fn.dataTable.Api.register('sum()', function () {
939
$.fn.dataTable.Api.register('sum()', function() {
909
	return this.flatten().reduce(function (a, b) {
940
	return this.flatten().reduce(function(a, b) {
910
		if (typeof a === 'string') {
941
		if (typeof a === 'string') {
911
			a = a.replace(/[^\d.-]/g, '') * 1;
942
			a = a.replace(/[^\d.-]/g, '') * 1;
912
			a = isNaN(a) ? 0 : a;
943
			a = isNaN(a) ? 0 : a;
913
		}
944
		}
914
		if (typeof b === 'string') {
945
		if (typeof b === 'string') {
Line 920... Line 951...
920
	}, 0);
951
	}, 0);
921
});
952
});
922
 
953
 
923
const debounce = (func, delay) => {
954
const debounce = (func, delay) => {
924
	let debounceTimer
955
	let debounceTimer
925
	return function () {
956
	return function() {
926
		const context = this
957
		const context = this
927
		const args = arguments
958
		const args = arguments
928
		clearTimeout(debounceTimer)
959
		clearTimeout(debounceTimer)
929
		debounceTimer
960
		debounceTimer
930
			= setTimeout(() => func.apply(context, args), delay)
961
			= setTimeout(() => func.apply(context, args), delay)
Line 936... Line 967...
936
	let tableId = $(container).data('tableid');
967
	let tableId = $(container).data('tableid');
937
	var elt = document.getElementById(tableId);
968
	var elt = document.getElementById(tableId);
938
	if ($.fn.DataTable.isDataTable(`#${tableId}`)) {
969
	if ($.fn.DataTable.isDataTable(`#${tableId}`)) {
939
		elt = $(`#${tableId}`).DataTable().table(0).container();
970
		elt = $(`#${tableId}`).DataTable().table(0).container();
940
	}
971
	}
941
	var wb = XLSX.utils.table_to_book(elt, {sheet: "sheet1"});
972
	var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
942
	return dl ?
973
	return dl ?
943
		XLSX.write(wb, {bookType: type, bookSST: true, type: 'base64'}) :
974
		XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
944
		XLSX.writeFile(wb, fn || ('MySheetName.' + (type || 'xlsx')));
975
		XLSX.writeFile(wb, fn || ('MySheetName.' + (type || 'xlsx')));
945
}
976
}
946
 
977
 
947
 
978
 
948
$(document).on('click', ".manage-pcm", function () {
979
$(document).on('click', ".manage-pcm", function() {
949
	managePCM();
980
	managePCM();
950
});
981
});
951
 
982
 
952
function managePCM() {
983
function managePCM() {
953
	doGetAjaxRequestHandler(`${context}/brand-pcm`, function (response) {
984
	doGetAjaxRequestHandler(`${context}/brand-pcm`, function(response) {
954
		$('#main-content').html(response);
985
		$('#main-content').html(response);
955
	});
986
	});
956
}
987
}