diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm index bf6598d8c9..77aff5bbc4 100644 --- a/Koha/Object/Mixin/AdditionalFields.pm +++ b/Koha/Object/Mixin/AdditionalFields.pm @@ -91,6 +91,49 @@ sub set_additional_fields { } } +=head3 get_additional_field_values_for_template + +Returns additional field values in the format expected by the .tt file + + my $fields = Koha::Acquisition::Baskets->find($basketno)->get_additional_field_values_for_template; + +Expected format is a hash of arrays, where the hash key is the field id and its respective array contains +the field values 'value' for that field. Example where field_id = 2 is the only repeatable field: + +{ + '3' => ['first value for field 3'], + '1' => ['first value for field 1'], + '4' => ['first value for field 4'], + '2' => [ + 'first value for field 2', + 'second value for field 2', + 'third value for field 2' + ] +}; + +=cut + +sub get_additional_field_values_for_template { + my ($self) = @_; + + my $additional_field_ids = $self->additional_field_values->search( + {}, + { + columns => ['field_id'], + distinct => 1, + } + ); + + my %fields; + while ( my $additional_field_value = $additional_field_ids->next ) { + my @values = map ( $_->value, + $self->additional_field_values->search( { field_id => $additional_field_value->field_id } )->as_list ); + $fields{ $additional_field_value->field_id } = \@values; + } + + return \%fields; +} + =head3 additional_field_values Returns additional field values diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc index 7b2bab777d..052d462739 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc @@ -1,11 +1,25 @@ [% USE AuthorisedValues %] [% FOR field IN available %] -
  • - [% field.name | html %]: - [% IF field.authorised_value_category %] - [% AuthorisedValues.GetByCode( field.authorised_value_category, values.${field.name} ) | html %] - [% ELSE %] - [% values.${field.name} | html %] + [% IF is_table_cell %] + + [% END %] + [% SET values_list = [] %] + [% FOR value IN values.${field.id} %] + [% IF field.authorised_value_category %] + [% values_list.push(AuthorisedValues.GetByCode( field.authorised_value_category, value )) %] + [% ELSE %] + [% values_list.push(value) %] + [% END %] + [% END %] + [% IF value_only %] + [% values_list.join(', ') | html %] + [% ELSIF !values_list.empty %] +
  • + [% field.name | html %]: + [% values_list.join(', ') | html %] +
  • + [% END %] + [% IF is_table_cell %] + [% END %] - [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc index df874de316..dd3db99683 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc @@ -3,67 +3,124 @@ [% USE ClassSources %] [% USE ItemTypes %] [% IF wrap_fieldset != 0 %] -
    +
    Additional fields
      [% END %] [% FOR field IN available %] [% authorised_value_category = field.effective_authorised_value_category %] -
    1. + [% IF authorised_value_category %] +
    2. - [% IF authorised_value_category %] - [% IF field.marcfield && field.marcfield_mode == 'get' %] - + [% ELSE %] + [% IF !field.repeatable %] [% av.lib | html %] + + [% SET av_field_value_rendered = 1 %] + [% END %] + [% END %] + [% IF !av_field_value_rendered %] + + [% END %] [% END %] [% END %] - (Authorised values for [% authorised_value_category | html %]) - [% ELSIF field.marcfield && field.marcfield_mode == 'get' %] - - [% ELSE %] - - [% END %] - - [% IF field.marcfield && field.marcfield_mode == 'get' %] - This value will be filled with the [% field.marcfield | html %] subfield of the selected bibliographic record. - [% ELSIF field.marcfield && field.marcfield_mode == 'set' %] - This value will be saved to the [% field.marcfield | html %] subfield of the selected bibliographic record. + [% END %] + + [% IF !search_form %] + (Authorised values for [% authorised_value_category | html %]) + [% IF field.marcfield && field.marcfield_mode == 'get' %] + This value will be filled with the [% field.marcfield | html %] subfield of the selected bibliographic record. + [% ELSIF field.marcfield && field.marcfield_mode == 'set' %] + This value will be saved to the [% field.marcfield | html %] subfield of the selected bibliographic record. + [% END %] [% END %]
    3. + + [% ELSIF field.marcfield && field.marcfield_mode == 'get' %] +
    4. + + + [% IF !search_form %] + This value will be filled with the [% field.marcfield | html %] subfield of the selected bibliographic record. + [% END %] +
    5. + [% ELSE %] + [% SET text_field_value_rendered = 0 %] + [% FOR value IN values.${field.id} %] +
    6. + + + [% UNLESS search_form == 1 %] + Clear + [% END %] + [% IF field.repeatable && !search_form %] + New + [% END %] + [% SET text_field_value_rendered = 1 %] + [% END %] + [% IF !text_field_value_rendered %] +
    7. + + + [% UNLESS search_form == 1 %] + Clear + [% END %] + [% IF field.repeatable && !search_form %] + New + [% END %] + [% END %] + [% IF field.marcfield && field.marcfield_mode == 'set' && !search_form %] + This value will be saved to the [% field.marcfield | html %] subfield of the selected bibliographic record. + [% END %] +
    8. + [% END %] [% END %] [% IF wrap_fieldset != 0 %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc index d939531a26..626a9f2bd1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc @@ -31,7 +31,7 @@ - [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_filters wrap_fieldset=0 %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_filters wrap_fieldset=0 search_form=1 %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt index 45424212b6..6ab7a044bf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt @@ -210,7 +210,7 @@
    Search orders [% END %] - [% INCLUDE 'filter-orders.inc' %] + [% INCLUDE 'filter-orders.inc' search_form=1 %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/js/additional-fields-entry.js b/koha-tmpl/intranet-tmpl/prog/js/additional-fields-entry.js new file mode 100644 index 0000000000..590533b7d5 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/additional-fields-entry.js @@ -0,0 +1,28 @@ +$(document).ready(function() { + $("#additional_fields_form_section").on("click", ".clone_attribute", function(e){ + e.preventDefault(); + clone_entry( this ); + }); + + $("#additional_fields_form_section").on("click", ".clear_attribute", function(e){ + e.preventDefault(); + clear_entry( this ); + }); + + $('#additional_fields_form_section').parents('form ').submit(function() { + $('.marcfieldget').prop("disabled", false); + return true; + }); +}); + +function clone_entry(node) { + var original = $(node).parent(); + var clone = $(node).parent().clone(); + $(original).after(clone); + return false; +} + +function clear_entry(node) { + var original = $(node).parent(); + $("input", original).val(''); +} \ No newline at end of file