Bug 8132: Delete the items in a transaction and rollback if something wrong
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / batchMod-del.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% PROCESS 'i18n.inc' %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Tools &rsaquo; Batch item deletion</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 <!--[if IE]>
9 <style>#selections { display: none; }</style>
10 <![endif]-->
11 </head>
12 <body id="tools_batchMod-del" class="tools">
13 [% INCLUDE 'header.inc' %]
14 [% INCLUDE 'cat-search.inc' %]
15
16 <div id="breadcrumbs">
17     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
18     <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
19     <a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Batch item deletion</a>
20 </div>
21
22 <div class="main container-fluid">
23
24                 [% IF ( show ) %]<h1>Batch item deletion</h1>[% ELSE %]<h1>Batch item deletion results</h1>[% END %]
25         [% IF ( barcode_not_unique ) %]<div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]
26         [% IF ( no_next_barcode ) %]<div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
27         [% IF ( book_on_loan ) %]<div class="dialog alert"><strong>Cannot delete</strong>: item is checked out.</div>[% END %]
28         [% IF ( book_reserved ) %]<div class="dialogalert"><strong>Cannot delete</strong>: item has a waiting hold.</div>[% END %]
29
30     [% UNLESS ( action ) %]
31
32     [% IF ( notfoundbarcodes.size ) %]
33         <div class="dialog alert">
34             [% IF ( itemresults ) %]<p>Warning, the following barcodes were not found:</p>[% ELSE %]<p>Warning: no barcodes were found</p>[% END %]
35         </div>
36         <table style="margin:auto;">
37             <thead>
38                 <tr><th>Barcodes not found</th></tr>
39             </thead>
40             <tbody>
41                 [% FOREACH notfoundbarcode IN notfoundbarcodes %]
42                     <tr><td>[% notfoundbarcode |html %]</td></td>
43                 [% END %]
44             </tbody>
45         </table>
46         [% UNLESS ( too_many_items_display ) %]
47             [% IF ( item_loop ) %]
48                     <h4>The following barcodes were found: </h4>
49             [% END %]
50         [% END %]
51     [% END %] <!-- /notfoundbarcodes -->
52     [% IF ( notfounditemnumbers.size ) %]
53         <div class="dialog alert">
54             [% IF ( itemresults ) %]<p>Warning, the following itemnumbers were not found:</p>[% ELSE %]<p>Warning: no itemnumbers were found</p>[% END %]
55         </div>
56         <table style="margin:auto;">
57             <thead>
58                 <tr><th>Itemnumbers not found</th></tr>
59             </thead>
60             <tbody>
61                 [% FOREACH notfounditemnumber IN notfounditemnumbers %]
62                     <tr><td>[% notfounditemnumber |html %]</td></td>
63                 [% END %]
64             </tbody>
65         </table>
66         [% UNLESS ( too_many_items_display ) %]
67             [% IF ( item_loop ) %]
68                     <h4>The following itemnumbers were found: </h4>
69             [% END %]
70         [% END %]
71     [% END %] <!-- /notfounditemnumbers -->
72
73
74
75
76 <form name="f" action="batchMod.pl" method="post">
77      <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblionumber | html %]" />
78      <input type="hidden" name="op" value="[% op | html %]" />
79      <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
80      <input type="hidden" name="completedJobID" id="completedJobID" value="" />
81      <input type="hidden" name="src" id="src" value="[% src | html %]" />
82      [% IF biblionumber %]
83         <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblionumber | html %]" />
84      [% END %]
85
86 [% IF ( item_loop ) %]
87     [% IF ( show ) %]<div id="toolbar"><a id="selectallbutton" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="clearallbutton" href="#"><i class="fa fa-remove"></i> Clear all</a></div>[% END %]
88     <div id="cataloguing_additem_itemlist">
89
90     <p id="selections"><strong>Show/hide columns:</strong> <span class="selected"><input type="checkbox" checked="checked" id="showall"/><label for="showall">Show all columns</label></span> <span><input type="checkbox" id="hideall"/><label for="hideall">Hide all columns</label></span>
91         [% FOREACH item_header_loo IN item_header_loop %]
92         <span class="selected"><input id="checkheader[% loop.count | html %]" type="checkbox" checked="checked" /> <label for="checkheader[% loop.count | html %]">[% item_header_loo.header_value | html %]</label> </span>
93         [% END %]
94     </p>
95
96         <table id="itemst">
97             <thead>
98             <tr>
99                 [% IF ( show ) %]<th>&nbsp;</th>[% END %]
100                 <th class="anti-the">Title</th>
101                 <th class="holds_count" title="Item holds / Total holds">Holds</th>
102                 [% FOREACH item_header_loo IN item_header_loop %]
103                 <th> [% item_header_loo.header_value | html %] </th>
104                 [% END %]
105             </tr>
106             </thead>
107             <tbody>
108             [% FOREACH item_loo IN item_loop %]
109               <tr>
110                 [% IF show %]
111                   [% IF item_loo.nomod %]
112                     <td class="error">Cannot delete</td>
113                 [% ELSE %]
114                     [% SET can_be_deleted = item_loo.item.safe_to_delete %]
115                     [% IF can_be_deleted == 1 %]
116                         <td><input type="checkbox" name="itemnumber" value="[% item_loo.itemnumber | html %]" id="row[% item_loo.itemnumber | html %]" checked="checked" /></td>
117                     [% ELSE %]
118                         [% SWITCH can_be_deleted %]
119                         [% CASE "book_on_loan" %][% SET cannot_delete_reason = t("Item is checked out") %]
120                         [% CASE "not_same_branch" %][% SET cannot_delete_reason = t("Item does not belongs to your library") %]
121                         [% CASE "book_reserved" %][% SET cannot_delete_reason = t("Item has a waiting hold") %]
122                         [% CASE "linked_analytics" %][% SET cannot_delete_reason = t("Item has linked analytics") %]
123                         [% CASE "last_item_for_hold" %][% SET cannot_delete_reason = t("Last item for bibliographic record wich biblio-level hold on it") %]
124                         [% CASE %][% SET cannot_delete_reason = t("Unknown reason") _ '(' _ can_be_deleted _ ')' %]
125                         [% END %]
126
127                         <td><input type="checkbox" name="itemnumber" value="[% item_loo.itemnumber | html %]" id="row[% item_loo.itemnumber | html %]" disabled="disabled" title="[% cannot_delete_reason %]"/></td>
128                     [% END %]
129                   [% END %]
130                 [% ELSE %]
131                   <td>&nbsp;</td>
132                 [% END %]
133                 <td>
134                     <label for="row[% item_loo.itemnumber | html %]">
135                         <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item_loo.biblionumber | uri %]">
136                             [% item_loo.title | html %]
137                         </a>
138                         [% IF ( item_loo.author ) %], by [% item_loo.author | html %][% END %]
139                     </label>
140                 </td>
141                 <td class="holds_count">
142                     [% IF item_loo.holds %]
143                         [% IF item_loo.item_holds %]
144                             <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="Holds on this item: [% item_loo.item_holds | html %] / Total holds on this record: [% item_loo.holds | html -%]" >
145                         [% ELSE %]
146                             <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="No holds on this item / Total holds on this record: [% item_loo.holds | html -%]" >
147                         [% END %]
148                     [% ELSE %]
149                         [% IF item_loo.holds %]
150                             <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="Holds on this record: [% item_loo.holds | html -%]" >
151                         [% ELSE %]
152                             <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="No holds on this record" >
153                         [% END %]
154                     [% END %]
155                                 [% IF item_loo.holds %]
156                                     [% item_loo.item_holds | html %]/[% item_loo.holds | html %]
157                                 [% ELSE %]
158                                     [% item_loo.holds | html %]
159                                 [% END %]
160                             </a>
161                 </td>
162             [% FOREACH item_valu IN item_loo.item_value %] <td>[% item_valu.field | html %]</td>
163                     [% END %] </tr>
164             [% END %]
165             </tbody>
166         </table>
167     </div>
168 [% END %]
169
170 [% IF ( simple_items_display ) %]
171     <ul>
172     [% FOREACH simple_items_displa IN simple_items_display %]
173         <li>
174             <a href="[% simple_items_displa.itemnumber | url %]">[% simple_items_displa.barcode | html %]</a>
175         </li>
176     [% END %]
177     </ul>
178 [% END %]
179
180
181 [% IF ( show ) %]
182
183 [% IF ( too_many_items_display ) %]
184     <p>Too many items ([% too_many_items_display | html %]) to display individually.</p>
185     [% FOREACH itemnumber IN itemnumbers_array %]
186         <input type="hidden" name="itemnumber" value="[% itemnumber | html %]" />
187     [% END %]
188 [% END %]
189
190 [% IF ( itemresults ) %]
191         <div id="cataloguing_additem_newitem">
192          <input type="hidden" name="op" value="[% op | html %]" />
193          <p>This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.</p>
194          <input type="hidden" name="del" value="1" />
195          <fieldset class="action">
196         <input type="checkbox" name="del_records" id="del_records" /> <label for="del_records">Delete records if no items remain.</label>
197         [% IF too_many_items_display %]
198             <input type="submit" name="mainformsubmit" value="Delete ALL submitted items" />
199         [% ELSE %]
200             <input type="submit" name="mainformsubmit" value="Delete selected items" />
201         [% END %]
202
203         <a href="/cgi-bin/koha/tools/batchMod.pl?del=1" class="cancel">Cancel</a>
204         </fieldset>
205     </div>
206     [% ELSE %]
207     <p><a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Return to batch item deletion</a></p>
208     [% END %]
209     [% END %]
210     </form>
211     [% END %]
212
213 [% IF ( action ) %]
214     [% IF deletion_failed %]
215         <div class="dialog alert">
216             At least one item blocked the deletion. The operation rolled back and nothing happened!
217         </div>
218     [% ELSE %]
219         <div class="dialog message">
220             <p>[% deleted_items | html %] item(s) deleted.</p>
221             [% IF delete_records %] <p>[% deleted_records | html %] record(s) deleted.</p> [% END %]
222             [% IF src == 'CATALOGUING' # from catalogue/detail.pl > Delete items in a batch%]
223                 [% IF biblio_deleted %]
224                     <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Return to the cataloging module</a>
225                 [% ELSE %]
226                     <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">Return to the record</a>
227                 [% END %]
228             [% ELSIF src %]
229                 <a href="[% src | url %]">Return to where you were</a>
230             [% ELSE %]
231                 <a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Return to batch item deletion</a>
232             [% END %]
233         </div>
234     [% END %]
235     [% IF ( not_deleted_items ) %]
236     <div style="width:55%;margin:auto;">
237         <p>[% not_deleted_items | html %] item(s) could not be deleted: [% FOREACH not_deleted_itemnumber IN not_deleted_itemnumbers %][% not_deleted_itemnumber.itemnumber | html %][% END %]</p>
238     [% IF ( not_deleted_loop ) %]
239     <table id="itemst">
240         <thead>
241             <tr>
242             <th>Itemnumber</th>
243             <th>Barcode</th>
244             <th>Reason</th>
245             </tr>
246         </thead>
247         <tbody>
248             [% FOREACH not_deleted_loo IN not_deleted_loop %]
249             <tr>
250                 <td>[% not_deleted_loo.itemnumber | html %]</td>
251                 <td>[% IF ( CAN_user_editcatalogue_edit_items ) %]<a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&amp;biblionumber=[% not_deleted_loo.biblionumber | uri %]&amp;itemnumber=[% not_deleted_loo.itemnumber | uri %]">[% not_deleted_loo.barcode | html %]</a>[% ELSE %][% not_deleted_loo.barcode | html %][% END %]</td>
252                 <td>
253                     [% SWITCH not_deleted_loo.reason %]
254                     [% CASE "book_on_loan" %][% SET cannot_delete_reason = t("Item is checked out") %]
255                     [% CASE "not_same_branch" %][% SET cannot_delete_reason = t("Item does not belongs to your library") %]
256                     [% CASE "book_reserved" %][% SET cannot_delete_reason = t("Item has a waiting hold") %]
257                     [% CASE "linked_analytics" %][% SET cannot_delete_reason = t("Item has linked analytics") %]
258                     [% CASE "last_item_for_hold" %][% SET cannot_delete_reason = t("Last item for bibliographic record wich biblio-level hold on it") %]
259                     [% CASE %][% SET cannot_delete_reason = t("Unknown reason") _ '(' _ can_be_deleted _ ')' %]
260                     [% END %]
261                     [% cannot_delete_reason %]
262                 </td>
263             </tr>
264             [% END %]
265         </tbody>
266         </table>
267     [% END %]
268     </div>
269     [% END %]
270
271     <p>
272         [% IF src == 'CATALOGUING' # from catalogue/detail.pl > Delete items in a batch%]
273             [% IF biblio_deleted %]
274                 <a class="btn btn-default" href="/cgi-bin/koha/cataloguing/addbooks.pl"><i class="fa fa-check-square-o"></i> Return to the cataloging module</a>
275             [% ELSE %]
276                <a class="btn btn-default" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]"><i class="fa fa-check-square-o"></i> Return to the record</a>
277             [% END %]
278         [% ELSIF src %]
279            <a class="btn btn-default" href="[% src | url %]"><i class="fa fa-check-square-o"></i> Return to where you were</a>
280         [% ELSE %]
281            <a class="btn btn-default" href="/cgi-bin/koha/tools/batchMod.pl?del=1"><i class="fa fa-check-square-o"></i> Return to batch item deletion</a>
282         [% END %]
283     </p>
284 [% END %]
285     </div>
286
287 [% MACRO jsinclude BLOCK %]
288     [% Asset.js("js/tools-menu.js") | $raw %]
289     [% INCLUDE 'datatables.inc' %]
290     [% Asset.js("js/pages/batchMod.js") | $raw %]
291     [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
292     <script type="text/javascript">
293         // Prepare array of all column headers, incrementing each index by
294         // two to accommodate control and title columns
295         var allColumns = new Array([% FOREACH item_header_loo IN item_header_loop %]'[% loop.count | html %]'[% UNLESS ( loop.last ) %],[% END %][% END %]);
296         for( x=0; x<allColumns.length; x++ ){
297           allColumns[x] = Number(allColumns[x]) + 2;
298         }
299         $(document).ready(function(){
300             $("#mainformsubmit").on("click",function(){
301                 return submitBackgroundJob(this.form);
302             });
303         });
304     </script>
305 [% END %]
306
307 [% INCLUDE 'intranet-bottom.inc' %]