From ae48a3198ee78a0a468462d34e01eb6cb13b8adc Mon Sep 17 00:00:00 2001 From: Srdjan Date: Fri, 23 Mar 2012 13:08:54 +1300 Subject: [PATCH] bug 6372: moved background-job.inc to background-job-progressbar.js Check for div 0 when calculating percentage Signed-off-by: Liz Rea div0 no longer appears on 0 size jobs. Passes t xt Signed-off-by: Paul Poulain Signed-off-by: Chris Cormack --- .../prog/en/includes/background-job.inc | 91 ------------------- .../prog/en/js/background-job-progressbar.js | 84 +++++++++++++++++ .../en/modules/offline_circ/process_koc.tt | 2 +- .../prog/en/modules/test/progressbar.tt | 2 +- .../prog/en/modules/tools/batchMod-del.tt | 2 +- .../prog/en/modules/tools/batchMod-edit.tt | 2 +- .../en/modules/tools/manage-marc-import.tt | 2 +- .../en/modules/tools/stage-marc-import.tt | 2 +- .../prog/en/modules/tools/upload-images.tt | 2 +- tools/batchMod.pl | 10 -- 10 files changed, 91 insertions(+), 108 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/background-job-progressbar.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc deleted file mode 100644 index b18d5ce39a..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/background-job.inc +++ /dev/null @@ -1,91 +0,0 @@ - - diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/background-job-progressbar.js b/koha-tmpl/intranet-tmpl/prog/en/js/background-job-progressbar.js new file mode 100644 index 0000000000..2804182969 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/js/background-job-progressbar.js @@ -0,0 +1,84 @@ +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 = json.job_status == 'completed' ? 100 : + json.job_size > 0 ? Math.floor(100 * json.progress / json.job_size) : + 100; + var bgproperty = (parseInt(percentage/2)*3-300)+"px 0px"; + $("#jobprogress").css("background-position",bgproperty); + $("#jobprogresspercent").text(percentage); + + if (percentage == 100) { + clearInterval(backgroundJobProgressTimer); // just in case form submission fails + completeJob(); + } + inBackgroundJobProgressTimer = false; + }); +} + +function completeJob() { + savedForm.completedJobID.value = jobID; + savedForm.submit(); +} + +// submit a background job with data +// supplied from form f and activate +// progress indicator +function submitBackgroundJob(f) { + // check for background field + if (f.runinbackground) { + // set value of this hidden field for + // use by CGI script + savedForm = f; + f.mainformsubmit.disabled = true; + f.runinbackground.value = 'true'; + + // gather up form submission + var inputs = []; + $(':input', f).each(function() { + if (this.type == 'radio' || this.type == 'checkbox') { + if (this.checked) { + inputs.push(this.name + '=' + escape(this.value)); + } + } else if (this.type == 'button') { + ; // do nothing + } else { + inputs.push(this.name + '=' + escape(this.value)); + } + + }); + + // and submit the request + $("#jobpanel").show(); + $("#jobstatus").show(); + $.ajax({ + data: inputs.join('&'), + url: f.action, + dataType: 'json', + type: 'post', + success: function(json) { + jobID = json.jobID; + inBackgroundJobProgressTimer = false; + backgroundJobProgressTimer = setInterval("updateJobProgress()", 500); + }, + error: function(xml, textStatus) { + alert('Failed to submit form: ' + textStatus); + } + + }); + + } else { + // background job support not enabled, + // so just do a normal form submission + f.submit(); + } + + return false; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/offline_circ/process_koc.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/offline_circ/process_koc.tt index a101023961..b818039cec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/offline_circ/process_koc.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/offline_circ/process_koc.tt @@ -2,7 +2,7 @@ Koha › Circulation › Offline circulation file upload [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'file-upload.inc' %] -[% INCLUDE 'background-job.inc' %] +