From 04384d1893ee72eeb82f97bae82c6debe28c848a Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 11 Jun 2020 12:40:03 +0200
Subject: [PATCH] Bug 22417: Restore the 'add to list' feature

This feature has been added recently by bug 18127.

It highlights the need of a post processing hook.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Cook <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 admin/background_jobs.pl                      |  4 +-
 .../prog/en/modules/admin/background_jobs.tt  | 41 ++++++++++++-------
 .../tools/batch_record_modification.tt        | 17 --------
 tools/batch_record_modification.pl            |  2 -
 4 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl
index 4eacc8c4d4..85dd740b40 100755
--- a/admin/background_jobs.pl
+++ b/admin/background_jobs.pl
@@ -24,8 +24,8 @@ use C4::Context;
 use C4::Auth;
 use C4::Output;
 
-use Koha::BackgroundJob;
 use Koha::BackgroundJobs;
+use Koha::Virtualshelves;
 
 my $input             = new CGI;
 my $op                = $input->param('op') || 'list';
@@ -50,6 +50,8 @@ if ( $op eq 'view' ) {
         $template->param(
             job       => $job,
         );
+        $template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, owner => $loggedinuser }, { category => 2 }]) )
+            if $job->type eq 'batch_biblio_record_modification';
     } else {
         $op = 'list';
     }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt
index ada068edbb..4949d958f1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt
@@ -51,6 +51,16 @@
                         [% 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>
+                                [% IF lists.count %]
+                                    <br />
+                                    Add modified records to the following list:
+                                    <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 | html %]">[% list.shelfname | html %]</option>
+                                        [% END %]
+                                    </select>
+                                [% END %]
                             </div>
                         [% ELSE %]
                             <div class="dialog message">
@@ -95,21 +105,6 @@
                                 Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has not been modified. An error occurred on modifying it.[% IF m.error %] ([% m.error %])[% END %].
                             [% CASE 'biblio_modified' %]
                                 Bibliographic record <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% m.biblionumber | uri %]">[% m.biblionumber | html %]</a> has successfully been modified.
-                                <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 | html %]">[% list.shelfname | html %]</option>
-                                            [% END %]
-                                        </select>
-                                    </li>
-                                    [% END %]
-                                </ul>
                             [% END %]
                         </div>
                     [% END %]
@@ -224,6 +219,22 @@
                 "iDisplayLength": 10,
                 "sPaginationType": "full_numbers"
             }));
+
+            $("#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 job.messages %]
+                        [% IF message.code == 'biblio_modified' %]
+                            bibs.push("biblionumber="+[% message.biblionumber | html %]);
+                        [% 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/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 973ec4185e..140d3885aa 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
@@ -363,23 +363,6 @@
                 $("#marcPreviewLabel").html("");
                 $("#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 | html %]);
-                        [% 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 2e304e360b..0e2f87d28d 100755
--- a/tools/batch_record_modification.pl
+++ b/tools/batch_record_modification.pl
@@ -52,8 +52,6 @@ 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");
 
 my @templates = GetModificationTemplates( $mmtid );
-- 
2.24.1 (Apple Git-126)