From c5299d094d211d8349416befee9290d10912bab1 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Thu, 21 Jul 2016 14:48:57 -0600 Subject: [PATCH] Bug 11844: (followup) use new unified additional field screen --- acqui/add_order_fields.pl | 123 --------------- acqui/neworderempty.pl | 35 +++-- .../prog/en/modules/acqui/add_order_fields.tt | 165 --------------------- .../prog/en/modules/acqui/neworderempty.tt | 31 +--- .../prog/en/modules/admin/additional-fields.tt | 1 + 5 files changed, 23 insertions(+), 332 deletions(-) delete mode 100755 acqui/add_order_fields.pl delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt diff --git a/acqui/add_order_fields.pl b/acqui/add_order_fields.pl deleted file mode 100755 index ef77af6..0000000 --- a/acqui/add_order_fields.pl +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Copyright 2014 BibLibre -# -# 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 CGI; -use C4::Auth; -use C4::Koha; -use C4::Output; -use Koha::AdditionalField; - -my $input = new CGI; - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "acqui/add_order_fields.tt", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { acquisition => '*' }, - debug => 1, - } -); - -my $op = $input->param('op') // 'list'; -my $field_id = $input->param('field_id'); -my @messages; - -if ( $op eq 'add' ) { - my $name = $input->param('name') // q{}; - my $authorised_value_category = $input->param('authorised_value_category') // q{}; - my $marcfield = $input->param('marcfield') // q{}; - if ( $field_id and $name ) { - my $updated = 0; - eval { - my $af = Koha::AdditionalField->new({ - id => $field_id, - name => $name, - authorised_value_category => $authorised_value_category, - marcfield => $marcfield, - }); - $updated = $af->update; - }; - push @messages, { - code => 'update', - number => $updated, - }; - } elsif ( $name ) { - my $inserted = 0; - eval { - my $af = Koha::AdditionalField->new({ - tablename => 'aqorders', - name => $name, - authorised_value_category => $authorised_value_category, - marcfield => $marcfield, - }); - $inserted = $af->insert; - }; - push @messages, { - code => 'insert', - number => $inserted, - }; - } else { - push @messages, { - code => 'insert', - number => 0, - }; - } - $op = 'list'; -} - -if ( $op eq 'delete' ) { - my $deleted = 0; - eval { - my $af = Koha::AdditionalField->new( { id => $field_id } ); - $deleted = $af->delete; - $deleted = 0 if $deleted eq '0E0'; - }; - push @messages, { - code => 'delete', - number => $deleted, - }; - $op = 'list'; -} - -if ( $op eq 'add_form' ) { - my $categories = C4::Koha::GetAuthorisedValueCategories(); - my $field; - if ( $field_id ) { - $field = Koha::AdditionalField->new( { id => $field_id } )->fetch; - } - - $template->param( - field => $field, - categories => $categories, - ); -} - -if ( $op eq 'list' ) { - my $fields = Koha::AdditionalField->all( { tablename => 'aqorders' } ); - $template->param( fields => $fields ); -} - -$template->param( - op => $op, - messages => \@messages, -); - -output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index e4aa0b4..9c21d49 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -301,25 +301,28 @@ my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', ''); # Get additional fields my $record; -my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'}); -foreach my $af (@$additional_fields) { - if (!$af->{authorised_value_category} && $af->{marcfield}) { - # Try to retrieve authorised values category from MARC framework - my ($field, $subfield) = split /\$/, $af->{marcfield}; - my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield); - if ($category) { - $af->{authorised_value_category} = $category; +my $available_additional_fields = Koha::AdditionalField->all( { tablename => 'aqorders' } ); +my $additional_field_values = {}; + +if ( $ordernumber ) { + $additional_field_values = Koha::AdditionalField->fetch_all_values( { + tablename => 'aqorders', + record_id => $ordernumber, + } )->{$ordernumber}; +} elsif ( $biblionumber ) { + foreach my $af (@$additional_fields) { + if ($af->{marcfield}) { + $record //= GetMarcBiblio($biblionumber); + my ($field, $subfield) = split /\$/, $af->{marcfield}; + $additional_field_values->{ $af->{name} } = $record->subfield($field, $subfield); } } - if ($ordernumber) { - $af->fetch_values({record_id => $ordernumber}); - } elsif ($biblionumber && $af->{marcfield}) { - $record //= GetMarcBiblio($biblionumber); - my ($field, $subfield) = split /\$/, $af->{marcfield}; - $af->{values}->{'new'} = $record->subfield($field, $subfield); - } } -$template->param(additional_fields => $additional_fields); + +$template->param( + available_additional_fields => $available_additional_fields, + additional_field_values => $additional_field_values +); # fill template $template->param( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt deleted file mode 100644 index 4fab644..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt +++ /dev/null @@ -1,165 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Acquisitions › Manage new fields for order lines - [% IF op == "list" %] › List of fields - [% ELSIF op == "add_form" %] - [% IF field %] › Modify field - [% ELSE %] › Add field - [% END %] - [% END %] - -[% INCLUDE 'doc-head-close.inc' %] - -[% INCLUDE "datatables.inc" %] - - - - - [% INCLUDE 'header.inc' %] - [% INCLUDE 'acquisitions-search.inc' %] - - - -
-
-
-
- [% IF op == 'list' %] - - [% END %] - - [% IF messages %] - [% FOR message IN messages %] - [% IF message.code == 'insert' %] - [% IF message.number > 0 %] -
The field has been inserted
- [% ELSE %] -
The field has not been inserted (name still exist?)
- [% END %] - [% ELSIF message.code == 'update' %] - [% IF message.number > 0 %] -
The field has been updated
- [% ELSE %] -
The field has not been updated (name still exist?)
- [% END %] - [% ELSIF message.code == 'delete' %] - [% IF message.number > 0 %] -
The field has been deleted
- [% ELSE %] -
The field has not been deleted
- [% END %] - [% END %] - [% END %] - [% END %] - - [% IF op == 'list' %] -

