From 476f417a62559b6bf805002a6572a852c204ec9a Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 13 Oct 2023 09:58:17 +0000 Subject: [PATCH] Bug 35044: Preparation: get_additional_field_values_for_template method New method to be utilized for retrieval of additional fields of any class that implements it. This is to be used when additional_fields are needed to be sent to .tt files for renderering. Both for form entries and read-only 'show' pages. Template files: Updated additional-fields-entry.inc: Now considers entry of repeatable fields. Repeatable text fields will have a "+New" link to allow for adding of a new instance of a repeatable field. Repeatable AV fields will be shown as checkboxes instead of a dropdown Update additional-fields-display.inc When displaying non-editable additional-fields, multiple instances for each field are now considered. Label now only shows if field has a non-null value in it. Option to show value_only Option to set if its to be displayed on a table cell Update histsearch.tt and filter-orders.inc Now calls additional-fields-entry.inc with search_form=1 to prevent repetable "+New" controls from showing on search inputs. additional-fields-entry.js New JS asset to be called by template files who require additional-fields-entry.inc for repeatable fields controls. This also handles the need for having the marcfield of type 'get' submitted if it is a disabled dropdown (AV marc field) Signed-off-by: Martin Renvoize --- Koha/Object/Mixin/AdditionalFields.pm | 43 ++++++ .../en/includes/additional-fields-display.inc | 30 ++-- .../en/includes/additional-fields-entry.inc | 133 +++++++++++++----- .../prog/en/includes/filter-orders.inc | 2 +- .../prog/en/modules/acqui/histsearch.tt | 2 +- .../prog/js/additional-fields-entry.js | 28 ++++ 6 files changed, 190 insertions(+), 48 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/additional-fields-entry.js 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 %] - [% END %] -
  • + [% 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 !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. - [% IF field.marcfield && field.marcfield_mode == 'get' %] + [% 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. - [% ELSIF field.marcfield && field.marcfield_mode == 'set' %] + [% 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 4c2e5b17fc..cb2107d72b 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 -- 2.39.2