Bug 32484: Enable plugins when UseACQFrameworkForBiblioRecords is set
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 <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit edcabe3728
)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
266c2a521b
commit
b913b98929
6 changed files with 867 additions and 550 deletions
372
Koha/UI/Form/Builder/Biblio.pm
Normal file
372
Koha/UI/Form/Builder/Biblio.pm
Normal file
|
@ -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 <http://www.gnu.org/licenses>.
|
||||
|
||||
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 <<YYYY>>, <<YY>>, <<MM>>, <<DD>> 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/<<YYYY>>/$year/g;
|
||||
$value =~ s/<<YY>>/$shortyear/g;
|
||||
$value =~ s/<<MM>>/$month/g;
|
||||
$value =~ s/<<DD>>/$day/g;
|
||||
# And <<USER>> with surname (?)
|
||||
my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
|
||||
$value=~s/<<USER>>/$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;
|
|
@ -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 <<YYYY>>, <<YY>>, <<MM>>, <<DD>> 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/<<YYYY>>/$year/g;
|
||||
$value =~ s/<<YY>>/$shortyear/g;
|
||||
$value =~ s/<<MM>>/$month/g;
|
||||
$value =~ s/<<DD>>/$day/g;
|
||||
|
||||
# And <<USER>> with surname (?)
|
||||
my $username =
|
||||
( C4::Context->userenv
|
||||
? C4::Context->userenv->{'surname'}
|
||||
: "superlibrarian" );
|
||||
$value =~ s/<<USER>>/$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,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <input ...> 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 <<YYYY>>, <<YY>>, <<MM>>, <<DD>> 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/<<YYYY>>/$year/g;
|
||||
$value =~ s/<<YY>>/$shortyear/g;
|
||||
$value =~ s/<<MM>>/$month/g;
|
||||
$value =~ s/<<DD>>/$day/g;
|
||||
# And <<USER>> with surname (?)
|
||||
my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
|
||||
$value=~s/<<USER>>/$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,
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
[% USE KohaDates %]
|
||||
[% USE Price %]
|
||||
[% USE ItemTypes %]
|
||||
[% SET footerjs = 1 %]
|
||||
[% INCLUDE 'doc-head-open.inc' %]
|
||||
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] › Basket [% basketno | html %] › Acquisitions › Koha</title>
|
||||
[% INCLUDE 'doc-head-close.inc' %]
|
||||
|
@ -35,6 +34,189 @@
|
|||
}
|
||||
</style>
|
||||
[% 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' %]
|
||||
<script>
|
||||
actTotal = "";
|
||||
|
||||
function Check(ff) {
|
||||
[% IF (AcqCreateItemOrdering) %]
|
||||
// Remove last itemblock if it is not in items_list
|
||||
var lastitemblock = $("#outeritemblock > div:last");
|
||||
var tobedeleted = true;
|
||||
var listitems = $("#items_list tr");
|
||||
$(listitems).each(function(){
|
||||
if($(this).attr('idblock') == $(lastitemblock).attr('id')){
|
||||
tobedeleted = false;
|
||||
}
|
||||
});
|
||||
if(tobedeleted){
|
||||
$(lastitemblock).remove();
|
||||
}
|
||||
[% END %]
|
||||
|
||||
var ok=0;
|
||||
var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
|
||||
|
||||
_alertString +="-------------------------------------------------------------------\n\n";
|
||||
|
||||
if(isNull(ff.budget_id,1)){
|
||||
ok=1;
|
||||
_alertString += "\n- "+ _("You must select a fund");
|
||||
}
|
||||
|
||||
if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Quantity must be greater than '0'");
|
||||
}
|
||||
|
||||
if (!(isNum(ff.listprice,0))){
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Vendor price must be a number");
|
||||
}
|
||||
|
||||
if (!(isNum(ff.total,0))){
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Total must be a number");
|
||||
}
|
||||
|
||||
if (totalExceedsBudget(ff.budget_id.value, ff.total.value ) ) {
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
|
||||
}
|
||||
|
||||
if ( ff.field_value ) {
|
||||
var empty_item_mandatory = CheckMandatorySubfields(ff);
|
||||
if (empty_item_mandatory > 0) {
|
||||
ok = 1;
|
||||
_alertString +=
|
||||
"\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
alert(_alertString);
|
||||
[% IF (AcqCreateItemOrdering) %]
|
||||
if(tobedeleted) {
|
||||
$(lastitemblock).appendTo('#outeritemblock');
|
||||
}
|
||||
[% END %]
|
||||
return false;
|
||||
}
|
||||
|
||||
[% IF (AcqCreateItemOrdering) %]
|
||||
if(check_additem('[% UniqueItemFields | html %]') == false) {
|
||||
alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
|
||||
if(tobedeleted) {
|
||||
$(lastitemblock).appendTo('#outeritemblock');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
[% END %]
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
[% IF AcqCreateItemOrdering and not basket.is_standing %]
|
||||
cloneItemBlock(0, '[% UniqueItemFields | html %]');
|
||||
[% END %]
|
||||
|
||||
[% IF ( suggestionid ) %]updateCosts();[% END %]
|
||||
$("#quantity").change(function() {
|
||||
updateCosts();
|
||||
});
|
||||
|
||||
//We apply the fonction only for modify option
|
||||
[% IF ( quantityrec and not subscriptionid ) %]
|
||||
[% IF ( acqcreate ) %]
|
||||
$('#quantity').blur(function(){
|
||||
// if user decreases the quantity
|
||||
if($(this).val() < [% quantityrec | html %]){
|
||||
alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
|
||||
return true;
|
||||
} else {
|
||||
// if user increases the quantity
|
||||
alert(_("You can't add a new item, please create a new order line"));
|
||||
// and we replace the original value
|
||||
$(this).val([% quantityrec | html %])
|
||||
updateCosts(); // blur is invoked after change which updated values
|
||||
return false;
|
||||
}
|
||||
});
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
||||
//keep a copy of all budgets before removing the inactives
|
||||
disabledBudgetsCopy = $('#budget_id').html();
|
||||
$('#budget_id .b_inactive').remove();
|
||||
|
||||
$('#showallbudgets').click(function() {
|
||||
if ($(this).is(":checked")) {
|
||||
$('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
|
||||
}
|
||||
else {
|
||||
$('#budget_id .b_inactive').remove();
|
||||
}
|
||||
});
|
||||
|
||||
$("#budget_id").change(function(){
|
||||
var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
|
||||
var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
|
||||
var sort1 = $(destination_sort1).val() || "";
|
||||
if ( destination_sort1.length < 1 ) {
|
||||
destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
|
||||
}
|
||||
var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
|
||||
var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
|
||||
var sort2 = $(destination_sort2).val() || "";
|
||||
if ( destination_sort2.length < 1 ) {
|
||||
destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
|
||||
}
|
||||
getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
|
||||
getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
|
||||
});
|
||||
$("#budget_id").change();
|
||||
});
|
||||
|
||||
function UserSearchPopup(f) {
|
||||
window.open(
|
||||
"/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
|
||||
'UserSearchPopup',
|
||||
'width=1024, height=768, scrollbars=yes, toolbar=no,'
|
||||
);
|
||||
}
|
||||
|
||||
function add_user(borrowernumber, borrowername) {
|
||||
var ids = $("#users_ids").val();
|
||||
if(ids.length > 0) {
|
||||
ids = ids.split(':');
|
||||
} else {
|
||||
ids = new Array;
|
||||
}
|
||||
if (ids.indexOf(borrowernumber.toString()) < 0) {
|
||||
ids.push(borrowernumber);
|
||||
$("#users_ids").val(ids.join(':'));
|
||||
var li = '<li id="user_'+borrowernumber+'">'+borrowername
|
||||
+ ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
|
||||
+ _("Delete user") + '</a>]</li>';
|
||||
$("#users_names").append(li);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function del_user(borrowernumber) {
|
||||
$("#user_"+borrowernumber).remove();
|
||||
var ids = $("#users_ids").val().split(':');
|
||||
ids.splice(ids.indexOf(borrowernumber.toString()), 1);
|
||||
$("#users_ids").val(ids.join(':'));
|
||||
}
|
||||
</script>
|
||||
[% Asset.css("css/addbiblio.css") | $raw %]
|
||||
</head>
|
||||
|
||||
<body id="acq_neworderempty" class="acq">
|
||||
|
@ -264,21 +446,17 @@
|
|||
[% IF biblionumber %]
|
||||
<ol>
|
||||
[% FOREACH field IN catalog_details %]
|
||||
<li>
|
||||
<div class="subfield_line">
|
||||
<label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
|
||||
[% field.value | html %]
|
||||
</div>
|
||||
<li class="subfield_line">
|
||||
<label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
|
||||
[% field.value | html %]
|
||||
</li>
|
||||
[% END %]
|
||||
</ol>
|
||||
[% ELSE %]
|
||||
<ol>
|
||||
[% FOREACH field IN catalog_details %]
|
||||
<li>
|
||||
<div class="subfield_line">
|
||||
[% PROCESS display_subfield field=field %]
|
||||
</div>
|
||||
<li class="subfield_line">
|
||||
[% PROCESS display_subfield field=field %]
|
||||
</li>
|
||||
[% END %]
|
||||
</ol>
|
||||
|
@ -564,226 +742,54 @@
|
|||
</div> <!-- /.row -->
|
||||
|
||||
[% 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' %]
|
||||
<script>
|
||||
actTotal = "";
|
||||
|
||||
function Check(ff) {
|
||||
[% IF (AcqCreateItemOrdering) %]
|
||||
// Remove last itemblock if it is not in items_list
|
||||
var lastitemblock = $("#outeritemblock > div:last");
|
||||
var tobedeleted = true;
|
||||
var listitems = $("#items_list tr");
|
||||
$(listitems).each(function(){
|
||||
if($(this).attr('idblock') == $(lastitemblock).attr('id')){
|
||||
tobedeleted = false;
|
||||
}
|
||||
});
|
||||
if(tobedeleted){
|
||||
$(lastitemblock).remove();
|
||||
}
|
||||
[% END %]
|
||||
|
||||
var ok=0;
|
||||
var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
|
||||
|
||||
_alertString +="-------------------------------------------------------------------\n\n";
|
||||
|
||||
if(isNull(ff.budget_id,1)){
|
||||
ok=1;
|
||||
_alertString += "\n- "+ _("You must select a fund");
|
||||
}
|
||||
|
||||
if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Quantity must be greater than '0'");
|
||||
}
|
||||
|
||||
if (!(isNum(ff.listprice,0))){
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Vendor price must be a number");
|
||||
}
|
||||
|
||||
if (!(isNum(ff.total,0))){
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Total must be a number");
|
||||
}
|
||||
|
||||
if (totalExceedsBudget(ff.budget_id.value, ff.total.value ) ) {
|
||||
ok=1;
|
||||
_alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
|
||||
}
|
||||
|
||||
if ( ff.field_value ) {
|
||||
var empty_item_mandatory = CheckMandatorySubfields(ff);
|
||||
if (empty_item_mandatory > 0) {
|
||||
ok = 1;
|
||||
_alertString +=
|
||||
"\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
alert(_alertString);
|
||||
[% IF (AcqCreateItemOrdering) %]
|
||||
if(tobedeleted) {
|
||||
$(lastitemblock).appendTo('#outeritemblock');
|
||||
}
|
||||
[% END %]
|
||||
return false;
|
||||
}
|
||||
|
||||
[% IF (AcqCreateItemOrdering) %]
|
||||
if(check_additem('[% UniqueItemFields | html %]') == false) {
|
||||
alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
|
||||
if(tobedeleted) {
|
||||
$(lastitemblock).appendTo('#outeritemblock');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
[% END %]
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
[% IF AcqCreateItemOrdering and not basket.is_standing %]
|
||||
cloneItemBlock(0, '[% UniqueItemFields | html %]');
|
||||
[% END %]
|
||||
|
||||
[% IF ( suggestionid ) %]updateCosts();[% END %]
|
||||
$("#quantity").change(function() {
|
||||
updateCosts();
|
||||
});
|
||||
|
||||
//We apply the fonction only for modify option
|
||||
[% IF ( quantityrec and not subscriptionid ) %]
|
||||
[% IF ( acqcreate ) %]
|
||||
$('#quantity').blur(function(){
|
||||
// if user decreases the quantity
|
||||
if($(this).val() < [% quantityrec | html %]){
|
||||
alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
|
||||
return true;
|
||||
} else {
|
||||
// if user increases the quantity
|
||||
alert(_("You can't add a new item, please create a new order line"));
|
||||
// and we replace the original value
|
||||
$(this).val([% quantityrec | html %])
|
||||
updateCosts(); // blur is invoked after change which updated values
|
||||
return false;
|
||||
}
|
||||
});
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
||||
//keep a copy of all budgets before removing the inactives
|
||||
disabledBudgetsCopy = $('#budget_id').html();
|
||||
$('#budget_id .b_inactive').remove();
|
||||
|
||||
$('#showallbudgets').click(function() {
|
||||
if ($(this).is(":checked")) {
|
||||
$('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
|
||||
}
|
||||
else {
|
||||
$('#budget_id .b_inactive').remove();
|
||||
}
|
||||
});
|
||||
|
||||
$("#budget_id").change(function(){
|
||||
var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
|
||||
var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
|
||||
var sort1 = $(destination_sort1).val() || "";
|
||||
if ( destination_sort1.length < 1 ) {
|
||||
destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
|
||||
}
|
||||
var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
|
||||
var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
|
||||
var sort2 = $(destination_sort2).val() || "";
|
||||
if ( destination_sort2.length < 1 ) {
|
||||
destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
|
||||
}
|
||||
getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
|
||||
getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
|
||||
});
|
||||
$("#budget_id").change();
|
||||
});
|
||||
|
||||
function UserSearchPopup(f) {
|
||||
window.open(
|
||||
"/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
|
||||
'UserSearchPopup',
|
||||
'width=1024, height=768, scrollbars=yes, toolbar=no,'
|
||||
);
|
||||
}
|
||||
|
||||
function add_user(borrowernumber, borrowername) {
|
||||
var ids = $("#users_ids").val();
|
||||
if(ids.length > 0) {
|
||||
ids = ids.split(':');
|
||||
} else {
|
||||
ids = new Array;
|
||||
}
|
||||
if (ids.indexOf(borrowernumber.toString()) < 0) {
|
||||
ids.push(borrowernumber);
|
||||
$("#users_ids").val(ids.join(':'));
|
||||
var li = '<li id="user_'+borrowernumber+'">'+borrowername
|
||||
+ ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
|
||||
+ _("Delete user") + '</a>]</li>';
|
||||
$("#users_names").append(li);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function del_user(borrowernumber) {
|
||||
$("#user_"+borrowernumber).remove();
|
||||
var ids = $("#users_ids").val().split(':');
|
||||
ids.splice(ids.indexOf(borrowernumber.toString()), 1);
|
||||
$("#users_ids").val(ids.join(':'));
|
||||
}
|
||||
</script>
|
||||
[% END %]
|
||||
|
||||
[% INCLUDE 'intranet-bottom.inc' %]
|
||||
|
||||
[% BLOCK display_subfield %]
|
||||
<label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
|
||||
[% IF field.authorised_value %]
|
||||
[% SWITCH field.authorised_value %]
|
||||
[% CASE 'branches' %]
|
||||
[% IF field.mandatory %]
|
||||
<select name="bib_field_value" required="required">
|
||||
[% ELSE %]
|
||||
<select name="bib_field_value">
|
||||
[% END %]
|
||||
<option value=""></option>
|
||||
[% PROCESS options_for_libraries libraries => Branches.all( selected => "FIXME" ) %]
|
||||
</select>
|
||||
[% CASE 'itemtypes' %]
|
||||
[% IF field.mandatory %]
|
||||
<select name="bib_field_value" required="required">
|
||||
[% ELSE %]
|
||||
<select name="bib_field_value">
|
||||
[% END %]
|
||||
<option value=""></option>
|
||||
[% PROCESS options_for_item_types itemtypes => ItemTypes.Get(), selected_itemtype => "FIXME" %]
|
||||
</select>
|
||||
[% CASE 'cn_source' %]
|
||||
[% CASE %]
|
||||
[% PROCESS 'av-build-dropbox.inc' name="bib_field_value", category=field.authorised_value, default="FIXME" %]
|
||||
[% END %]
|
||||
[% ELSE %]
|
||||
[% IF field.mandatory %]
|
||||
<input type="text" name="bib_field_value" value="[% field.value | html %]" required="required" size="50" />
|
||||
<label>[% field.marc_lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
|
||||
|
||||
[% SET mv = field.marc_value %]
|
||||
[% IF ( mv.type == 'text' ) %]
|
||||
[% IF ( mv.readonly == 1 ) %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="bib_field_value" value="[%- mv.value | html -%]" class="input_marceditor readonly" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" readonly="readonly" />
|
||||
[% ELSE %]
|
||||
<input type="text" name="bib_field_value" value="[% field.value | html %]" size="50" />
|
||||
<input type="text" id="[%- mv.id | html -%]" name="bib_field_value" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
|
||||
[% END %]
|
||||
|
||||
[% END %]
|
||||
[% ELSIF ( mv.type == 'text_complex' ) %]
|
||||
<input type="text" id="[%- mv.id | html -%]" name="bib_field_value" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
|
||||
[% mv.javascript | $raw %]
|
||||
[% ELSIF ( mv.type == 'hidden' ) %]
|
||||
<input tabindex="1" type="hidden" id="[%- mv.id | html -%]" name="bib_field_value" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
|
||||
[% ELSIF ( mv.type == 'textarea' ) %]
|
||||
<textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="bib_field_value" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
|
||||
[% ELSIF ( mv.type == 'select' ) %]
|
||||
<select name="bib_field_value" tabindex="1" class="input_marceditor select2" id="[%- mv.id | html -%]">
|
||||
[% FOREACH aval IN mv.values %]
|
||||
[% IF aval == mv.default %]
|
||||
<option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
|
||||
[% ELSE %]
|
||||
<option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
|
||||
[% END %]
|
||||
[% END %]
|
||||
</select>
|
||||
[% END # /IF (mv.type...) %]
|
||||
|
||||
<div class="subfield_controls">
|
||||
[% IF ( mv.type == 'text_complex' ) %]
|
||||
[% IF mv.noclick %]
|
||||
<span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
|
||||
[% ELSE %]
|
||||
[% IF mv.plugin == "upload.pl" %]
|
||||
<a href="#" id="buttonDot_[% mv.id | html %]" class="tag_editor upload framework_plugin" tabindex="1"><i class="fa fa-upload" aria-hidden="true"></i> Upload</a>
|
||||
[% ELSE %]
|
||||
<a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor">Tag editor</a>
|
||||
[% END %]
|
||||
[% END %]
|
||||
[% END %]
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="bib_kohafield" value="[% field.kohafield | html %]" />
|
||||
<input type="hidden" name="bib_tag" value="[% field.tag | html %]" />
|
||||
<input type="hidden" name="bib_subfield" value="[% field.subfield | html %]" />
|
||||
|
|
|
@ -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<inputs.length;myindex++){
|
||||
if (inputs[myindex].name && inputs[myindex].name.match(tagsubfield)){
|
||||
var subfieldcode=getSubfieldCode(inputs[myindex].name);
|
||||
|
|
182
t/db_dependent/Koha/UI/Form/Builder/Biblio.t
Executable file
182
t/db_dependent/Koha/UI/Form/Builder/Biblio.t
Executable file
|
@ -0,0 +1,182 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use DateTime;
|
||||
use Test::More;
|
||||
|
||||
use C4::ClassSource;
|
||||
|
||||
use Koha::ClassSources;
|
||||
use Koha::ItemTypes;
|
||||
use Koha::Libraries;
|
||||
|
||||
use_ok('Koha::UI::Form::Builder::Biblio');
|
||||
|
||||
subtest 'generate_subfield_form default 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' => {
|
||||
defaultvalue => 'The date is <<YYYY>>-<<MM>>-<<DD>> and user is <<USER>>',
|
||||
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,<script>.*</script>,s);
|
||||
};
|
||||
|
||||
done_testing();
|
Loading…
Reference in a new issue