Additional fields for order lines

- [% IF fields %] - - - - - - - - - - - [% FOR field IN fields %] - - - - - - - [% END %] - -
NameAuthorised value categoryMARC fieldActions
[% field.name %][% field.authorised_value_category %][% field.marcfield %] - Edit - Delete -
- [% ELSE %] - There is no field defined. - [% END %] - [% ELSIF op == 'add_form' %] - [% IF field %] -

Modify field

- [% ELSE %] -

Add field

- [% END %] -
-
-
    -
  1. - - -
  2. -
  3. - - -
  4. -
  5. - - - Use this syntax: XXX$y -
  6. -
-
-
- [% IF field %] - - [% END %] - - - Cancel -
-
- [% END %] - -
-
- -
-[% INCLUDE 'acquisitions-menu.inc' %] -
-
-[% INCLUDE 'intranet-bottom.inc' %] 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 b8d1c12..d2c759d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -631,34 +631,9 @@ $(document).ready(function() - [% FOREACH af IN additional_fields %] -
  • - - [% value = '' %] - [% IF ordernumber %] - [% value = af.values.$ordernumber %] - [% ELSE %] - [% value = af.values.new %] - [% END %] - [% authorised_values = [] %] - [% IF af.authorised_value_category %] - [% authorised_values = AuthorisedValues.GetValues(af.authorised_value_category) %] - [% END %] - [% IF authorised_values.size > 0 %] - - [% ELSE %] - - [% END %] -
  • + + [% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values wrap_fieldset=0 %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt index 5166e4e..735fca5 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt @@ -97,6 +97,7 @@ [% END %]
      [% WRAPPER table_option value="aqbasket" %]Order baskets[% END %] + [% WRAPPER table_option value="aqorders" %]Order lines[% END %] [% WRAPPER table_option value="subscription" %]Subscriptions[% END %]
    [% ELSIF op == 'list' %] -- 2.8.1