Bug 9565: (follow-up) Adapt batch record deletion tool
[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>Batch record deletion &rsaquo; Tools &rsaquo; Koha</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 </head>
9
10 <body id="tools_batch_delete_records" class="tools">
11 [% INCLUDE 'header.inc' %]
12 [% INCLUDE 'cat-search.inc' %]
13
14 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
15     <ol>
16         <li>
17             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
18         </li>
19         <li>
20             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
21         </li>
22         <li>
23             <a href="#" aria-current="page">Batch record deletion</a>
24         </li>
25     </ol>
26 </nav>
27
28 <div class="main container-fluid">
29     <div class="row">
30         <div class="col-sm-10 col-sm-push-2">
31             <main>
32
33   <h1>Batch record deletion</h1>
34   [% FOREACH message IN messages %]
35     [% IF message.type == 'success' %]
36       <div class="dialog message">
37     [% ELSIF message.type == 'warning' %]
38       <div class="dialog alert">
39     [% ELSIF message.type == 'error' %]
40       <div class="dialog alert" style="margin:auto;">
41     [% END %]
42     [% IF message.code == 'biblio_not_exists' %]
43       The biblionumber [% message.biblionumber | html %] does not exist in the database.
44     [% ELSIF message.code == 'authority_not_exists' %]
45       The authority id [% message.authid | html %] does not exist in the database.
46     [% ELSIF message.code == 'cannot_enqueue_job' %]
47         Cannot enqueue this job.
48     [% ELSIF message.code == 'biblio_not_exists' %]
49         Bibliographic record [% message.biblionumber | html %] does not exist in the database.
50     [% ELSIF message.code == 'authority_not_exists' %]
51         Authority record [% message.authid | html %] does not exist in the database.
52     [% END %]
53
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       <div id="batch_del_form" class="toptabs" style="clear:both">
70         <ul>
71           <li><a href="#uploadfile_tab">Upload a file</a></li>
72           [% IF lists.count %]<li id="show_list_option"><a href="#shelves_tab">Select a list of records</a></li>[% END %]
73           <li><a href="#enterlist_tab">Enter a list of record numbers</a></li>
74         </ul>
75
76         <div id="uploadfile_tab">
77           <fieldset class="rows">
78             <legend>Use a file</legend>
79             <ol>
80               <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
81             </ol>
82           </fieldset>
83           &nbsp;
84         </div>
85
86         [% IF lists.count %]
87             <div id="shelves_tab">
88               <fieldset class="rows">
89                 <legend>Or select a list of records</legend>
90                 <ol>
91                   <li>
92                     <label for="shelf_number">Use records from the following list: </label>
93                     <select name="shelf_number" id="shelf_number">
94                       <option value="">Select a list</option>
95                         [% FOREACH list IN lists %]
96                           <option value="[% list.shelfnumber | html %]">[% list.shelfname | html %]</option>
97                         [% END %]
98                       </option>
99                     </select>
100                   </li>
101                 </ol>
102               </fieldset>
103               &nbsp;
104             </div>
105         [% END %]
106
107         <div id="enterlist_tab">
108           <fieldset class="rows">
109             <legend>Or enter a list of record numbers</legend>
110             <ol>
111               <li>
112                 <label for="recordnumber_list">List of biblionumbers or authority ids (one per line): </label>
113                 <textarea rows="10" cols="30" id="recordnumber_list" name="recordnumber_list"></textarea>
114               </li>
115             </ol>
116           </fieldset>
117           &nbsp;
118         </div>
119
120       </div>
121
122       <fieldset class="action">
123         <input type="hidden" name="op" value="list" />
124         <input type="submit" value="Continue" class="button" />
125         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
126       </fieldset>
127     </form>
128   [% ELSIF op == 'list' %]
129     [% IF records %]
130       [% IF recordtype == 'biblio' %]
131         <div id="toolbar">
132           <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
133           | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
134           | <a id="selectwithoutitems" href="#">Select without items</a>
135           | <a id="selectnotreserved" href="#">Select without holds</a>
136           | <a id="selectwithoutsubscriptions" href="#">Select without subscriptions</a>
137         </div>
138         <form action="/cgi-bin/koha/tools/batch_delete_records.pl" method="post" id="selectrecords">
139           <table id="biblios" class="records">
140             <thead>
141               <tr>
142                 <th></th>
143                 <th>Biblionumber</th>
144                 <th>Title</th>
145                 <th>Items</th>
146                 <th>Holds</th>
147                 <th>Checkouts</th>
148                 <th>Subscriptions</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 %]" data-subscriptions="[% biblio.subscriptions_count | html %]" /></td>
155                   <td><label for="record_id_[% biblio.biblionumber | html %]">[% biblio.biblionumber | html %]</label></td>
156                   <td>[% INCLUDE 'biblio-title.inc' link = 1 %]</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                   <td><a href="/cgi-bin/koha/serials/serials-search.pl?searched=1&biblionumber=[% biblio.biblionumber | uri %]">[% biblio.subscriptions_count | html %]</a></td>
161                 </tr>
162               [% END %]
163             </tbody>
164           </table>
165           <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>
166       [% ELSE %]
167         <div id="toolbar">
168           <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
169           | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
170           | <a id="clearlinkedtobiblio" href="#">Clear used authorities</a>
171         </div>
172         <form action="/cgi-bin/koha/tools/batch_delete_records.pl" method="post" id="selectauths">
173           <table id="authorities" class="records">
174             <thead>
175               <tr>
176                 <th></th>
177                 <th>Authid</th>
178                 <th>Summary</th>
179                 <th>Used in</th>
180               </tr>
181             </thead>
182             <tbody>
183               [% FOR authority IN records %]
184                 <tr>
185                   <td><input type="checkbox" name="record_id" value="[% authority.authid | html %]" data-usage="[% authority.count_usage | html %]" /></td>
186                   <td><a href="/cgi-bin/koha/authorities/detail.pl?authid=[% authority.authid | uri %]">[% authority.authid | html %]</a></td>
187                   <td>[% PROCESS authresult summary=authority.summary authid=authority.authid %]</td>
188                   <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>
189                 </tr>
190               [% END %]
191             </tbody>
192           </table>
193           <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will delete all selected authorities!</div>
194       [% END %]
195         <fieldset class="action">
196           <input type="hidden" name="op" value="delete" />
197           <input type="hidden" name="recordtype" value="[% recordtype | html %]" />
198           <input type="submit" value="Delete selected records" class="button" />
199           <a class="cancel" href="/cgi-bin/koha/tools/batch_delete_records.pl">Cancel</a>
200         </fieldset>
201       </form>
202     [% ELSE %]
203       There are no record ids defined.
204     [% END %]
205   [% ELSIF op == 'enqueued' %]
206     <div class="dialog message">
207       <p>The job has been enqueued! It will be processed as soon as possible.</p>
208       <p><a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a>
209       | <a href="/cgi-bin/koha/tools/batch_delete_records.pl" title="New batch record deletion">New batch record deletion</a></p>
210     </div>
211   [% ELSE %]
212     No action defined for the template.
213   [% END %]
214
215             </main>
216         </div> <!-- /.col-sm-10.col-sm-push-2 -->
217
218         <div class="col-sm-2 col-sm-pull-10">
219             <aside>
220                 [% INCLUDE 'tools-menu.inc' %]
221             </aside>
222         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
223      </div> <!-- /.row -->
224
225 [% MACRO jsinclude BLOCK %]
226     [% Asset.js("js/tools-menu.js") | $raw %]
227     [% INCLUDE 'datatables.inc' %]
228     <script>
229         var MSG_CANNOT_BE_DELETED = _("This record cannot be deleted, at least one item is currently checked out.");
230         $(document).ready(function() {
231
232           $("#batch_del_form").tabs();
233
234           $("input[type='radio']").click(function(){
235             if ($(this).attr('id') == 'authority_type') {
236               $("#show_list_option").hide();
237             } else if ($(this).attr('id') == 'biblio_type') {
238               $("#show_list_option").show();
239             }
240           });
241             $("#selectall").click(function(e){
242                 e.preventDefault();
243                 $(".records input[type='checkbox']:not(:disabled)").each(function(){
244                     $(this).prop("checked", true);
245                 });
246             });
247
248             $("#clearall").click(function(e){
249                 e.preventDefault();
250                 $(".records input[type='checkbox']:not(:disabled)").each(function(){
251                     $(this).prop("checked", false);
252                 });
253             });
254
255             $("#selectwithoutitems").click(function(e){
256                 e.preventDefault();
257                 $(".records input[type='checkbox']:not(:disabled)").each(function(){
258                     if( $(this).data("items") == 0 ){
259                         $(this).prop("checked", true );
260                     } else {
261                         $(this).prop("checked", false );
262                     }
263                 });
264             });
265
266             $("#selectnotreserved").click(function(e){
267                 e.preventDefault();
268                 $(".records input[type='checkbox']:not(:disabled)").each(function(){
269                     if( $(this).data("reserves") == 0 ){
270                         $(this).prop("checked", true );
271                     } else {
272                         $(this).prop("checked", false );
273                     }
274                 });
275             });
276
277             $("#selectwithoutsubscriptions").click(function(e){
278                 e.preventDefault();
279                 $(".records input[type='checkbox']:not(:disabled)").each(function(){
280                     if( $(this).data("subscriptions") == 0 ){
281                         $(this).prop("checked", true );
282                     } else {
283                         $(this).prop("checked", false );
284                     }
285                 });
286             });
287
288             $("#clearlinkedtobiblio").click(function(e){
289                 e.preventDefault();
290                 $(".records input[type='checkbox']:not(:disabled)").each(function(){
291                     if( $(this).data("usage") == 0 ){
292                         $(this).prop("checked", true );
293                     } else {
294                         $(this).prop("checked", false );
295                     }
296                 });
297             });
298
299           $("#selectall").click();
300
301           [% IF recordtype == 'biblio' %]
302             $(".records input:checkbox[data-issues!='0']").each(function(){
303               $(this).attr('title', MSG_CANNOT_BE_DELETED)
304               $(this).prop('disabled', true);
305               $(this).prop('checked', false);
306               $(this).parents('tr').find('td').css('background-color', '#ffff99');
307             });
308           [% END %]
309
310           $("table#biblios").dataTable($.extend(true, {}, dataTablesDefaults, {
311             "aoColumnDefs": [
312               { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
313               { "aTargets": [ 3, 4 ], "sType": "num-html" }
314             ],
315             "sDom": 't',
316             "aaSorting": [],
317             "bPaginate": false
318           }));
319
320           $("table#authorities").dataTable($.extend(true, {}, dataTablesDefaults, {
321             "aoColumnDefs": [
322               { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
323               { "aTargets": [ 3 ], "sType": "num-html" }
324             ],
325             "sDom": 't',
326             "aaSorting": [],
327             "bPaginate": false
328           }));
329
330           $("#selectrecords").on("submit",function(){
331             var nb_checked = $("#selectrecords").find("input[type='checkbox'][name='record_id']:checked").size();
332             if (nb_checked == 0){
333               alert(_("No records have been selected."));
334               return false;
335             }
336           });
337
338           $("#selectauths").on("submit",function(){
339             var checked = $("#selectauths").find("input[type='checkbox'][name='record_id']:checked").size();
340             if (checked == 0) {
341               alert(_("No authorities have been selected."));
342               return false;
343             }
344           });
345
346           $("#record_ids_selection").on("submit", function(e){
347             var tab = $(this).find('.ui-tabs-active:first a').attr('href');
348             if ( tab == '#uploadfile_tab' ) {
349                 $("#shelf_number").empty('');
350                 $("#recordnumber_list").val('');
351             } else if ( tab == '#shelves_tab' ) {
352                 $("#uploadfile").val('')
353                 $("#recordnumber_list").val('');
354             } else { // enterlist
355                 $("#uploadfile").val('')
356                 $("#shelf_number").empty('');
357             }
358           });
359
360         });
361     </script>
362 [% END %]
363
364 [% INCLUDE 'intranet-bottom.inc' %]