Bugzilla – Attachment 5851 Details for
Bug 6977
Support for repeated subfields when importing an authority into a biblio record field.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Adds support for repeatable subfields when importing authorities.
Adds-support-for-repeatable-subfields-when-importi.patch (text/plain), 6.80 KB, created by
Paul Poulain
on 2011-10-12 13:13:18 UTC
(
hide
)
Description:
Adds support for repeatable subfields when importing authorities.
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2011-10-12 13:13:18 UTC
Size:
6.80 KB
patch
obsolete
>From 066a8dd5e7cf0d3d42b4d70845ad322cdbfc9c68 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick=20Capovilla?= <frederick.capovilla@libeo.com> >Date: Wed, 5 Oct 2011 13:16:37 -0400 >Subject: [PATCH] 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. > >http://bugs.koha-community.org/show_bug.cgi?id=6977 >Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> >Signed-off-by: Paul Poulain <paul.poulain@biblibre.com> >--- > 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 0f734b2..7de7db3 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 6a7064b..1697289 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<nb-subfields.length; i++) { >+ window.opener.opener.CloneSubfield(subfields[0].getAttribute('id')); >+ } >+ } >+ >+ // Fills the subfield with the values entered in argument >+ function SetSubfieldValues() { >+ // Get the arguments >+ var subfield_name = arguments[0]; >+ var values = new Array(); >+ for(var i=1; i<arguments.length; i++) { >+ values.push(arguments[i]); >+ } >+ >+ // Create the correct number of form fields for all values >+ SetSubfieldNumber(subfield_name, values.length); >+ >+ // Find the subfields where we will add the new values >+ var re = new RegExp('^subfield' + subfield_name,'g'); >+ var subfields = $(field_start).children('div').filter( function() { >+ return this.id.match(re); >+ }); >+ >+ // Add the new values to those subfields, empty the additional fields >+ var i=0; >+ subfields.each(function() { >+ if(i in values) { >+ this.getElementsByTagName('input')[1].value = values[i]; >+ } >+ else { >+ this.getElementsByTagName('input')[1].value = ""; >+ } >+ i++; >+ }); >+ } >+ >+ [% FOREACH SUBFIELD_LOO IN SUBFIELD_LOOP %] >+ SetSubfieldValues( >+ "[% tag_number |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %][% SUBFIELD_LOO.marc_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]" >+ [% FOREACH marc_value IN SUBFIELD_LOO.marc_values %] >+ ,"[% marc_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]" >+ [% END %] >+ ); >+ [% END %] >+ > opener.close(); > window.close(); > >-- >1.7.4.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 6977
:
5719
|
5801
| 5851 |
6020
|
6285