From 5916cd5836bafdeef4d6188779024595f617f190 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 20 Jun 2013 11:03:41 +0200 Subject: [PATCH] Bug 10480: Followup for additem.pl (no redefines for plugins) Content-Type: text/plain; charset=utf-8 Adds the same functionality for additem as in addbiblio. Note that the new subroutine is slightly different from the addbiblio case. Test plan: Test your cataloging plugins on Add/edit items. If you have no one, temporarily connect new_example_plugin.pl; it will only put 12345 in your item field. --- cataloguing/additem.pl | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 38 insertions(+), 9 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index a2eacef..a6695f6 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -41,6 +41,10 @@ use MARC::File::XML; use URI::Escape; our $dbh = C4::Context->dbh; +our $building_plugin={}; + #hashref { record => .., subfieldid => .., } + #used in building the new cataloging plugins (without redefinitions) + #plugin script should add function and javascript to hash sub find_value { my ($tagfield,$insubfield,$record) = @_; @@ -241,19 +245,19 @@ sub generate_subfield_form { elsif ( $subfieldlib->{value_builder} ) { # opening plugin my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $subfieldlib->{'value_builder'}; - if (do $plugin) { - my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, $loop_data ); - my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, $loop_data ); - my $change = index($javascript, 'function Change') > -1 ? - "return Change$function_name($subfield_data{random}, '$subfield_data{id}');" : - 'return 1;'; + my ( $function_name, $javascript ) = _new_plugin_builder( $plugin, $temp, $subfield_data{id} ); #no tabno passed for items + if( $function_name ) { + my $change = index($javascript, 'function Change') > -1 ? + "return Change$function_name($subfield_data{random}, '$subfield_data{id}');" : + 'return 1;'; $subfield_data{marc_value} = qq[ + onchange=" $change" + onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" /> ... $javascript]; - } else { + } + else { warn "Plugin Failed: $plugin"; $subfield_data{marc_value} = ""; # supply default input form } @@ -280,6 +284,31 @@ sub generate_subfield_form { return \%subfield_data; } +sub _new_plugin_builder { + my ($plugin, $record, $subfieldid) = @_; + + $building_plugin = { + record => $record, + subfieldid => $subfieldid, + }; + do $plugin || return; + + #first, try the new way without redefines using building_plugin hash + if( defined $building_plugin->{function} && + defined $building_plugin->{javascript} ) { + return ($building_plugin->{function}, + $building_plugin->{javascript} ); + } + + #arriving here, we try the old way with redefines: we are PHASING this OUT + #next call is of no use, commented + #my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop ); + my ( $function_name, $javascript ) = plugin_javascript( undef, $record, undef, $subfieldid ); #no tabno passed for items, same for tagslib + #first param was dbh, not needed: use C4::Context->dbh in plugin + return ( $function_name, $javascript ); + #caller tests if function_name is defined +} + # Removes some subfields when prefilling items # This function will remove any subfield that is not in the SubfieldsToUseWhenPrefill syspref sub removeFieldsForPrefill { -- 1.7.7.6