69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
function matchFuelLogs() {
|
|
$('.breadcrumb').hide();
|
|
$('tr:not(.complete) .match-status').append('<span class="label">Pending</span');
|
|
var total = $("#fuellogs > tbody > tr:not(.complete)").length;
|
|
$('#page-match-status').html('<span class="label label-warning"><i class="fa fa-spinner fa-spin"></i> Matching In Progress</span> for ' + total + ' fuel logs. <strong>Keep page open until complete.</strong>');
|
|
$('#page-match-status').after('<div class="progress progress-striped active"><div class="bar" style="width:0%"></div><div>');
|
|
|
|
$(".match-status a").addClass('pull-right');
|
|
|
|
submitNext();
|
|
var unmatchedCount = 0;
|
|
var errorCount = 0;
|
|
|
|
function submitNext() {
|
|
var $fuelLogs = $("#fuellogs > tbody > tr:not(.complete)");
|
|
var percentComplete = Math.round( (1 - ($fuelLogs.length / total)) * 100 );
|
|
$('.progress .bar').attr('style', 'width:' + percentComplete + '%');
|
|
|
|
if ($fuelLogs.length > 0) {
|
|
var $row = $($fuelLogs[0]);
|
|
var data = $('form', $row).serialize();
|
|
var url = $('form', $row).attr('action');
|
|
|
|
$('.match-status', $row).html('<span class="label label-info"><i class="fa fa-spinner fa-spin"></i> Submitting</span>');
|
|
|
|
$.ajax({
|
|
url: url,
|
|
type: 'post',
|
|
data: data,
|
|
success: function (result) {
|
|
$row.addClass("complete");
|
|
if (result.Status == "Match") {
|
|
$('.match-status', $row).html('<span class="label label-success">Match found</span>');
|
|
}
|
|
else if (result.Status == "NoMatch" || result.Status == "Error") {
|
|
if (result.Status == "NoMatch") {
|
|
$('.match-status', $row).html('<span class="label label-warning">No Match</span>');
|
|
unmatchedCount++;
|
|
} else {
|
|
$('.match-status', $row).html('<span class="label label-important">Error</span>');
|
|
errorCount++;
|
|
$('.progress .bar').addClass('bar-warning');
|
|
}
|
|
$('.match-message', $row).text(result.Message);
|
|
}
|
|
|
|
if (result.Action != undefined && result.Action != null) {
|
|
$('.match-status', $row).append(" " + result.Action);
|
|
$("a", $row).addClass('pull-right');
|
|
matchCountFunc.apply($("a[matchcount]", $row));
|
|
}
|
|
|
|
submitNext();
|
|
}
|
|
});
|
|
} else {
|
|
$('.breadcrumb').show();
|
|
$('.progress').removeClass('progress-striped');
|
|
$('.progress').removeClass('active');
|
|
if (errorCount == 0) {
|
|
$('#page-match-status').html('<span class="label">Complete</span> ' + total + ' total with <strong>' + unmatchedCount + '</strong> left unmatched.');
|
|
$('.progress .bar').addClass('bar-success');
|
|
} else {
|
|
$('#page-match-status').html('<span class="label label-warning">Complete</span> with errors. See below.');
|
|
}
|
|
}
|
|
}
|
|
}
|