Koha/koha-tmpl/intranet-tmpl/prog/en/js/background-job-progressbar.js
Fridolyn SOMERS 0397e7ea64 Bug 9113: fix handling of certain characters by item batch modification tool
If you're using the batch modification tool and entering a call number
like "E+ 123 ABC", the tool removes the + and puts a space in its place,
e.g., "E  123 ABC"

This is because the form is posted via Ajax by background-job-progressbar.js.
Values are URI-encoded using escape(), but this method does not escape some
characters: * @ - _ + . /

Also, "+" is considered as a space in a URI.

This patch replaces escape() by encodeURIComponent() which encodes every character.

Test plan :
Perform an items batch modification by setting '* @ - _ + . /' in a field
(notes for example) and see that all characters are saved correctly.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2013-07-05 15:35:25 +00:00

84 lines
2.6 KiB
JavaScript

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 + '=' + encodeURIComponent(this.value));
}
} else if (this.type == 'button') {
; // do nothing
} else {
inputs.push(this.name + '=' + encodeURIComponent(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;
}