Bug 8132: No changes but disable checkboxes
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 2 Dec 2019 15:15:59 +0000 (16:15 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 11 May 2020 08:56:00 +0000 (09:56 +0100)
When the list of items is displayed we already know if there will be a
problem during the deletion. So let's disable the checkbox to tell the
user in advance that items cannot be deleted.

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt
tools/batchMod.pl

index 3d11faf..8701d9e 100644 (file)
@@ -1,6 +1,7 @@
 [% USE raw %]
 [% USE Asset %]
 [% SET footerjs = 1 %]
+[% PROCESS 'i18n.inc' %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Batch item deletion</title>
 [% INCLUDE 'doc-head-close.inc' %]
               <tr>
                 [% IF show %]
                   [% IF item_loo.nomod %]
-                    <td class="error">Cannot edit</td>
-                  [% ELSE %]
-                    <td><input type="checkbox" name="itemnumber" value="[% item_loo.itemnumber | html %]" id="row[% item_loo.itemnumber | html %]" checked="checked" data-is-onloan="[% item_loo.onloan | html %]" /></td>
+                    <td class="error">Cannot delete</td>
+                [% ELSE %]
+                    [% SET can_be_deleted = item_loo.item.safe_to_delete %]
+                    [% IF can_be_deleted == 1 %]
+                        <td><input type="checkbox" name="itemnumber" value="[% item_loo.itemnumber | html %]" id="row[% item_loo.itemnumber | html %]" checked="checked" /></td>
+                    [% ELSE %]
+                        [% SWITCH can_be_deleted %]
+                        [% CASE "book_on_loan" %][% SET cannot_delete_reason = t("Item is checked out") %]
+                        [% CASE "not_same_branch" %][% SET cannot_delete_reason = t("Item does not belongs to your library") %]
+                        [% CASE "book_reserved" %][% SET cannot_delete_reason = t("Item has a waiting hold") %]
+                        [% CASE "linked_analytics" %][% SET cannot_delete_reason = t("Item has linked analytics") %]
+                        [% CASE %][% SET cannot_delete_reason = t("Unknown reason") %]
+                        [% END %]
+
+                        <td><input type="checkbox" name="itemnumber" value="[% item_loo.itemnumber | html %]" id="row[% item_loo.itemnumber | html %]" disabled="disabled" title="[% cannot_delete_reason %]"/></td>
+                    [% END %]
                   [% END %]
                 [% ELSE %]
                   <td>&nbsp;</td>
index 8b13257..a7e3188 100755 (executable)
@@ -633,6 +633,7 @@ sub BuildItemsData{
             $this_row{biblionumber} = $biblio->biblionumber;
             $this_row{holds}        = $biblio->holds->count;
             $this_row{item_holds}   = Koha::Holds->search( { itemnumber => $itemnumber } )->count;
+            $this_row{item}         = Koha::Items->find($itemnumber);
 
                        if (%this_row) {
                                push(@big_array, \%this_row);
@@ -658,6 +659,7 @@ sub BuildItemsData{
       $row_data{biblionumber} = $row->{biblionumber};
       $row_data{holds}        = $row->{holds};
       $row_data{item_holds}   = $row->{item_holds};
+      $row_data{item}         = $row->{item};
       my $is_on_loan = C4::Circulation::IsItemIssued( $row->{itemnumber} );
       $row_data{onloan} = $is_on_loan ? 1 : 0;
                        push(@item_value_loop,\%row_data);