Bugzilla – Attachment 160185 Details for
Bug 35044
Additional fields: Allow for repeatable fields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35044: Update: Serial subscriptions batch edit
Bug-35044-Update-Serial-subscriptions-batch-edit.patch (text/plain), 10.97 KB, created by
Martin Renvoize (ashimema)
on 2023-12-21 10:28:43 UTC
(
hide
)
Description:
Bug 35044: Update: Serial subscriptions batch edit
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-12-21 10:28:43 UTC
Size:
10.97 KB
patch
obsolete
>From 8a1701a32efffea04fd9adb05c5843672c29ee79 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 16 Oct 2023 16:14:53 +0000 >Subject: [PATCH] Bug 35044: Update: Serial subscriptions batch edit > >Test plan, k-t-d: > >Preparation: Create additional fields for table 'subscription', visit: >/cgi-bin/koha/admin/additional-fields.pl?tablename=subscription > >2 text fields, one repeatable, one not-repeatable >2 AV fields, one repeatable, one not-repeatable >2 MARC fields, one 'get' and one 'set', both non-repeatable, MARC field 942$c >Attempt to create a repeatable MARC field (get or set). Notice you're unable to. > >1) Add a new serial subscription, visit: >/cgi-bin/koha/serials/subscription-add.pl >2) Set the mandatory "Record" input (e.g. '112'). Click the 'Next' and press 'Ok' on the alert box. >3) Fill in all required fields and press "Test prediction pattern" >4) At the bottom, fill in all additional fields, click the '+New' and 'Clear' links, hit 'Save' >5) Notice the fields are shown, repeated fields are comma separated >6) Repeat steps 1-4 to create a second subscription >7) Visit serials home and hit "Search": >/cgi-bin/koha/serials/serials-home.pl >8) Check the checkboxes next to the 2 subscriptions and click "Edit selected serials" >9) Input some values in the additional fields section, click the '+New' and 'Clear' links, hit 'Save' >10) Verify that both subscriptions now have the new values form the batch edit. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Object/Mixin/AdditionalFields.pm | 47 +++++++++++++++++++ > .../en/includes/additional-fields-entry.inc | 12 ++++- > .../modules/serials/subscription-batchedit.tt | 19 ++------ > serials/subscription-batchedit.pl | 42 ++++++----------- > 4 files changed, 76 insertions(+), 44 deletions(-) > >diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm >index 77aff5bbc42..9f7a39728b3 100644 >--- a/Koha/Object/Mixin/AdditionalFields.pm >+++ b/Koha/Object/Mixin/AdditionalFields.pm >@@ -91,6 +91,53 @@ sub set_additional_fields { > } > } > >+=head3 add_additional_fields >+ >+Similar to set_additional_fields, but instead of overwriting existing fields, only adds new ones >+ >+ $foo->add_additional_fields( >+ { >+ '2' => [ >+ 'first value for field 2', >+ 'second value for field 2' >+ ], >+ '1' => ['first value for field 1'] >+ }, >+ 'subscription' >+ ); >+ >+=cut >+ >+sub add_additional_fields { >+ my ( $self, $new_additional_fields, $tablename ) = @_; >+ >+ my @additional_fields; >+ >+ my $table_fields = Koha::AdditionalFields->search( { tablename => $tablename } ); >+ while ( my $field = $table_fields->next ) { >+ my $new_additional_field_values = $new_additional_fields->{ $field->id }; >+ >+ if ( $new_additional_field_values && scalar @{$new_additional_field_values} ) { >+ foreach my $value ( @{$new_additional_field_values} ) { >+ push @additional_fields, { >+ id => $field->id, >+ value => $value, >+ } if $value; >+ } >+ } else { >+ my $existing_additional_field_values = $self->additional_field_values->search( { field_id => $field->id } ); >+ while ( my $existing = $existing_additional_field_values->next ) { >+ push @additional_fields, { >+ id => $field->id, >+ value => $existing->value, >+ } if $existing && $existing->value; >+ } >+ } >+ } >+ >+ $self->set_additional_fields( \@additional_fields ); >+} >+ > =head3 get_additional_field_values_for_template > > Returns additional field values in the format expected by the .tt file >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 dd3db99683f..4c42e905d31 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 >@@ -20,7 +20,11 @@ > [% END %] > [% END %] > [% IF !field.repeatable %] >- <option value=""></option> >+ [% IF batch_edit %] >+ <option value="">No change</option> >+ [% ELSE %] >+ <option value=""></option> >+ [% END %] > [% END %] > [% IF authorised_value_category == 'branches' %] > [% FOREACH branch IN Branches.all() %] >@@ -108,7 +112,11 @@ > [% IF !text_field_value_rendered %] > <li> > <label for="additional_field_[% field.id | html %]"> [% field.name | html %]: </label> >- <input type="text" id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]" /> >+ [% IF batch_edit %] >+ <input type="text" id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]" placeholder="No change" /> >+ [% ELSE %] >+ <input type="text" id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]" /> >+ [% END %] > [% UNLESS search_form == 1 %] > <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt >index 1f9050e60f5..5b9e6ba3c46 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt >@@ -1,4 +1,5 @@ > [% USE raw %] >+[% USE Asset %] > [% USE AuthorisedValues %] > [% USE Branches %] > [% USE ItemTypes %] >@@ -141,20 +142,8 @@ > <label for="enddate">Expiration date: </label> > <input type="text" class="flatpickr" id="enddate" name="enddate" placeholder="No change"/> > </li> >- [% FOREACH field IN additional_fields %] >- <li> >- <label for="field_[% field.id | html %]">[% field.name | html %]</label> >- [% IF field.authorised_value_category %] >- <select id="field_[% field.id | html %]" name="field_[% field.id | html %]"> >- <option value="">No change</option> >- [% FOREACH av IN AuthorisedValues.Get(field.authorised_value_category) %] >- <option value="[% av.authorised_value | html %]">[% av.lib | html %]</option> >- [% END %] >- </select> >- [% ELSE %] >- <input type="text" id="field_[% field.id | html %]" name="field_[% field.id | html %]" placeholder="No change"/> >- [% END %] >- </li> >+ [% IF available_additional_fields.count %] >+ [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values batch_edit=1 %] > [% END %] > </ol> > </fieldset> >@@ -175,5 +164,5 @@ > </div> <!-- /.col-sm-2.col-sm-pull-10 --> > </div> <!-- /.row --> > >- >+ [% Asset.js("js/additional-fields-entry.js") | $raw %] > [% INCLUDE 'intranet-bottom.inc' %] >diff --git a/serials/subscription-batchedit.pl b/serials/subscription-batchedit.pl >index 274bcd4f23e..ffdf6d9b8bc 100755 >--- a/serials/subscription-batchedit.pl >+++ b/serials/subscription-batchedit.pl >@@ -49,7 +49,7 @@ foreach my $subscriptionid (@subscriptionids) { > push @subscriptions, $subscription if $subscription; > } > >-my @available_additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list; >+my $available_additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } ); > > my $batchedit = $cgi->param('batchedit'); > if ($batchedit) { >@@ -65,9 +65,15 @@ if ($batchedit) { > ); > > my $field_values = {}; >- foreach my $field (@available_additional_fields) { >- my $value = $cgi->param( 'field_' . $field->id ); >- $field_values->{ $field->id } = $value; >+ >+ while ( my $available_field = $available_additional_fields->next ) { >+ my @submitted_fields = $cgi->param( 'additional_field_' . $available_field->id ); >+ >+ my @submitted_fields_array; >+ foreach my $submitted_field (@submitted_fields) { >+ push @submitted_fields_array, $submitted_field if $submitted_field; >+ } >+ $field_values->{ $available_field->id } = \@submitted_fields_array; > } > > foreach my $subscription (@subscriptions) { >@@ -80,25 +86,7 @@ if ($batchedit) { > } > } > >- my @additional_field_values; >- foreach my $field (@available_additional_fields) { >- my $value = $field_values->{ $field->id }; >- if ( defined $value and $value ne '' ) { >- push @additional_field_values, { >- id => $field->id, >- value => $value, >- }; >- } else { >- my $existing = $subscription->additional_field_values->search( { field_id => $field->id } )->last; >- if ( $existing && $existing->value ) { >- push @additional_field_values, { >- id => $field->id, >- value => $existing->value, >- }; >- } >- } >- } >- $subscription->set_additional_fields( \@additional_field_values ); >+ $subscription->add_additional_fields($field_values, 'subscription'); > > $subscription->store; > } >@@ -109,10 +97,10 @@ if ($batchedit) { > } > > $template->param( >- subscriptions => \@subscriptions, >- booksellers => [ Koha::Acquisition::Booksellers->search->as_list ], >- additional_fields => \@available_additional_fields, >- referrer => scalar $cgi->param('referrer'), >+ subscriptions => \@subscriptions, >+ booksellers => [ Koha::Acquisition::Booksellers->search->as_list ], >+ available_additional_fields => Koha::AdditionalFields->search( { tablename => 'subscription' } ), >+ referrer => scalar $cgi->param('referrer'), > ); > > output_html_with_http_headers $cgi, $cookie, $template->output; >-- >2.43.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35044
:
157324
|
157325
|
157326
|
157327
|
157328
|
157329
|
157330
|
157331
|
157332
|
157333
|
157334
|
158113
|
158498
|
158499
|
158500
|
158501
|
158502
|
158503
|
158504
|
158505
|
158506
|
158507
|
158508
|
158857
|
158858
|
158859
|
158860
|
158861
|
158862
|
158863
|
158864
|
158865
|
158866
|
158867
|
158868
|
159268
|
160177
|
160178
|
160179
|
160180
|
160181
|
160182
|
160183
|
160184
|
160185
|
160186
|
160187
|
160188
|
160189
|
164162
|
164163
|
164164
|
164165
|
164166
|
164167
|
164168
|
164169
|
164170
|
164171
|
164172
|
164173
|
164174
|
167690
|
168537
|
168538
|
168539
|
168540
|
168541
|
168542
|
168543
|
168544
|
168545
|
168546
|
168547
|
168548
|
169545
|
169546
|
169547
|
169603
|
169604
|
169605
|
169606
|
169607
|
169643
|
169644
|
169645
|
169646
|
169647
|
169648
|
169649
|
169650
|
169651
|
169652
|
169653
|
169654
|
169655
|
169656
|
169657
|
169658
|
169659
|
169660
|
169661
|
169662
|
169663
|
169664
|
169665
|
169666
|
169667
|
169668
|
169669
|
169670
|
169671
|
169672
|
169673
|
169674
|
169675
|
169676
|
169677
|
169678
|
169679
|
169680
|
169681
|
169682
|
169683
|
169684
|
169697
|
170501