Fuel Log Import basic functionality

This commit is contained in:
2015-09-18 13:02:15 -04:00
parent 4987215f0b
commit e3590b29e5
18 changed files with 438 additions and 59 deletions
+61
View File
@@ -0,0 +1,61 @@
function importFuelLogs() {
$('.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> <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>');
submitNext();
var failureCount = 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>');
} else {
$('.match-status', $row).html('<span class="label label-important">Error</span>');
}
$('.match-message', $row).text(result.Message);
failureCount++;
$('.progress .bar').addClass('bar-warning');
}
if (result.Action != undefined && result.Action != null) {
$('.match-status', $row).append(" " + result.Action);
}
submitNext();
}
});
} else {
$('.breadcrumb').show();
$('.progress').removeClass('progress-striped');
$('.progress').removeClass('active');
if (failureCount == 0) {
$('#page-match-status').html('<span class="label">Complete</span> with all matches.');
$('.progress .bar').addClass('bar-success');
} else {
$('#page-match-status').html('<span class="label label-warning">Complete</span> but with errors. See details below.');
}
}
}
}