Bug 22417: Adapt the batch_record_modification tool
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / batch_record_modification.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 modification</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 [% Asset.css("css/humanmsg.css") | $raw %]
9 </head>
10
11 <body id="tools_batch_record_modification" 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_record_modification.pl">Batch record modification</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 modification</h1>
27
28                     [% IF ( messages ) %]
29                         <div class="dialog message">
30
31                             [% FOREACH message IN messages %]
32                                 [% IF message.type == 'success' %]
33                                     <div><i class="fa fa-check success"></i>
34                                 [% ELSIF message.type == 'warning' %]
35                                     <div><i class="fa fa-warning warn"></i>
36                                 [% ELSIF message.type == 'error' %]
37                                     <div><i class="fa fa-exclamation error"></i>
38                                 [% END %]
39                                 [% IF message.code == 'no_action_defined_for_the_template' %]
40                                     The selected template (id=[% message.mmtid | html %]) does not exist or no action is defined.
41                                 [% ELSIF message.code == 'biblio_not_exists' %]
42                                     Bibliographic record [% message.biblionumber | html %] does not exist in the database.
43                                 [% ELSIF message.code == 'authority_not_exists' %]
44                                     Authority record [% message.authid | html %] does not exist in the database.
45                                 [% ELSIF message.code == 'authority_not_modified' %]
46                                     Authority record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has not been modified. An error occurred on modifying it.
47                                 [% ELSIF message.code == 'authority_modified' %]
48                                     Bibliographic record <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% message.authid | uri %]">[% message.authid | html %]</a> has successfully been modified.
49                                 [% END %]
50                                 [% IF message.error %]
51                                     (The error was: [% message.error | html %]. See the Koha logfile for more information).
52                                 [% END %]
53                                 </div>
54                             [% END %]
55
56                         </div> <!-- /.dialog.message -->
57                     [% END %]
58
59                     [% IF view == 'form' %]
60                         <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batch_record_modification.pl" id="record_ids_selection">
61                             <fieldset class="rows">
62                                 <legend>Record type</legend>
63                                 <ol>
64                                     <li><label for="biblio_type">Biblios: </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_mod_form" class="toptabs" style="clear:both">
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 | html %]">[% list.shelfname | html %]</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> <!-- /#batch_mod_form -->
123
124                             <fieldset class="rows">
125                                 <legend>Use MARC Modification Template:</legend>
126                                 <ol>
127                                     <li>
128                                         <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
129                                         <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
130                                             <option value="">Select a template</option>
131                                             [% FOREACH mmt IN MarcModificationTemplatesLoop %]
132                                             <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
133                                             [% END %]
134                                         </select>
135                                     </li>
136                                 </ol>
137                             </fieldset>
138                             <fieldset class="action">
139                                 <input type="hidden" name="op" value="list" />
140                                 <input type="submit" value="Continue" class="button" />
141                                 <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
142                             </fieldset>
143                         </form> <!-- /#record_ids_selection -->
144                     [% ELSIF view == 'list' %]
145                         [% IF records %]
146                             <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post">
147                                 <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
148                                 <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
149                                     <option value="">Select a template</option>
150                                     [% FOREACH mmt IN MarcModificationTemplatesLoop %]
151                                         [% IF mmt.selected %]
152                                             <option value="[% mmt.template_id | html %]" selected="selected">[% mmt.name | html %]</option>
153                                         [% ELSE %]
154                                             <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
155                                         [% END %]
156                                     [% END %]
157                                 </select>
158                                 <div id="marcPreview" class="modal" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
159                                     <div class="modal-dialog">
160                                         <div class="modal-content">
161                                             <div class="modal-header">
162                                                 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
163                                                 <h3 id="marcPreviewLabel">MARC preview</h3>
164                                             </div>
165                                             <div class="modal-body">
166                                                 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
167                                             </div>
168                                             <div class="modal-footer">
169                                                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
170                                             </div>
171                                         </div>
172                                     </div>
173                                 </div>
174                                 [% IF recordtype == 'biblio' %]
175                                     <div id="toolbar">
176                                         <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
177                                         | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
178                                     </div>
179                                     <table id="biblios" class="records">
180                                         <thead>
181                                             <tr>
182                                                 <th>&nbsp;</th>
183                                                 <th>Biblionumber</th>
184                                                 <th>Title</th>
185                                                 <th>&nbsp;</th>
186                                             </tr>
187                                         </thead>
188                                         <tbody>
189                                             [% FOR biblio IN records %]
190                                                 <tr>
191                                                     <td><input type="checkbox" name="record_id" value="[% biblio.biblionumber | html %]" /></td>
192                                                     <td>[% biblio.biblionumber | html %]</td>
193                                                     <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]">[% biblio.title | html %]</a></td>
194                                                     <td class="actions">
195                                                         <a href="/cgi-bin/koha/svc/records/preview?record_type=biblio&record_id=[% biblio.biblionumber | uri %]&mmtid=[% mmtid | uri %]" class="previewMARC btn btn-default btn-xs" data-record_type="biblio" data-record_id="[% biblio.biblionumber | html %]" data-mmtid="[% mmtid | html %]" title="Preview MARC"><i class="fa fa-eye"></i> Show MARC</a>
196                                                     </td>
197                                                 </tr>
198                                             [% END %]
199                                         </tbody>
200                                     </table> <!-- /#biblios -->
201                                     <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected biblios!</div>
202                                 [% ELSE %]
203                                     <div id="toolbar">
204                                         <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
205                                         | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
206                                     </div>
207                                     <table id="authorities" class="records">
208                                         <thead>
209                                             <tr>
210                                                 <th></th>
211                                                 <th>Authid</th>
212                                                 <th>Summary</th>
213                                                 <th>&nbsp;</th>
214                                             </tr>
215                                         </thead>
216                                         <tbody>
217                                             [% FOR authority IN records %]
218                                                 <tr>
219                                                     <td><input type="checkbox" name="record_id" value="[% authority.authid | html %]" data-usage="[% authority.count_usage | html %]" /></td>
220                                                     <td><a href="/cgi-bin/koha/authorities/detail.pl?authid=[% authority.authid | uri %]">[% authority.authid | html %]</a></td>
221                                                     <td>[% PROCESS authresult summary=authority.summary %]</td>
222                                                     <td class="actions"><a href="/cgi-bin/koha/svc/records/preview?record_type=authority&record_id=[% authority.authid | uri %]&mmtid=[% mmtid | uri %]" data-record_type="authority" data-record_id="[% authority.authid | html %]" data-mmtid="[% mmtid | html %]" class="previewMARC btn btn-default btn-xs"><i class='fa fa-eye'></i> Show MARC</a>
223                                                 </tr>
224                                             [% END %]
225                                         </tbody>
226                                     </table> <!-- /#authorities -->
227                                     <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected authorities!</div>
228                                 [% END %]
229                                 <fieldset class="action">
230                                     <input type="hidden" name="op" value="modify" />
231                                     <input type="hidden" name="recordtype" value="[% recordtype | html %]" />
232                                     <input type="submit" id="mainformsubmit" value="Modify selected records" class="button" />
233                                 </fieldset>
234                             </form> <!-- /#process -->
235                         [% ELSE %]
236                             <div class="dialog message">
237                                 No records were modified. [% IF recordtype != 'biblio' %]<a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>[% END %]
238                             </div>
239                         [% END %]
240                     [% ELSIF view == 'errors' %]
241                         [% FOR error IN errors %]
242                             [% IF error == 'no_template_defined' %]
243                                 <div class="dialog alert">
244                                     No MARC modification template is defined. You have <a href="/cgi-bin/koha/tools/marc_modification_templates.pl">to create</a> at least one template for using this tool.
245                                 </div>
246                             [% END %]
247                         [% END %]
248                      [% ELSIF view == 'enqueued' %]
249                         <div class="dialog message">
250                             The job has been enqueued! It will be processed as soon as possible (FIXME - well, it could depend on a config?)
251                             <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>
252                             | <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
253                         </div>
254                     [% ELSE %]
255                         <div class="dialog alert">
256                             No action defined for the template.
257                         </div>
258                     [% END %]
259                 </main>
260             </div> <!-- /.col-sm-10.col-sm-push-2 -->
261             <div class="col-sm-2 col-sm-pull-10">
262                 <aside>
263                     [% INCLUDE 'tools-menu.inc' %]
264                 </aside>
265             </div> <!-- /.col-sm-2.col-sm-pull-10 -->
266         </div> <!-- /.row -->
267
268 [% MACRO jsinclude BLOCK %]
269     [% Asset.js("js/tools-menu.js") | $raw %]
270     [% INCLUDE 'datatables.inc' %]
271     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
272     [% Asset.js("js/background-job-progressbar.js") | $raw %]
273     <script>
274         $(document).ready(function() {
275
276             $("#batch_mod_form").tabs();
277
278             $("input[type='radio']").click(function() {
279                 if ($(this).attr('id') == 'authority_type') {
280                     $("#show_list_option").hide();
281                 } else if ($(this).attr('id') == 'biblio_type') {
282                     $("#show_list_option").show();
283                 }
284             });
285
286             $("#selectall").click(function(e){
287                 e.preventDefault();
288                 $(".records input[type='checkbox']").each(function(){
289                     $(this).prop("checked", true);
290                 });
291             });
292
293             $("#clearall").click(function(e){
294                 e.preventDefault();
295                 $(".records input[type='checkbox']").each(function(){
296                     $(this).prop("checked", false);
297                 });
298             });
299
300             $("#selectall").click();
301
302             $("table#biblios").dataTable($.extend(true, {}, dataTablesDefaults, {
303                 "aoColumnDefs": [
304                     { "aTargets": [0, 3], "bSortable": false, "bSearchable": false },
305                     { "aTargets": [1], "sType": "num-html" }
306                 ],
307                 "sDom": 't',
308                 "aaSorting": [],
309                 "bPaginate": false
310             }));
311
312             $("table#authorities").dataTable($.extend(true, {}, dataTablesDefaults, {
313                 "aoColumnDefs": [
314                     { "aTargets": [0, 3], "bSortable": false, "bSearchable": false },
315                     { "aTargets": [1], "sType": "num-html" }
316                 ],
317                 "sDom": 't',
318                 "aaSorting": [],
319                 "bPaginate": false
320             }));
321
322             $("#mainformsubmit").click(function() {
323                 if ($("input[type=checkbox][name='record_id']:checked").length == 0) {
324                     alert(_("Please select at least one record to process"));
325                     return false;
326                 }
327                 if ($("#marc_modification_template_id").val() <= 0) {
328                     alert(_("Please select a modification template."));
329                     return false;
330                 }
331                 return true;
332             });
333
334             $("#record_ids_selection").on("submit", function(e) {
335                 var tab = $(this).find('.ui-tabs-active:first a').attr('href');
336                 if (tab == '#uploadfile_tab') {
337                     $("#shelf_number").empty('');
338                     $("#recordnumber_list").val('');
339                 } else if (tab == '#shelves_tab') {
340                     $("#uploadfile").val('')
341                     $("#recordnumber_list").val('');
342                 } else { // enterlist
343                     $("#uploadfile").val('')
344                     $("#shelf_number").empty('');
345                 }
346             });
347
348             $("#marc_modification_template_id").change(function() {
349                 var url = "/cgi-bin/koha/svc/records/preview?"
350                 var mmtid = $(this).val();
351                 $("a.previewMARC").each(function() {
352                     $(this).attr("href", url + "record_type=" + $(this).attr("data-record_type") + "&record_id=" + $(this).attr("data-record_id") + "&mmtid=" + mmtid);
353                 });
354             });
355
356             $("body").on("click", ".previewMARC", function(e) {
357                 e.preventDefault();
358                 var ltitle = $(this).text();
359                 var page = $(this).attr("href");
360                 $("#marcPreviewLabel").text(ltitle);
361                 $("#marcPreview .modal-body").load(page + " div");
362                 $('#marcPreview').modal({ show: true });
363             });
364             $("#marcPreview").on("hidden.bs.modal", function() {
365                 $("#marcPreviewLabel").html("");
366                 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
367             });
368
369             $("#add_bibs_to_list").change(function(){
370                 var selected = $("#add_bibs_to_list").find("option:selected");
371                 if ( selected.attr("class") == "shelf" ){
372                     var shelfnumber = selected.attr("value");
373                     var bibs = new Array();
374                     [% FOREACH message IN messages %]
375                         [% IF message.code == 'biblio_modified' %]
376                             bibs.push("biblionumber="+[% message.biblionumber | html %]);
377                         [% END %]
378                     [% END %]
379                     var bibstring = bibs.join("&");
380                     window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&'+bibstring, 'popup', 'width=500,height=500,toolbar=false,scrollbars=yes,resizeable=yes');
381                     return false;
382                 }
383             });
384
385         });
386     </script>
387 [% END %]
388
389 [% INCLUDE 'intranet-bottom.inc' %]