Bug 12759: Pass records from selected tab
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / batch_delete_records.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% PROCESS 'authorities-search-results.inc' %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Tools &rsaquo; Batch record deletion</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 [% Asset.css("css/datatables.css") | $raw %]
9 </head>
10
11 <body id="tools_batch_delete_records" class="tools">
12 [% INCLUDE 'header.inc' %]
13 [% INCLUDE 'cat-search.inc' %]
14
15 <div id="breadcrumbs">
16     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
17     <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
18     <a href="/cgi-bin/koha/tools/batch_delete_records.pl">Batch record deletion</a>
19 </div>
20
21 <div class="main container-fluid">
22     <div class="row">
23         <div class="col-sm-10 col-sm-push-2">
24             <main>
25
26   <h1>Batch record deletion</h1>
27   [% FOREACH message IN messages %]
28     [% IF message.type == 'success' %]
29       <div class="dialog message">
30     [% ELSIF message.type == 'warning' %]
31       <div class="dialog alert">
32     [% ELSIF message.type == 'error' %]
33       <div class="dialog alert" style="margin:auto;">
34     [% END %]
35     [% IF message.code == 'biblio_not_exists' %]
36       The biblionumber [% message.biblionumber | html %] does not exist in the database.
37     [% ELSIF message.code == 'authority_not_exists' %]
38       The authority id [% message.authid | html %] does not exist in the database.
39     [% ELSIF message.code == 'item_issued' %]
40       At least one item is checked out on bibliographic record [% message.biblionumber | html %].
41     [% ELSIF message.code == 'reserve_not_cancelled' %]
42       Bibliographic record [% message.biblionumber | html %] was not deleted. A hold could not be canceled (reserve_id [% message.reserve_id | html %]).
43     [% ELSIF message.code == 'item_not_deleted' %]
44       The bibliographic record [% message.biblionumber | html %] was not deleted. An error was encountered when deleting an item (itemnumber [% message.itemnumber | html %]).
45     [% ELSIF message.code == 'biblio_not_deleted' %]
46       Bibliographic record [% message.biblionumber | html %] was not deleted. An error occurred.
47     [% ELSIF message.code == 'authority_not_deleted' %]
48       Authority record [% message.authid | html %] was not deleted. An error occurred.
49     [% ELSIF message.code == 'biblio_deleted' %]
50       Bibliographic record [% message.biblionumber | html %] has been deleted successfully.
51     [% ELSIF message.code == 'authority_deleted' %]
52       Authority [% message.authid | html %] has been deleted successfully.
53     [% END %]
54     [% IF message.error %]
55       (The error was: [% message.error | html %], see the Koha log file for more information).
56     [% END %]
57     </div>
58   [% END %]
59   [% IF op == 'form' %]
60     <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batch_delete_records.pl" id="record_ids_selection">
61       <fieldset class="rows">
62         <legend>Record type</legend>
63         <ol>
64           <li><label for="biblio_type">Bibliographic: </label><input type="radio" name="recordtype" value="biblio" id="biblio_type" checked="checked" /></li>
65           <li><label for="authority_type">Authorities: </label><input type="radio" name="recordtype" value="authority" id="authority_type" /></li>
66         </ol>
67       </fieldset>
68
69       <br><br>
70
71       <div id="batch_del_form" class="toptabs">
72         <ul>
73           <li><a href="#uploadfile_tab">Upload a file</a></li>
74           [% IF lists.count %]<li id="show_list_option"><a href="#shelves_tab">Select a list of records</a></li>[% END %]
75           <li><a href="#enterlist_tab">Enter a list of record numbers</a></li>
76         </ul>
77
78         <div id="uploadfile_tab">
79           <fieldset class="rows">
80             <legend>Use a file</legend>
81             <ol>
82               <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
83             </ol>
84           </fieldset>
85           &nbsp;
86         </div>
87
88         [% IF lists.count %]
89             <div id="shelves_tab">
90               <fieldset class="rows">
91                 <legend>Or select a list of records</legend>
92                 <ol>
93                   <li>
94                     <label for="shelf_number">Use records from the following list: </label>
95                     <select name="shelf_number" id="shelf_number">
96                       <option value="">Select a list</option>
97                         [% FOREACH list IN lists %]
98                           <option value="[% list.shelfnumber %]">[% list.shelfname %]</option>
99                         [% END %]
100                       </option>
101                     </select>
102                   </li>
103                 </ol>
104               </fieldset>
105               &nbsp;
106             </div>
107         [% END %]
108
109         <div id="enterlist_tab">
110           <fieldset class="rows">
111             <legend>Or enter a list of record numbers</legend>
112             <ol>
113               <li>
114                 <label for="recordnumber_list">List of biblionumbers or authority ids (one per line): </label>
115                 <textarea rows="10" cols="30" id="recordnumber_list" name="recordnumber_list"></textarea>
116               </li>
117             </ol>
118           </fieldset>
119           &nbsp;
120         </div>
121
122       </div>
123
124       <fieldset class="action">
125         <input type="hidden" name="op" value="list" />
126         <input type="submit" value="Continue" class="button" />
127         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
128       </fieldset>
129     </form>
130   [% ELSIF op == 'list' %]
131     [% IF records %]
132       [% IF recordtype == 'biblio' %]
133         <div id="toolbar">
134           <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
135           | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
136           | <a id="selectwithoutitems" href="#">Select without items</a>
137           | <a id="selectnotreserved" href="#">Select without holds</a>
138         </div>
139         <form action="/cgi-bin/koha/tools/batch_delete_records.pl" method="post" id="selectrecords">
140           <table id="biblios" class="records">
141             <thead>
142               <tr>
143                 <th></th>
144                 <th>Biblionumber</th>
145                 <th>Title</th>
146                 <th>Items</th>
147                 <th>Holds</th>
148                 <th>Checkouts</th>
149               </tr>
150             </thead>
151             <tbody>
152               [% FOR biblio IN records %]
153                 <tr>
154                   <td><input type="checkbox" name="record_id" id="record_id_[% biblio.biblionumber | html %]" value="[% biblio.biblionumber | html %]" data-items="[% biblio.itemnumbers.size | html %]" data-issues="[% biblio.issues_count | html %]" data-reserves="[% biblio.holds_count | html %]" /></td>
155                   <td><label for="record_id_[% biblio.biblionumber | html %]">[% biblio.biblionumber | html %]</label></td>
156                   <td>[% INCLUDE 'biblio-default-view.inc' biblionumber=biblio.biblionumber %][% biblio.title | html %][% IF ( biblio.subtitle ) %][% FOREACH subtitle IN biblio.subtitle %] [% subtitle.subfield | html %][% END %][% END %]</a></td>
157                   <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber | uri %]">[% biblio.itemnumbers.size | html %]</a></td>
158                   <td><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio.biblionumber | uri %]">[% biblio.holds_count | html %]</a></td>
159                   <td><a href="/cgi-bin/koha/catalogue/issuehistory.pl?biblionumber=[% biblio.biblionumber | uri %]">[% biblio.issues_count | html %]</a></td>
160                 </tr>
161               [% END %]
162             </tbody>
163           </table>
164           <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will delete all selected bibliographic records, attached subscriptions, existing holds, and attached items!</div>
165       [% ELSE %]
166         <div id="toolbar">
167           <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
168           | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
169           | <a id="clearlinkedtobiblio" href="#">Clear used authorities</a>
170         </div>
171         <form action="/cgi-bin/koha/tools/batch_delete_records.pl" method="post" id="selectauths">
172           <table id="authorities" class="records">
173             <thead>
174               <tr>
175                 <th></th>
176                 <th>Authid</th>
177                 <th>Summary</th>
178                 <th>Used in</th>
179               </tr>
180             </thead>
181             <tbody>
182               [% FOR authority IN records %]
183                 <tr>
184                   <td><input type="checkbox" name="record_id" value="[% authority.authid | html %]" data-usage="[% authority.count_usage | html %]" /></td>
185                   <td><a href="/cgi-bin/koha/authorities/detail.pl?authid=[% authority.authid | uri %]">[% authority.authid | html %]</a></td>
186                   <td>[% PROCESS authresult summary=authority.summary %]</td>
187                   <td><a href="/cgi-bin/koha/catalogue/search.pl?type=intranet&amp;op=do_search&amp;idx=an,phr&amp;q=[% authority.authid | uri %]">[% authority.count_usage | html %] record(s)</a></td>
188                 </tr>
189               [% END %]
190             </tbody>
191           </table>
192           <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will delete all selected authorities!</div>
193       [% END %]
194         <fieldset class="action">
195           <input type="hidden" name="op" value="delete" />
196           <input type="hidden" name="recordtype" value="[% recordtype | html %]" />
197           <input type="submit" value="Delete selected records" class="button" />
198           <a class="cancel" href="/cgi-bin/koha/tools/batch_delete_records.pl">Cancel</a>
199         </fieldset>
200       </form>
201     [% ELSE %]
202       There are no record ids defined.
203     [% END %]
204   [% ELSIF op == 'report' %]
205     [% IF report.total_records == report.total_success %]
206       All records have been deleted successfully!
207     [% ELSIF report.total_success == 0 %]
208       No record has been deleted. An error occurred.
209     [% ELSE %]
210       [% report.total_success | html %] / [% report.total_records | html %] records have been deleted successfully but some errors occurred.
211     [% END %]
212     <p><a href="/cgi-bin/koha/tools/batch_delete_records.pl" title="New batch record deletion">New batch record deletion</a></p>
213   [% ELSE %]
214     No action defined for the template.
215   [% END %]
216
217             </main>
218         </div> <!-- /.col-sm-10.col-sm-push-2 -->
219
220         <div class="col-sm-2 col-sm-pull-10">
221             <aside>
222                 [% INCLUDE 'tools-menu.inc' %]
223             </aside>
224         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
225      </div> <!-- /.row -->
226
227 [% MACRO jsinclude BLOCK %]
228     [% Asset.js("js/tools-menu.js") | $raw %]
229     [% INCLUDE 'datatables.inc' %]
230     [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
231     <script>
232         var MSG_CANNOT_BE_DELETED = _("This record cannot be deleted, at least one item is currently checked out.");
233         $(document).ready(function() {
234
235           $("#batch_del_form").tabs();
236
237           $("input[type='radio']").click(function(){
238             if ($(this).attr('id') == 'authority_type') {
239               $("#show_list_option").hide();
240             } else if ($(this).attr('id') == 'biblio_type') {
241               $("#show_list_option").show();
242             }
243           });
244           $("#selectall").click(function(e){
245             e.preventDefault();
246             $(".records").checkCheckboxes(":input[type='checkbox']:not(:disabled)");
247           });
248           $("#clearall").click(function(e){
249             e.preventDefault();
250             $(".records").unCheckCheckboxes(":input[type='checkbox']:not(:disabled)");
251           });
252           $("#selectwithoutitems").click(function(e){
253             e.preventDefault();
254             $("#biblios").checkCheckboxes(":input[data-items='0']:not(:disabled)");
255           });
256           $("#selectnotreserved").click(function(e){
257             e.preventDefault();
258             $("#biblios").checkCheckboxes(":input[data-reserves='0']:not(:disabled)");
259
260           });
261           $("#clearlinkedtobiblio").click(function(e){
262             e.preventDefault();
263             $("#authorities").unCheckCheckboxes(":not(input[data-usage='0'])");
264           });
265           $("#selectall").click();
266
267           [% IF recordtype == 'biblio' %]
268             $(".records input:checkbox[data-issues!='0']").each(function(){
269               $(this).attr('title', MSG_CANNOT_BE_DELETED)
270               $(this).prop('disabled', true);
271               $(this).prop('checked', false);
272               $(this).parents('tr').find('td').css('background-color', '#ffff99');
273             });
274           [% END %]
275
276           $("table#biblios").dataTable($.extend(true, {}, dataTablesDefaults, {
277             "aoColumnDefs": [
278               { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
279               { "aTargets": [ 3, 4 ], "sType": "num-html" }
280             ],
281             "sDom": 't',
282             "aaSorting": [],
283             "bPaginate": false
284           }));
285
286           $("table#authorities").dataTable($.extend(true, {}, dataTablesDefaults, {
287             "aoColumnDefs": [
288               { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
289               { "aTargets": [ 3 ], "sType": "num-html" }
290             ],
291             "sDom": 't',
292             "aaSorting": [],
293             "bPaginate": false
294           }));
295
296           $("#selectrecords").on("submit",function(){
297             var nb_checked = $("#selectrecords").find("input[type='checkbox'][name='record_id']:checked").size();
298             if (nb_checked == 0){
299               alert(_("No records have been selected."));
300               return false;
301             }
302           });
303
304           $("#selectauths").on("submit",function(){
305             var checked = $("#selectauths").find("input[type='checkbox'][name='record_id']:checked").size();
306             if (checked == 0) {
307               alert(_("No authorities have been selected."));
308               return false;
309             }
310           });
311
312           $("#record_ids_selection").on("submit", function(e){
313             var tab = $(this).find('.ui-tabs-active:first a').attr('href');
314             if ( tab == '#uploadfile_tab' ) {
315                 $("#shelf_number").empty('');
316                 $("#recordnumber_list").val('');
317             } else if ( tab == '#shelves_tab' ) {
318                 $("#uploadfile").val('')
319                 $("#recordnumber_list").val('');
320             } else { // enterlist
321                 $("#uploadfile").val('')
322                 $("#shelf_number").empty('');
323             }
324           });
325
326         });
327     </script>
328 [% END %]
329
330 [% INCLUDE 'intranet-bottom.inc' %]