Bugzilla – Attachment 171609 Details for
Bug 37941
Batch extend due date tool should separate actions/forms
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37941: WIP different actions in forms
Bug-37941-WIP-different-actions-in-forms.patch (text/plain), 12.47 KB, created by
Nick Clemens (kidclamp)
on 2024-09-17 12:11:27 UTC
(
hide
)
Description:
Bug 37941: WIP different actions in forms
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-09-17 12:11:27 UTC
Size:
12.47 KB
patch
obsolete
>From 0c0d0ef4557a10c1ec19ebbbd38dbe6ec79f5ba1 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 17 Sep 2024 12:11:08 +0000 >Subject: [PATCH] Bug 37941: WIP different actions in forms > >--- > .../modules/tools/batch_extend_due_dates.tt | 33 ++-- > tools/batch_extend_due_dates.pl | 145 ++++++++---------- > 2 files changed, 86 insertions(+), 92 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt >index aa7161ada74..c1f1fb7889b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt >@@ -82,7 +82,7 @@ > [% END %] > > [% IF view == 'form' %] >- <form method="post" action="/cgi-bin/koha/tools/batch_extend_due_dates.pl" id="extend_due_dates_form"> >+ <form action="/cgi-bin/koha/tools/batch_extend_due_dates.pl" id="extend_due_dates_form"> > [% INCLUDE 'csrf-token.inc' %] > <fieldset class="rows"> > <legend>Checkout criteria:</legend> >@@ -139,19 +139,9 @@ > </li> > </ol> > </fieldset> >- <fieldset class="rows"> >- <legend>Options:</legend> >- <ol> >- <li> >- <label for="preview_results">Preview results:</label> >- <input type="checkbox" name="preview_results" id="preview_results" checked /> >- <span class="hint">This is not recommended when changing very large numbers of due dates.</span> >- </li> >- </ol> >- </fieldset> > <fieldset class="action"> >- <input type="hidden" name="op" value="cud-list" /> >- <input type="submit" class="btn btn-primary" value="Continue" /> >+ <input type="button" class="btn btn-primary submit_extend" value="Preview results" /> >+ <input type="button" class="btn btn-primary submit_extend" value="Update due dates" /> > <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a> > </fieldset> > </form> <!-- /#extend_due_dates_form --> >@@ -188,7 +178,9 @@ > <td>[% checkout.issuedate | $KohaDates %]</td> > <td>[% Branches.GetName( checkout.branchcode ) | html %]</td> > <td> >- [% new_due_dates.shift | $KohaDates as_due_date => 1 %] >+ [%- SET new_due_date = new_due_dates.shift -%] >+ [%- new_due_date | $KohaDates as_due_date => 1 -%] >+ <input type="hidden" name="new_due_date_issue_[% checkout.issue_id | html %]" value="[% new_due_date %]"> > </td> > </tr> > [% END %] >@@ -197,7 +189,7 @@ > </div> <!-- /.page-section --> > <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected checkouts!</div> > <fieldset class="action"> >- <input type="hidden" name="op" value="cud-modify" /> >+ <input type="hidden" name="op" value="cud-commit_preview" /> > <input type="hidden" name="new_hard_due_date" value="[% new_hard_due_date | $KohaDates dateformat => 'iso' %]" /> > <input type="hidden" name="due_date_days" value="[% due_date_days | html %]" /> > <input type="submit" class="btn btn-primary" value="Modify selected checkouts" /> >@@ -297,6 +289,17 @@ > "paginate": false > })); > >+ $('.submit_extend').on('click', function(){ >+ let form_action = $(this).val(); >+ if( form_action == 'Update due dates' ){ >+ let form_input = '<input type="hidden" name="op" value="cud-modify">'; >+ $("#extend_due_dates_form").append(form_input).attr('method','post').submit(); >+ } else { >+ let form_input = '<input type="hidden" name="op" value="list">'; >+ $("#extend_due_dates_form").append(form_input).attr('method','get').submit(); >+ } >+ }); >+ > $("#extend_due_dates_form").on('submit', function(e) { > var new_hard_due_date = $("#new_hard_due_date").val(); > var due_date_days = $("#due_date_days").val(); >diff --git a/tools/batch_extend_due_dates.pl b/tools/batch_extend_due_dates.pl >index d6b0e84fc85..6cefe674980 100755 >--- a/tools/batch_extend_due_dates.pl >+++ b/tools/batch_extend_due_dates.pl >@@ -22,22 +22,22 @@ use Modern::Perl; > > use CGI; > >-use C4::Auth qw( get_template_and_user ); >+use C4::Auth qw( get_template_and_user ); > use C4::Output qw( output_html_with_http_headers ); > use Koha::Checkouts; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Items; > >-my $input = CGI->new; >-my $op = $input->param('op') // q|form|; >+my $input = CGI->new; >+my $op = $input->param('op') // q|form|; > my $preview_results = $input->param('preview_results'); > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >- template_name => 'tools/batch_extend_due_dates.tt', >- query => $input, >- type => "intranet", >- flagsrequired => { tools => 'batch_extend_due_dates' }, >+ template_name => 'tools/batch_extend_due_dates.tt', >+ query => $input, >+ type => "intranet", >+ flagsrequired => { tools => 'batch_extend_due_dates' }, > } > ); > >@@ -45,8 +45,27 @@ my @issue_ids; > > if ( $op eq 'form' ) { > $template->param( view => 'form', ); >-} >-elsif ( $op eq 'list' ) { >+} elsif ( $op eq 'cud-commit_preview' ) { >+ @issue_ids = $input->multi_param('issue_id') unless @issue_ids; >+ >+ my $checkouts = >+ Koha::Checkouts->search( { issue_id => { -in => \@issue_ids } } ); >+ while ( my $checkout = $checkouts->next ) { >+ my $new_due_date = $input->param( 'new_date_due_issue_' . $checkout->issue_id ); >+ >+ # Update checkout's due date >+ $checkout->date_due($new_due_date)->store; >+ >+ # Update items.onloan >+ $checkout->item->onloan($new_due_date)->store; >+ } >+ >+ $template->param( >+ view => 'report', >+ checkouts => $checkouts, >+ ); >+ >+} else { > > my @categorycodes = $input->multi_param('categorycodes'); > my @itemtypecodes = $input->multi_param('itemtypecodes'); >@@ -75,93 +94,65 @@ elsif ( $op eq 'list' ) { > > if ( $from_due_date and $to_due_date ) { > my $to_due_date_endday = dt_from_string($to_due_date); >- $to_due_date_endday >- ->set( # We set last second of day to see all checkouts from that day >+ $to_due_date_endday->set( # We set last second of day to see all checkouts from that day > hour => 23, > minute => 59, > second => 59 >- ); >+ ); > $search_params->{'me.date_due'} = { > -between => [ > $dtf->format_datetime( dt_from_string($from_due_date) ), > $dtf->format_datetime($to_due_date_endday), > ] > }; >- } >- elsif ($from_due_date) { >+ } elsif ($from_due_date) { > $search_params->{'me.date_due'} = >- { '>=' => $dtf->format_datetime( dt_from_string($from_due_date) ) }; >- } >- elsif ($to_due_date) { >+ { '>=' => $dtf->format_datetime( dt_from_string($from_due_date) ) }; >+ } elsif ($to_due_date) { > my $to_due_date_endday = dt_from_string($to_due_date); >- $to_due_date_endday >- ->set( # We set last second of day to see all checkouts from that day >+ $to_due_date_endday->set( # We set last second of day to see all checkouts from that day > hour => 23, > minute => 59, > second => 59 >- ); >+ ); > $search_params->{'me.date_due'} = >- { '<=' => $dtf->format_datetime($to_due_date_endday) }; >+ { '<=' => $dtf->format_datetime($to_due_date_endday) }; > } > > my $checkouts = Koha::Checkouts->search( > $search_params, >- { >- join => [ 'item', 'patron' ] >- } >+ { join => [ 'item', 'patron' ] } > ); > > my @new_due_dates; > while ( my $checkout = $checkouts->next ) { >- if ($preview_results) { >- push( >- @new_due_dates, >- calc_new_due_date( >- { >- due_date => dt_from_string( $checkout->date_due ), >- new_hard_due_date => $new_hard_due_date, >- add_days => $due_date_days >- } >- ), >- ); >- } else { >- push( @issue_ids, $checkout->id ); >- } >- } >- >- if ( $preview_results ) { >- $template->param( >- checkouts => $checkouts, >- new_hard_due_date => $new_hard_due_date, >- due_date_days => $due_date_days, >- new_due_dates => \@new_due_dates, >- view => 'list', >+ push( >+ @new_due_dates, >+ calc_new_due_date( >+ { >+ due_date => dt_from_string( $checkout->date_due ), >+ new_hard_due_date => $new_hard_due_date, >+ add_days => $due_date_days >+ } >+ ), > ); >- } else { >- $op = 'cud-modify'; > } >-} >- >-if ( $op eq 'cud-modify' ) { > >- # We want to modify selected checkouts! >- my $new_hard_due_date = $input->param('new_hard_due_date'); >- my $due_date_days = $input->param('due_date_days'); >+} > >- # @issue_ids will already be populated if we are skipping the results display >- @issue_ids = $input->multi_param('issue_id') unless @issue_ids; >+if ( $op = 'list' ) { >+ $template->param( >+ checkouts => $checkouts, >+ new_hard_due_date => $new_hard_due_date, >+ due_date_days => $due_date_days, >+ new_due_dates => \@new_due_dates, >+ view => 'list', >+ ); >+} elsif ( $op eq 'cud-modify' ) { > >- $new_hard_due_date &&= dt_from_string($new_hard_due_date); >- my $checkouts = >- Koha::Checkouts->search( { issue_id => { -in => \@issue_ids } } ); >+ $checkouts->reset; > while ( my $checkout = $checkouts->next ) { >- my $new_due_date = calc_new_due_date( >- { >- due_date => dt_from_string($checkout->date_due), >- new_hard_due_date => $new_hard_due_date, >- add_days => $due_date_days >- } >- ); >+ my $new_due_date = shift(@new_due_dates); > > # Update checkout's due date > $checkout->date_due($new_due_date)->store; >@@ -183,16 +174,16 @@ sub calc_new_due_date { > my $add_days = $params->{add_days}; > > my $new; >- if ( $new_hard_due_date ) { >- $new = $new_hard_due_date->clone->set( >- hour => $due_date->hour, >- minute => $due_date->minute, >- second => $due_date->second, >- ) >- } else { >- $new = $due_date->clone->add( days => $add_days ); >- } >- return $new; >+ if ($new_hard_due_date) { >+ $new = $new_hard_due_date->clone->set( >+ hour => $due_date->hour, >+ minute => $due_date->minute, >+ second => $due_date->second, >+ ); >+ } else { >+ $new = $due_date->clone->add( days => $add_days ); >+ } >+ return $new; > } > > output_html_with_http_headers $input, $cookie, $template->output; >-- >2.39.5
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 37941
: 171609