<!-- Background job progress indicator -->
<script type="text/javascript">
//<![CDATA[
+ var backgroundJobProgressTimer = 0;
var jobID = '';
var savedForm;
+ var inBackgroundJobProgressTimer = false;
function updateJobProgress() {
+ if (inBackgroundJobProgressTimer) {
+ return;
+ }
+ inBackgroundJobProgressTimer = true;
$.getJSON("/cgi-bin/koha/tools/background-job-progress.pl?jobID=" + jobID, function(json) {
var percentage = Math.floor(100 * json.progress / json.job_size);
if (json.job_status == 'completed') {
percentage = 100;
}
- $("#jobprogress").text(percentage + '%');
- if (percentage < 100) {
- setTimeout("updateJobProgress()",200);
- } else {
+ $("#jobprogress").text(percentage);
+ if (percentage == 100) {
+ clearInterval(backgroundJobProgressTimer); // just in case form submission fails
completeJob();
}
+ inBackgroundJobProgressTimer = false;
});
}
// and submit the request
$("#jobstatus").show();
- setTimeout("updateJobProgress()", 2000);
$.ajax({
data: inputs.join('&'),
url: f.action,
dataType: 'json',
success: function(json) {
jobID = json.jobID;
+ inBackgroundJobProgressTimer = false;
+ backgroundJobProgressTimer = setInterval("updateJobProgress()", 500);
},
error: function(xml, textStatus) {
alert('Failed to submit form: ' + testStatus);
f.submit();
}
- //$("#jobstatus").show();
- //setTimeout("updateJobProgress()",2000);
- //updateJobProgress();
return false;
}
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/ajaxfileupload.js"></script>
<script type="text/javascript">
//<![CDATA[
+ var fileUploadProgressTimer = 0;
+ var inFileUploadProgressTimer = false;
+ var fileUploadProgressTimerCanceled = false;
function updateProgress() {
+ if (inFileUploadProgressTimer) {
+ // since $.getJSON is asynchronous, wait
+ // until the last one is finished
+ return;
+ }
+ inFileUploadProgressTimer = true;
$.getJSON("/cgi-bin/koha/tools/upload-file-progress.pl", function(json) {
- $("#fileuploadprogress").text(json.progress + '%');
- if (json.progress < 100) {
- setTimeout("updateProgress()",200);
+ if (!fileUploadProgressTimerCanceled) {
+ $("#fileuploadprogress").text(json.progress);
}
+ inFileUploadProgressTimer = false;
});
}
function ajaxFileUpload()
{
-
+ fileUploadProgressTimerCanceled = false;
$("#fileuploadstatus").show();
- setTimeout("updateProgress()",2000);
+ fileUploadProgressTimer = setInterval("updateProgress()",500);
$.ajaxFileUpload (
{
url:'/cgi-bin/koha/tools/upload-file.pl',
$("#fileuploadfailed").text("Upload failed -- database in maintenance state");
} else {
$("#uploadedfileid").val(data.fileid);
+ $("#fileuploadprogress").text("100");
}
+ fileUploadProgressTimerCanceled = true;
+ clearInterval(fileUploadProgressTimer);
},
error: function (data, status, e) {
+ fileUploadProgressTimerCanceled = true;
alert(e);
+ clearInterval(fileUploadProgressTimer);
}
}
)
- updateProgress();
return false;
}