From f97726406697f7973d2f8118049acaac2f95a3ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9rick=20Capovilla?= Date: Wed, 5 Oct 2011 13:16:37 -0400 Subject: [PATCH] Bug 6977 : Adds support for repeatable subfields when importing authorities. Before this patch, if we tried to import an authority with multiple $x subfields into a bibliographic record, only the last value get added to the form. All repeated values should now be sent to the form. Signed-off-by: Jared Camins-Esakov Signed-off-by: Paul Poulain Signed-off-by: Ian Walls Signed-off-by: Chris Cormack --- authorities/blinddetail-biblio-search.pl | 21 ++++- .../authorities/blinddetail-biblio-search.tt | 79 ++++++++++++++++--- 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/authorities/blinddetail-biblio-search.pl b/authorities/blinddetail-biblio-search.pl index 0f734b2062..7de7db3095 100755 --- a/authorities/blinddetail-biblio-search.pl +++ b/authorities/blinddetail-biblio-search.pl @@ -80,10 +80,20 @@ if ($authid) { my @fields = $record->field( $auth_type->{auth_tag_to_report} ); my $repet = ($query->param('repet') || 1) - 1; my $field = $fields[$repet]; + + # Get all values for each distinct subfield + my %subfields; for ( $field->subfields ) { - my ($letter, $value) = @$_; - $letter = '@' unless $letter; - push @subfield_loop, { marc_subfield => $letter, marc_value => $value }; + my $letter = $_->[0]; + next if defined $subfields{$letter}; + my @values = $field->subfield($letter); + $subfields{$letter} = \@values; + } + + # Add all subfields to the subfield_loop + for( keys %subfields ) { + my $letter = $_ || '@'; + push( @subfield_loop, {marc_subfield => $letter, marc_values => $subfields{$_}} ); } } else { @@ -91,11 +101,16 @@ else { $template->param( "clear" => 1 ); } +# Extract the tag number from the index +my $tag_number = $index; +$tag_number =~ s/^tag_(\d*)_.*$/$1/; + $template->param( authid => $authid ? $authid : "", index => $index, tagid => $tagid, SUBFIELD_LOOP => \@subfield_loop, + tag_number => $tag_number, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt index 6a7064b137..169728918c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt @@ -11,9 +11,11 @@ } catch(e) { return; } - - // browse all its subfields - var subfields = whichfield.parentNode.parentNode.getElementsByTagName('input'); + + var field_start = whichfield.parentNode.parentNode; + + // browse all its subfields (clear and $9) + var subfields = field_start.getElementsByTagName('input'); var re = /^tag_\d*_code_/; for(var i=0, len = subfields.length ; i< len ; i++) { // browse all subfields if(subfields[i].getAttribute('name').match(re)){ // it s a subfield @@ -22,18 +24,73 @@ [% IF ( clear ) %] if (subfield){subfield.value="" ;} - [% ELSE %] - [% FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP %] - if (code.value == "[% SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"){ - subfield.value = "[% SUBFIELD_LOO.marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"; + [% ELSE %] + if(code.value=='9'){ + subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"; } - [% END %] - if(code.value=='9'){ - subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"; - } [% END %] } } + + // Sets the good number of form fields for the specified subfield + function SetSubfieldNumber(subfield_name, nb) { + // Nothing to do if we only have one value + if(nb <= 1) { + return; + } + + // Find the subfield we want to clone + var re = new RegExp('^subfield' + subfield_name,'g'); + var subfields = $(field_start).children('div').filter( function() { + return this.id.match(re); + }); + + // Add as many clones as needed + for(var i=0; i