From a54f4eb8a213b8f17a0962e39666d15f878fb55f Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 22 Sep 2022 09:53:46 +0200 Subject: [PATCH] Bug 32484: Enable plugins when UseACQFrameworkForBiblioRecords is set Content-Type: text/plain; charset=utf-8 Test plan: 1. Do not apply the patch yet 2. Make sure you have an ACQ biblio framework with some framework plugins enabled. Create it if you don't. 3. Enable UseACQFrameworkForBiblioRecords system preference 4. Create a new acquisition basket. 5. On this new basket, click on "+ Add to basket", then "From a new (empty) record" 6. You should see a simplified MARC editor based on ACQ framework. Confirm that the plugins are not enabled (no visible buttons, nothing happening on focus/blur) 7. Apply patch 8. Repeat step 5 9. You should now see the plugins' buttons (only if you enabled plugins that use the 'click' event) 10. Confirm that the enabled plugins work correctly Signed-off-by: David Nind Signed-off-by: Marcel de Rooy --- Koha/UI/Form/Builder/Biblio.pm | 372 +++++++++++++++ acqui/neworderempty.pl | 60 ++- cataloguing/addbiblio.pl | 350 +++----------- .../prog/en/modules/acqui/neworderempty.tt | 444 +++++++++--------- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 3 +- t/db_dependent/Koha/UI/Form/Builder/Biblio.t | 182 +++++++ 6 files changed, 864 insertions(+), 547 deletions(-) create mode 100644 Koha/UI/Form/Builder/Biblio.pm create mode 100755 t/db_dependent/Koha/UI/Form/Builder/Biblio.t diff --git a/Koha/UI/Form/Builder/Biblio.pm b/Koha/UI/Form/Builder/Biblio.pm new file mode 100644 index 0000000000..eca798b06d --- /dev/null +++ b/Koha/UI/Form/Builder/Biblio.pm @@ -0,0 +1,372 @@ +package Koha::UI::Form::Builder::Biblio; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use C4::Context; +use C4::ClassSource qw( GetClassSources ); +use Koha::DateUtils qw( dt_from_string ); +use Koha::ItemTypes; +use Koha::Libraries; + +=head1 NAME + +Koha::UI::Form::Builder::Biblio + +Helper to build a form to add or edit a new biblio + +=head1 API + +=head2 Class methods + +=cut + +=head3 new + + my $form = Koha::UI::Form::Builder::Biblio->new( + { + biblionumber => $biblionumber, + } + ); + +=cut + + +sub new { + my ( $class, $params ) = @_; + + my $self = {}; + $self->{biblionumber} = $params->{biblionumber}; + + bless $self, $class; + return $self; +} + +=head3 generate_subfield_form + +Generate subfield's info for given tag, subfieldtag, etc. + +=cut + +sub generate_subfield_form { + my ($self, $params) = @_; + + my $tag = $params->{tag}; + my $subfield = $params->{subfield}; + my $value = $params->{value} // ''; + my $index_tag = $params->{index_tag}; + my $rec = $params->{record}; + my $hostitemnumber = $params->{hostitemnumber}; + my $op = $params->{op} // ''; + my $changed_framework = $params->{changed_framework}; + my $breedingid = $params->{breedingid}; + my $tagslib = $params->{tagslib}; + my $mandatory_z3950 = $params->{mandatory_z3950} // {}; + + my $index_subfield = $self->create_key(); # create a specifique key for each subfield + + # Apply optional framework default value when it is a new record, + # or when editing as new (duplicating a record), + # or when changing a record's framework, + # or when importing a record, + # based on the ApplyFrameworkDefaults setting. + # Substitute date parts, user name + my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults'); + if ( $value eq '' && ( + ( $applydefaults =~ /new/ && !$self->{biblionumber} ) || + ( $applydefaults =~ /duplicate/ && $op eq 'duplicate' ) || + ( $applydefaults =~ /changed/ && $changed_framework ) || + ( $applydefaults =~ /imported/ && $breedingid ) + ) ) { + $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{}; + + # get today date & replace <>, <>, <>, <
> if provided in the default value + my $today_dt = dt_from_string; + my $year = $today_dt->strftime('%Y'); + my $shortyear = $today_dt->strftime('%y'); + my $month = $today_dt->strftime('%m'); + my $day = $today_dt->strftime('%d'); + $value =~ s/<>/$year/g; + $value =~ s/<>/$shortyear/g; + $value =~ s/<>/$month/g; + $value =~ s/<
>/$day/g; + # And <> with surname (?) + my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian"); + $value=~s/<>/$username/g; + } + + my $dbh = C4::Context->dbh; + + # map '@' as "subfield" label for fixed fields + # to something that's allowed in a div id. + my $id_subfield = $subfield; + $id_subfield = "00" if $id_subfield eq "@"; + + my %subfield_data = ( + tag => $tag, + subfield => $id_subfield, + marc_lib => $tagslib->{$tag}->{$subfield}->{lib}, + tag_mandatory => $tagslib->{$tag}->{mandatory}, + mandatory => $tagslib->{$tag}->{$subfield}->{mandatory}, + important => $tagslib->{$tag}->{$subfield}->{important}, + repeatable => $tagslib->{$tag}->{$subfield}->{repeatable}, + kohafield => $tagslib->{$tag}->{$subfield}->{kohafield}, + index => $index_tag, + id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield, + value => $value, + maxlength => $tagslib->{$tag}->{$subfield}->{maxlength}, + random => $self->create_key(), + ); + + if (exists $mandatory_z3950->{$tag.$subfield}){ + $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield}; + } + # Subfield is hidden depending of hidden and mandatory flag, and is always + # shown if it contains anything or if its field is mandatory or important. + my $tdef = $tagslib->{$tag}; + $subfield_data{visibility} = "display:none;" + if $tdef->{$subfield}->{hidden} % 2 == 1 && + $value eq '' && + !$tdef->{$subfield}->{mandatory} && + !$tdef->{mandatory} && + !$tdef->{$subfield}->{important} && + !$tdef->{important}; + # expand all subfields of 773 if there is a host item provided in the input + $subfield_data{visibility} = '' if ($tag eq '773' and $hostitemnumber); + + + # it's an authorised field + if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { + $subfield_data{marc_value} = $self->build_authorized_values_list( + { + tag => $tag, + subfield => $subfield, + value => $value, + index_tag => $index_tag, + index_subfield => $index_subfield, + tagslib => $tagslib, + } + ); + } + # it's a subfield $9 linking to an authority record - see bug 2206 and 28022 + elsif ($subfield eq "9" and + exists($tagslib->{$tag}->{'a'}->{authtypecode}) and + defined($tagslib->{$tag}->{'a'}->{authtypecode}) and + $tagslib->{$tag}->{'a'}->{authtypecode} ne '' and + $tagslib->{$tag}->{'a'}->{hidden} > -4 and + $tagslib->{$tag}->{'a'}->{hidden} < 5) { + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 5, + maxlength => $subfield_data{maxlength}, + readonly => 1, + }; + + # it's a thesaurus / authority field + } + elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { + # when authorities auto-creation is allowed, do not set readonly + my $is_readonly = C4::Context->preference('RequireChoosingExistingAuthority'); + + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + readonly => ($is_readonly) ? 1 : 0, + authtype => $tagslib->{$tag}->{$subfield}->{authtypecode}, + }; + + # it's a plugin field + } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) { + require Koha::FrameworkPlugin; + my $plugin = Koha::FrameworkPlugin->new( { + name => $tagslib->{$tag}->{$subfield}->{'value_builder'}, + }); + my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib, + id => $subfield_data{id} }; + $plugin->build( $pars ); + if( !$plugin->errstr ) { + $subfield_data{marc_value} = { + type => 'text_complex', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + javascript => $plugin->javascript, + plugin => $plugin->name, + noclick => $plugin->noclick, + }; + } else { + warn $plugin->errstr; + # supply default input form + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + readonly => 0, + }; + } + + # it's an hidden field + } elsif ( $tag eq '' ) { + $subfield_data{marc_value} = { + type => 'hidden', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + }; + + } + else { + # it's a standard field + if ( + length($value) > 100 + or + ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300 + and $tag < 400 && $subfield eq 'a' ) + or ( $tag >= 500 + and $tag < 600 + && C4::Context->preference("marcflavour") eq "MARC21" ) + ) + { + $subfield_data{marc_value} = { + type => 'textarea', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + }; + + } + else { + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + name => $subfield_data{id}, + value => $value, + size => 67, + maxlength => $subfield_data{maxlength}, + readonly => 0, + }; + + } + } + $subfield_data{'index_subfield'} = $index_subfield; + + return \%subfield_data; +} + +sub build_authorized_values_list { + my ($self, $params) = @_; + + my $tag = $params->{tag}; + my $subfield = $params->{subfield}; + my $value = $params->{value}; + my $index_tag = $params->{index_tag}; + my $index_subfield = $params->{index_subfield}; + my $tagslib = $params->{tagslib}; + + my @authorised_values; + my %authorised_lib; + + # builds list, depending on authorised value... + + #---- branch + my $category = $tagslib->{$tag}->{$subfield}->{authorised_value}; + if ( $category eq "branches" ) { + my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']}); + while ( my $l = $libraries->next ) { + push @authorised_values, $l->branchcode; + $authorised_lib{$l->branchcode} = $l->branchname; + } + } + elsif ( $category eq "itemtypes" ) { + push @authorised_values, ""; + + my $itemtype; + my $itemtypes = Koha::ItemTypes->search_with_localization; + while ( $itemtype = $itemtypes->next ) { + push @authorised_values, $itemtype->itemtype; + $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; + } + $value = $itemtype unless ($value); + } + elsif ( $category eq "cn_source" ) { + push @authorised_values, ""; + + my $class_sources = GetClassSources(); + + my $default_source = C4::Context->preference("DefaultClassificationSource"); + + foreach my $class_source (sort keys %$class_sources) { + next unless $class_sources->{$class_source}->{'used'} or + ($value and $class_source eq $value) or + ($class_source eq $default_source); + push @authorised_values, $class_source; + $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'}; + } + $value = $default_source unless $value; + } + else { + my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{branch} : ''; + my $query = 'SELECT authorised_value, lib FROM authorised_values'; + $query .= ' LEFT JOIN authorised_values_branches ON ( id = av_id )' if $branch_limit; + $query .= ' WHERE category = ?'; + $query .= ' AND ( branchcode = ? OR branchcode IS NULL )' if $branch_limit; + $query .= ' GROUP BY authorised_value,lib ORDER BY lib, lib_opac'; + my $authorised_values_sth = C4::Context->dbh->prepare($query); + + $authorised_values_sth->execute( + $tagslib->{$tag}->{$subfield}->{authorised_value}, + $branch_limit ? $branch_limit : (), + ); + + push @authorised_values, ""; + + while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { + push @authorised_values, $value; + $authorised_lib{$value} = $lib; + } + } + + return { + type => 'select', + id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, + default => $value, + values => \@authorised_values, + labels => \%authorised_lib, + ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ), + }; + +} + +sub create_key { + return int(rand(1000000)); +} + +1; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index a584ea1d11..2a976114cf 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -99,6 +99,7 @@ use Koha::ItemTypes; use Koha::Patrons; use Koha::RecordProcessor; use Koha::Subscriptions; +use Koha::UI::Form::Builder::Biblio; our $input = CGI->new; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! @@ -207,9 +208,11 @@ if ( not $ordernumber ) { # create order } if ( not $biblionumber and Koha::BiblioFrameworks->find('ACQ') ) { + my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new(); foreach my $tag ( sort keys %{$tagslib} ) { next if $tag eq ''; next if $tag eq $itemnumber_tag; # skip items fields + my $index_tag = int(rand(1000000)); foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) { my $mss = $tagslib->{$tag}{$subfield}; next if IsMarcStructureInternal($mss); @@ -241,32 +244,15 @@ if ( not $ordernumber ) { # create order } } - if ( $value ) { - - # get today date & replace <>, <>, <>, <
> if provided in the default value - my $today_dt = dt_from_string; - my $year = $today_dt->strftime('%Y'); - my $shortyear = $today_dt->strftime('%y'); - my $month = $today_dt->strftime('%m'); - my $day = $today_dt->strftime('%d'); - $value =~ s/<>/$year/g; - $value =~ s/<>/$shortyear/g; - $value =~ s/<>/$month/g; - $value =~ s/<
>/$day/g; - - # And <> with surname (?) - my $username = - ( C4::Context->userenv - ? C4::Context->userenv->{'surname'} - : "superlibrarian" ); - $value =~ s/<>/$username/g; - } - push @catalog_details, { - tag => $tag, - subfield => $subfield, - %$mss, # Do we need plugins support (?) - value => $value, - }; + push @catalog_details, $biblio_form_builder->generate_subfield_form( + { + tag => $tag, + subfield => $subfield, + value => $value, + index_tag => $index_tag, + tagslib => $tagslib, + } + ); } } } @@ -298,10 +284,16 @@ if ( not $ordernumber or $biblionumber ) { if ( C4::Context->preference('UseACQFrameworkForBiblioRecords') ) { my $biblio = Koha::Biblios->find($biblionumber); my $record = $biblio ? $biblio->metadata->record : undef; + my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new( + { + biblionumber => $biblionumber, + } + ); foreach my $tag ( sort keys %{$tagslib} ) { next if $tag eq ''; next if $tag eq $itemnumber_tag; # skip items fields my @fields = $biblionumber ? $record->field($tag) : (); + my $index_tag = int(rand(1000000)); foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) { my $mss = $tagslib->{$tag}{$subfield}; next if IsMarcStructureInternal($mss); @@ -309,12 +301,16 @@ if ( not $ordernumber or $biblionumber ) { # We only need to display the values my $value = join '; ', map { $tag < 10 ? $_->data : $_->subfield( $subfield ) } @fields; if ( $value ) { - push @catalog_details, { - tag => $tag, - subfield => $subfield, - %$mss, - value => $value, - }; + push @catalog_details, $biblio_form_builder->generate_subfield_form( + { + tag => $tag, + subfield => $subfield, + value => $value, + index_tag => $index_tag, + record => $record, + tagslib => $tagslib, + } + ); } } } diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 815e2a80d4..23a2fa45a3 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -53,6 +53,7 @@ use Koha::Libraries; use Koha::BiblioFrameworks; use Koha::Patrons; +use Koha::UI::Form::Builder::Biblio; use MARC::File::USMARC; use MARC::File::XML; @@ -172,82 +173,6 @@ sub MARCfindbreeding { return -1; } -=head2 build_authorized_values_list - -=cut - -sub build_authorized_values_list { - my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_; - - my @authorised_values; - my %authorised_lib; - - # builds list, depending on authorised value... - - #---- branch - my $category = $tagslib->{$tag}->{$subfield}->{authorised_value}; - if ( $category eq "branches" ) { - my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']}); - while ( my $l = $libraries->next ) { - push @authorised_values, $l->branchcode;; - $authorised_lib{$l->branchcode} = $l->branchname; - } - } - elsif ( $category eq "itemtypes" ) { - push @authorised_values, ""; - - my $itemtype; - my $itemtypes = Koha::ItemTypes->search_with_localization; - while ( $itemtype = $itemtypes->next ) { - push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; - } - $value = $itemtype unless ($value); - } - elsif ( $category eq "cn_source" ) { - push @authorised_values, ""; - - my $class_sources = GetClassSources(); - - my $default_source = C4::Context->preference("DefaultClassificationSource"); - - foreach my $class_source (sort keys %$class_sources) { - next unless $class_sources->{$class_source}->{'used'} or - ($value and $class_source eq $value) or - ($class_source eq $default_source); - push @authorised_values, $class_source; - $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'}; - } - $value = $default_source unless $value; - } - else { - my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; - $authorised_values_sth->execute( - $tagslib->{$tag}->{$subfield}->{authorised_value}, - $branch_limit ? $branch_limit : (), - ); - - push @authorised_values, ""; - - while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { - push @authorised_values, $value; - $authorised_lib{$value} = $lib; - } - } - $authorised_values_sth->finish; - - return { - type => 'select', - id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, - name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, - default => $value, - values => \@authorised_values, - labels => \%authorised_lib, - ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ), - }; - -} - =head2 CreateKey Create a random value to set it into the input name @@ -282,213 +207,6 @@ sub GetMandatoryFieldZ3950 { }; } -=head2 create_input - - builds the entry for a subfield. - -=cut - -sub create_input { - my ( $tag, $subfield, $value, $index_tag, $rec, $authorised_values_sth,$cgi ) = @_; - - my $index_subfield = CreateKey(); # create a specifique key for each subfield - - # Apply optional framework default value when it is a new record, - # or when editing as new (duplicating a record), - # or when changing a record's framework, - # or when importing a record, - # based on the ApplyFrameworkDefaults setting. - # Substitute date parts, user name - my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults'); - if ( $value eq '' && ( - ( $applydefaults =~ /new/ && !$cgi->param('biblionumber') ) || - ( $applydefaults =~ /duplicate/ && $cgi->param('op') eq 'duplicate' ) || - ( $applydefaults =~ /changed/ && $cgi->param('changed_framework') ) || - ( $applydefaults =~ /imported/ && $cgi->param('breedingid') ) - ) ) { - $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{}; - - # get today date & replace <>, <>, <>, <
> if provided in the default value - my $today_dt = dt_from_string; - my $year = $today_dt->strftime('%Y'); - my $shortyear = $today_dt->strftime('%y'); - my $month = $today_dt->strftime('%m'); - my $day = $today_dt->strftime('%d'); - $value =~ s/<>/$year/g; - $value =~ s/<>/$shortyear/g; - $value =~ s/<>/$month/g; - $value =~ s/<
>/$day/g; - # And <> with surname (?) - my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian"); - $value=~s/<>/$username/g; - } - - my $dbh = C4::Context->dbh; - - # map '@' as "subfield" label for fixed fields - # to something that's allowed in a div id. - my $id_subfield = $subfield; - $id_subfield = "00" if $id_subfield eq "@"; - - my %subfield_data = ( - tag => $tag, - subfield => $id_subfield, - marc_lib => $tagslib->{$tag}->{$subfield}->{lib}, - tag_mandatory => $tagslib->{$tag}->{mandatory}, - mandatory => $tagslib->{$tag}->{$subfield}->{mandatory}, - important => $tagslib->{$tag}->{$subfield}->{important}, - repeatable => $tagslib->{$tag}->{$subfield}->{repeatable}, - kohafield => $tagslib->{$tag}->{$subfield}->{kohafield}, - index => $index_tag, - id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield, - value => $value, - maxlength => $tagslib->{$tag}->{$subfield}->{maxlength}, - random => CreateKey(), - ); - - if(exists $mandatory_z3950->{$tag.$subfield}){ - $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield}; - } - # Subfield is hidden depending of hidden and mandatory flag, and is always - # shown if it contains anything or if its field is mandatory or important. - my $tdef = $tagslib->{$tag}; - $subfield_data{visibility} = "display:none;" - if $tdef->{$subfield}->{hidden} % 2 == 1 && - $value eq '' && - !$tdef->{$subfield}->{mandatory} && - !$tdef->{mandatory} && - !$tdef->{$subfield}->{important} && - !$tdef->{important}; - # expand all subfields of 773 if there is a host item provided in the input - $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber')); - - - # it's an authorised field - if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { - $subfield_data{marc_value} = - build_authorized_values_list( $tag, $subfield, $value, $dbh, - $authorised_values_sth,$index_tag,$index_subfield ); - - # it's a subfield $9 linking to an authority record - see bug 2206 and 28022 - } - elsif ($subfield eq "9" and - exists($tagslib->{$tag}->{'a'}->{authtypecode}) and - defined($tagslib->{$tag}->{'a'}->{authtypecode}) and - $tagslib->{$tag}->{'a'}->{authtypecode} ne '' and - $tagslib->{$tag}->{'a'}->{hidden} > -4 and - $tagslib->{$tag}->{'a'}->{hidden} < 5) { - $subfield_data{marc_value} = { - type => 'text', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - size => 5, - maxlength => $subfield_data{maxlength}, - readonly => 1, - }; - - # it's a thesaurus / authority field - } - elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { - # when authorities auto-creation is allowed, do not set readonly - my $is_readonly = C4::Context->preference("RequireChoosingExistingAuthority"); - - $subfield_data{marc_value} = { - type => 'text', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - size => 67, - maxlength => $subfield_data{maxlength}, - readonly => ($is_readonly) ? 1 : 0, - authtype => $tagslib->{$tag}->{$subfield}->{authtypecode}, - }; - - # it's a plugin field - } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) { - require Koha::FrameworkPlugin; - my $plugin = Koha::FrameworkPlugin->new( { - name => $tagslib->{$tag}->{$subfield}->{'value_builder'}, - }); - my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib, - id => $subfield_data{id} }; - $plugin->build( $pars ); - if( !$plugin->errstr ) { - $subfield_data{marc_value} = { - type => 'text_complex', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - size => 67, - maxlength => $subfield_data{maxlength}, - javascript => $plugin->javascript, - plugin => $plugin->name, - noclick => $plugin->noclick, - }; - } else { - warn $plugin->errstr; - # supply default input form - $subfield_data{marc_value} = { - type => 'text', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - size => 67, - maxlength => $subfield_data{maxlength}, - readonly => 0, - }; - } - - # it's an hidden field - } elsif ( $tag eq '' ) { - $subfield_data{marc_value} = { - type => 'hidden', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - size => 67, - maxlength => $subfield_data{maxlength}, - }; - - } - else { - # it's a standard field - if ( - length($value) > 100 - or - ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300 - and $tag < 400 && $subfield eq 'a' ) - or ( $tag >= 500 - and $tag < 600 - && C4::Context->preference("marcflavour") eq "MARC21" ) - ) - { - $subfield_data{marc_value} = { - type => 'textarea', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - }; - - } - else { - $subfield_data{marc_value} = { - type => 'text', - id => $subfield_data{id}, - name => $subfield_data{id}, - value => $value, - size => 67, - maxlength => $subfield_data{maxlength}, - readonly => 0, - }; - - } - } - $subfield_data{'index_subfield'} = $index_subfield; - return \%subfield_data; -} - - =head2 format_indicator Translate indicator value for output form - specifically, map @@ -543,6 +261,13 @@ sub build_tabs { if($max_num_tab >= 9){ $max_num_tab = 9; } + + my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new( + { + biblionumber => scalar $input->param('biblionumber'), + } + ); + # loop through each tab 0 through 9 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) { my @loop_data = (); #innerloop in the template. @@ -583,9 +308,20 @@ sub build_tabs { 'biblio.biblionumber' ); push( @subfields_data, - &create_input( - $tag, $subfield, $value, $index_tag, $record, - $authorised_values_sth,$input + $biblio_form_builder->generate_subfield_form( + { + tag => $tag, + subfield => $subfield, + value => $value, + index_tag => $index_tag, + record => $record, + hostitemnumber => scalar $input->param('hostitemnumber'), + op => scalar $input->param('op'), + changed_framework => scalar $input->param('changed_framework'), + breedingid => scalar $input->param('breedingid'), + tagslib => $tagslib, + mandatory_z3950 => $mandatory_z3950, + } ) ); } @@ -598,9 +334,17 @@ sub build_tabs { next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop ); push( @subfields_data, - &create_input( - $tag, $subfield, $value, $index_tag, - $record, $authorised_values_sth,$input + $biblio_form_builder->generate_subfield_form( + { + tag => $tag, + subfield => $subfield, + value => $value, + index_tag => $index_tag, + record => $record, + hostitemnumber => scalar $input->param('hostitemnumber'), + tagslib => $tagslib, + mandatory_z3950 => $mandatory_z3950, + } ) ); } @@ -628,9 +372,17 @@ sub build_tabs { next if ( defined( $field->subfield($subfield) ) ); push( @subfields_data, - &create_input( - $tag, $subfield, '', $index_tag, $record, - $authorised_values_sth,$input + $biblio_form_builder->generate_subfield_form( + { + tag => $tag, + subfield => $subfield, + value => '', + index_tag => $index_tag, + record => $record, + hostitemnumber => scalar $input->param('hostitemnumber'), + tagslib => $tagslib, + mandatory_z3950 => $mandatory_z3950, + } ) ); } @@ -684,9 +436,17 @@ sub build_tabs { if ( $subfield->{tab} ne $tabloop ); push( @subfields_data, - &create_input( - $tag, $subfield->{subfield}, '', $index_tag, $record, - $authorised_values_sth,$input + $biblio_form_builder->generate_subfield_form( + { + tag => $tag, + subfield => $subfield->{subfield}, + value => '', + index_tag => $index_tag, + record => $record, + hostitemnumber => scalar $input->param('hostitemnumber'), + tagslib => $tagslib, + mandatory_z3950 => $mandatory_z3950, + } ) ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index 2eb84b61b9..280b4db05b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -4,7 +4,6 @@ [% USE KohaDates %] [% USE Price %] [% USE ItemTypes %] -[% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] › Basket [% basketno | html %] › Acquisitions › Koha [% INCLUDE 'doc-head-close.inc' %] @@ -35,6 +34,189 @@ } [% END %] + [% Asset.js("js/acquisitions-menu.js") | $raw %] + [% Asset.js("js/acq.js") | $raw %] + [% Asset.js("js/additem.js") | $raw %] + [% Asset.js("js/cataloging.js") | $raw %] + [% INCLUDE 'calendar.inc' %] + [% INCLUDE 'select2.inc' %] + +[% Asset.css("css/addbiblio.css") | $raw %] @@ -264,21 +446,17 @@ [% IF biblionumber %]
    [% FOREACH field IN catalog_details %] -
  1. -
    - - [% field.value | html %] -
    +
  2. + + [% field.value | html %]
  3. [% END %]
