1 <!-- Background job progress indicator -->
2 <script type="text/javascript">
4 var backgroundJobProgressTimer = 0;
7 var inBackgroundJobProgressTimer = false;
8 function updateJobProgress() {
9 if (inBackgroundJobProgressTimer) {
12 inBackgroundJobProgressTimer = true;
13 $.getJSON("/cgi-bin/koha/tools/background-job-progress.pl?jobID=" + jobID, function(json) {
14 var percentage = Math.floor(100 * json.progress / json.job_size);
15 if (json.job_status == 'completed') {
18 var bgproperty = (parseInt(percentage/2)*3-300)+"px 0px";
19 $("#jobprogress").css("background-position",bgproperty);
20 $("#jobprogresspercent").text(percentage);
22 if (percentage == 100) {
23 clearInterval(backgroundJobProgressTimer); // just in case form submission fails
26 inBackgroundJobProgressTimer = false;
30 function completeJob() {
31 savedForm.completedJobID.value = jobID;
35 // submit a background job with data
36 // supplied from form f and activate
38 function submitBackgroundJob(f) {
39 // check for background field
40 if (f.runinbackground) {
41 // set value of this hidden field for
44 f.mainformsubmit.disabled = true;
45 f.runinbackground.value = 'true';
47 // gather up form submission
49 $(':input', f).each(function() {
50 if (this.type == 'radio' || this.type == 'checkbox') {
52 inputs.push(this.name + '=' + escape(this.value));
54 } else if (this.type == 'button') {
57 inputs.push(this.name + '=' + escape(this.value));
62 // and submit the request
63 $("#jobpanel").show();
64 $("#jobstatus").show();
66 data: inputs.join('&'),
70 success: function(json) {
72 inBackgroundJobProgressTimer = false;
73 backgroundJobProgressTimer = setInterval("updateJobProgress()", 500);
75 error: function(xml, textStatus) {
76 alert('Failed to submit form: ' + textStatus);
82 // background job support not enabled,
83 // so just do a normal form submission