Bug 27461: Right pad with default elements for too short 008s

Note that we treat the elements 18-34 as one block of elements,
since its subdivision may vary.
E.g. if you pass 24 characters to the form, it will use the first
18 chars (until the last complete element) and pad with default
elements from position 18-39.

Test plan:
[1] Go to addbiblio. Make sure that 008 is connected to the plugin.
[2] Backspace field 008 a bit, click on the plugin button.
[3] Verify that the last elements come from the default.
[4] Repeat for a few different lengths.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Marcel de Rooy 2021-08-19 13:43:48 +00:00 committed by Jonathan Druart
parent c17adb49f3
commit 716f9c4ea2
2 changed files with 19 additions and 1 deletions

View file

@ -67,8 +67,9 @@ my $launcher = sub {
my ( $params ) = @_;
my $input = $params->{cgi};
my $default008 = biblio_008();
my $index = $input->param('index');
my $result = $input->param('result') || biblio_008();
my $result = $input->param('result') || $default008;
my $leader = $input->param('leader');
my $material_configuration;
@ -148,6 +149,7 @@ my $launcher = sub {
result => $result,
errorXml => $errorXml,
material_configuration => $material_configuration,
default008 => $default008,
);
output_html_with_http_headers $input, $cookie, $template->output;
};

View file

@ -62,6 +62,8 @@
var h4_result;
function loadXmlValues(){
$("#result").val( fix_field_008( $("#result").val() ) ); // fix field before loading elements
[% IF ( errorXml ) %]
alert("[% errorXml | html %]");
[% ELSE %]
@ -94,6 +96,20 @@
return false;
}
function fix_field_008( myfield ) {
// If field length < 40, append from default008 starting at last complete data element
var j, position = [ 6, 7, 11, 15, 18, 35, 38, 39, 40 ], defaultvalue = '[% default008 | $raw %]';
for( j=0; j<position.length; j++ ) {
if( myfield.length < position[j] ) break;
}
if( j == 0 ) {
return defaultvalue;
} else if( j < position.length ) {
return myfield.substring( 0, position[j-1] ) + defaultvalue.substring( position[j-1] );
}
return myfield;
}
</script>
[% END %]