From 92fe1a5d07ff52a2b490367193dcfae5f8b1cfa6 Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Wed, 5 Feb 2020 04:33:50 +0000
Subject: [PATCH] Bug 18127: Add batch modified records to an existing list

To test:
1) Start by having no (zero) lists
2) Go to Tools -> Batch record modification
3) Go through the batch record modification process, confirm everything
works as normal and there is a link to do a new batch record
modification at the end
4) In another tab, go to Lists and create a new list
5) Go back to the first tab and start a new batch modification process
6) At the end of the process, there should be a new option to add
modified records to an existing list
7) Select a list from the dropdown and confirm you are able to save your
modified records to the list as expected
8) Start a new batch modification process, this time for authorities
records
9) At the end confirm there is no option to add modified records to a
list, because authorities cannot be added to lists

Sponsored-by: Catalyst IT

Signed-off-by: Jessica Zairo <jzairo@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 .../tools/batch_record_modification.tt        | 38 ++++++++++++++++++-
 tools/batch_record_modification.pl            |  4 +-
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt
index 3d64557370..960217a9c9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt
@@ -245,19 +245,37 @@
                             </form> <!-- /#process -->
                         [% ELSE %]
                             <div class="dialog message">
-                                No records were modified. <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
+                                No records were modified. [% IF recordtype != 'biblio' %]<a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>[% END %]
                             </div>
                         [% END %]
                     [% ELSIF view == 'report' %]
                         [% IF report.total_records == report.total_success %]
                             <div class="dialog message">
-                                All records have successfully been modified! <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
+                                All records have successfully been modified! [% IF recordtype != 'biblio' %]<a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>[% END %]
                             </div>
                         [% ELSE %]
                             <div class="dialog message">
                                 [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
                             </div>
                         [% END %]
+
+                        [% IF recordtype == 'biblio' %]
+                            <h3>Next steps</h3>
+                            <ul>
+                                <li><a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
+                                [% IF lists.count %]
+                                <li>
+                                    <label for="add_bibs_to_list">Add modified records to the following list: </label>
+                                    <select name="add_bibs_to_list" id="add_bibs_to_list">
+                                        <option value="">Select a list</option>
+                                        [% FOREACH list IN lists %]
+                                            <option class="shelf" value="[% list.shelfnumber %]">[% list.shelfname %]</option>
+                                        [% END %]
+                                    </select>
+                                </li>
+                                [% END %]
+                            </ul>
+                        [% END %]
                     [% ELSIF view == 'errors' %]
                         [% FOR error IN errors %]
                             [% IF error == 'no_template_defined' %]
@@ -376,6 +394,22 @@
                 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
             });
 
+            $("#add_bibs_to_list").change(function(){
+                var selected = $("#add_bibs_to_list").find("option:selected");
+                if ( selected.attr("class") == "shelf" ){
+                    var shelfnumber = selected.attr("value");
+                    var bibs = new Array();
+                    [% FOREACH message IN messages %]
+                        [% IF message.code == 'biblio_modified' %]
+                            bibs.push("biblionumber="+[% message.biblionumber %]);
+                        [% END %]
+                    [% END %]
+                    var bibstring = bibs.join("&");
+                    window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&'+bibstring, 'popup', 'width=500,height=500,toolbar=false,scrollbars=yes,resizeable=yes');
+                    return false;
+                }
+            });
+
         });
     </script>
 [% END %]
diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl
index 1a82c476c3..0203b0bb69 100755
--- a/tools/batch_record_modification.pl
+++ b/tools/batch_record_modification.pl
@@ -50,6 +50,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
         flagsrequired => { tools => 'records_batchmod' },
 });
 
+$template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, owner => $loggedinuser }, { category => 2 }]) );
 
 my $sessionID = $input->cookie("CGISESSID");
 
@@ -63,14 +64,13 @@ if ( $completedJobID ) {
         report => $report,
         messages => $messages,
         view => 'report',
+        recordtype => $recordtype,
     );
     output_html_with_http_headers $input, $cookie, $template->output;
     $job->clear();
     exit;
 }
 
-$template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, owner => $loggedinuser }, { category => 2 }]) );
-
 my @templates = GetModificationTemplates( $mmtid );
 unless ( @templates ) {
     $op = 'error';
-- 
2.20.1