[% ELSE %]
    [% FOREACH field IN catalog_details %] -
  1. -
    - [% PROCESS display_subfield field=field %] -
    +
  2. + [% PROCESS display_subfield field=field %]
  3. [% END %]
@@ -564,226 +742,54 @@ [% MACRO jsinclude BLOCK %] - [% Asset.js("js/acquisitions-menu.js") | $raw %] - [% Asset.js("js/acq.js") | $raw %] - [% Asset.js("js/additem.js") | $raw %] - [% Asset.js("js/cataloging.js") | $raw %] - [% INCLUDE 'calendar.inc' %] - [% INCLUDE 'select2.inc' %] - [% END %] [% INCLUDE 'intranet-bottom.inc' %] [% BLOCK display_subfield %] - - [% IF field.authorised_value %] - [% SWITCH field.authorised_value %] - [% CASE 'branches' %] - [% IF field.mandatory %] - + [% ELSE %] + + [% END %] + + [% ELSIF ( mv.type == 'text_complex' ) %] + + [% mv.javascript | $raw %] + [% ELSIF ( mv.type == 'hidden' ) %] + + [% ELSIF ( mv.type == 'textarea' ) %] + + [% ELSIF ( mv.type == 'select' ) %] + + [% END %] - - [% PROCESS options_for_libraries libraries => Branches.all( selected => "FIXME" ) %] - - [% CASE 'itemtypes' %] - [% IF field.mandatory %] - + [% END # /IF (mv.type...) %] + +
+ [% IF ( mv.type == 'text_complex' ) %] + [% IF mv.noclick %] + [% ELSE %] - - [% CASE 'cn_source' %] - [% CASE %] - [% PROCESS 'av-build-dropbox.inc' name="bib_field_value", category=field.authorised_value, default="FIXME" %] - [% END %] - [% ELSE %] - [% IF field.mandatory %] - - [% ELSE %] - [% END %] +
- [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index 16cf857496..d6f6715cc3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -45,7 +45,8 @@ function openAuth(tagsubfieldid,authtype,source) { var mainmainstring=element.value; var mainstring = new Array(); - var inputs = element.closest('ul').getElementsByTagName('input'); + var ul = element.closest('ul'); + var inputs = ul ? ul.getElementsByTagName('input') : element.parentNode.getElementsByTagName('input'); for (var myindex =0; myindex sub { + my $builder = Koha::UI::Form::Builder::Biblio->new(); + + my $subfield = $builder->generate_subfield_form( + { + tag => '999', + subfield => '9', + value => '', + index_tag => int(rand(1000000)), + tagslib => { + '999' => { + '9' => { + defaultvalue => 'The date is <>-<>-<
> and user is <>', + hidden => 0, + } + } + }, + }, + ); + + my $today = DateTime->now->ymd; + is($subfield->{marc_value}->{value}, "The date is $today and user is superlibrarian"); +}; + +subtest 'generate_subfield_form branches' => sub { + my $builder = Koha::UI::Form::Builder::Biblio->new(); + + my $subfield = $builder->generate_subfield_form( + { + tag => '999', + subfield => '9', + value => '', + index_tag => int(rand(1000000)), + tagslib => { + '999' => { + '9' => { + authorised_value => 'branches', + hidden => 0, + } + } + }, + }, + ); + + my @libraries = Koha::Libraries->search({}, {order_by => 'branchname'})->as_list; + my %labels = map { $_->branchcode => $_->branchname } @libraries; + my @values = map { $_->branchcode } @libraries; + + is($subfield->{marc_value}->{type}, 'select'); + is_deeply($subfield->{marc_value}->{labels}, \%labels); + is_deeply($subfield->{marc_value}->{values}, \@values); +}; + +subtest 'generate_subfield_form itemtypes' => sub { + my $builder = Koha::UI::Form::Builder::Biblio->new(); + + my $subfield = $builder->generate_subfield_form( + { + tag => '999', + subfield => '9', + value => '', + index_tag => int(rand(1000000)), + tagslib => { + '999' => { + '9' => { + authorised_value => 'itemtypes', + hidden => 0, + } + } + }, + }, + ); + + my @itemtypes = Koha::ItemTypes->search_with_localization()->as_list; + my %labels = map { $_->itemtype => $_->description } @itemtypes; + my @values = ('', map { $_->itemtype } @itemtypes); + + is($subfield->{marc_value}->{type}, 'select'); + is_deeply($subfield->{marc_value}->{labels}, \%labels); + is_deeply($subfield->{marc_value}->{values}, \@values); +}; + +subtest 'generate_subfield_form class sources' => sub { + my $builder = Koha::UI::Form::Builder::Biblio->new(); + + my $subfield = $builder->generate_subfield_form( + { + tag => '999', + subfield => '9', + value => '', + index_tag => int(rand(1000000)), + tagslib => { + '999' => { + '9' => { + authorised_value => 'cn_source', + hidden => 0, + } + } + }, + }, + ); + + my @class_sources = Koha::ClassSources->search({used => 1}, {order_by => 'cn_source'})->as_list; + my %labels = map { $_->cn_source => $_->description } @class_sources; + my @values = ('', map { $_->cn_source } @class_sources); + + is($subfield->{marc_value}->{type}, 'select'); + is_deeply($subfield->{marc_value}->{labels}, \%labels); + is_deeply($subfield->{marc_value}->{values}, \@values); +}; + +subtest 'generate_subfield_form authorised value' => sub { + my $builder = Koha::UI::Form::Builder::Biblio->new(); + + my $subfield = $builder->generate_subfield_form( + { + tag => '999', + subfield => '9', + value => '', + index_tag => int(rand(1000000)), + tagslib => { + '999' => { + '9' => { + authorised_value => 'YES_NO', + hidden => 0, + } + } + }, + }, + ); + + my @authorised_values = Koha::AuthorisedValues->search({category => 'YES_NO'}, {order_by => ['lib', 'lib_opac']})->as_list; + my %labels = map { $_->authorised_value => $_->lib } @authorised_values; + my @values = ('', map { $_->authorised_value } @authorised_values); + + is($subfield->{marc_value}->{type}, 'select'); + is_deeply($subfield->{marc_value}->{labels}, \%labels); + is_deeply($subfield->{marc_value}->{values}, \@values); +}; + +subtest 'generate_subfield_form framework plugin' => sub { + my $builder = Koha::UI::Form::Builder::Biblio->new(); + + my $subfield = $builder->generate_subfield_form( + { + tag => '999', + subfield => '9', + value => '', + index_tag => int(rand(1000000)), + tagslib => { + '999' => { + '9' => { + value_builder => 'barcode.pl', + hidden => 0, + } + } + }, + }, + ); + + is($subfield->{marc_value}->{type}, 'text_complex'); + is($subfield->{marc_value}->{plugin}, 'barcode.pl'); + is($subfield->{marc_value}->{noclick}, 1); + like($subfield->{marc_value}->{javascript}, qr,,s); +}; + +done_testing(); -- 2.30.2