var notesText = "";
document.addEventListener('eInspListSynch', function (e) {
notesText += "Number of records to save : " + inspRecordList.length.toString() + "rn";
$("#SynchNotes").html(notesText);
$("#synchProgressBar").progressbar({
value: 0,
max: inspRecordList.length
}).show();
// Recursive call.
SendARecord(0);
});
// Recursive call required here because Chrome will set browser updates off when asynch false is set for ajax calls.
function SendARecord(currentRecord)
{
oneInspRecord.recordId = 99;
oneInspRecord.weatherId = 5;
var cntOfInspSaved = 0;
oneInspRecord.contractorName = "CYoung";
var pbVal = $("#synchProgressBar").progressbar("value");
$("#synchProgressBar").progressbar("value", pbVal + 1);
$("#synchProgressBar").show();
$.ajax({
type: "Post",
url: '@Url.Content("~/SiteVisitInspection/SaveOneSiteVisitInspection/")',
dataType: 'text',
success: function (res) {
// If successful then delete the record from local cache.
notesText = inspRecordList[currentRecord].recordId.toString() + " written to server.rn" + notesText;
currentRecord = currentRecord + 1;
$("#SynchNotes").html(notesText);
if (currentRecord < inspRecordList.length) {
SendARecord(currentRecord);
}
else {
$("#synchProgressBar").hide();
notesText = "Completed synchronization.rn" + notesText;
$("#SynchNotes").html(notesText);
return;
}
},
error: function (error) {
console.log("Error in SaveOneSiteVisitInspection.");
},
data: oneInspRecord//,
//async: false
})
}