1 var backgroundJobProgressTimer = 0;
4 var inBackgroundJobProgressTimer = false;
5 function updateJobProgress() {
6 if (inBackgroundJobProgressTimer) {
9 inBackgroundJobProgressTimer = true;
10 $.getJSON("/cgi-bin/koha/tools/background-job-progress.pl?jobID=" + jobID, function(json) {
11 var percentage = json.job_status == 'completed' ? 100 :
12 json.job_size > 0 ? Math.floor(100 * json.progress / json.job_size) :
14 var bgproperty = (parseInt(percentage*2)-300)+"px 0px";
15 $("#jobprogress").css("background-position",bgproperty);
16 $("#jobprogresspercent").text(percentage);
18 if (percentage == 100) {
19 clearInterval(backgroundJobProgressTimer); // just in case form submission fails
22 inBackgroundJobProgressTimer = false;
26 function completeJob() {
27 savedForm.completedJobID.value = jobID;
31 // submit a background job with data
32 // supplied from form f and activate
34 function submitBackgroundJob(f) {
35 // check for background field
36 if (f.runinbackground) {
37 // set value of this hidden field for
40 f.mainformsubmit.disabled = true;
41 f.runinbackground.value = 'true';
43 // gather up form submission
45 $(':input', f).each(function() {
46 if (this.type == 'radio' || this.type == 'checkbox') {
48 inputs.push(this.name + '=' + encodeURIComponent(this.value));
50 } else if (this.type == 'button') {
53 inputs.push(this.name + '=' + encodeURIComponent(this.value));
58 // and submit the request
59 $("#jobpanel").show();
60 $("#jobstatus").show();
62 data: inputs.join('&'),
66 success: function(json) {
68 inBackgroundJobProgressTimer = false;
69 backgroundJobProgressTimer = setInterval("updateJobProgress()", 500);
71 error: function(xml, textStatus) {
72 humanMsg.displayMsg( '<p>' + _('Import of record(s) failed: ') + textStatus + '</p></br>'+xml.responseText, { className: 'humanError' } );
78 // background job support not enabled,
79 // so just do a normal form submission