Bug 22417: Handle errors
[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                                 [% ELSIF message.code == 'cannot_enqueue_job' %]
50                                     Cannot enqueue this job.
51                                 [% END %]
52                                 [% IF message.error %]
53                                     (The error was: [% message.error | html %]. See the Koha logfile for more information).
54                                 [% END %]
55                                 </div>
56                             [% END %]
57
58                         </div> <!-- /.dialog.message -->
59                     [% END %]
60
61                     [% IF view == 'form' %]
62                         <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batch_record_modification.pl" id="record_ids_selection">
63                             <fieldset class="rows">
64                                 <legend>Record type</legend>
65                                 <ol>
66                                     <li><label for="biblio_type">Biblios: </label><input type="radio" name="recordtype" value="biblio" id="biblio_type" checked="checked" /></li>
67                                     <li><label for="authority_type">Authorities: </label><input type="radio" name="recordtype" value="authority" id="authority_type" /></li>
68                                 </ol>
69                             </fieldset>
70
71                             <br><br>
72
73                             <div id="batch_mod_form" class="toptabs" style="clear:both">
74                                 <ul>
75                                     <li><a href="#uploadfile_tab">Upload a file</a></li>
76                                         [% IF lists.count %]<li id="show_list_option"><a href="#shelves_tab">Select a list of records</a></li>[% END %]
77                                     <li><a href="#enterlist_tab">Enter a list of record numbers</a></li>
78                                 </ul>
79
80                                 <div id="uploadfile_tab">
81                                     <fieldset class="rows">
82                                         <legend>Use a file</legend>
83                                         <ol>
84                                             <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
85                                         </ol>
86                                     </fieldset>
87                                     &nbsp;
88                                 </div>
89
90                                 [% IF lists.count %]
91                                     <div id="shelves_tab">
92                                         <fieldset class="rows">
93                                             <legend>Or select a list of records</legend>
94                                             <ol>
95                                                 <li>
96                                                     <label for="shelf_number">Use records from the following list: </label>
97                                                     <select name="shelf_number" id="shelf_number">
98                                                         <option value="">Select a list</option>
99                                                         [% FOREACH list IN lists %]
100                                                         <option value="[% list.shelfnumber | html %]">[% list.shelfname | html %]</option>
101                                                         [% END %]
102                                                         </option>
103                                                     </select>
104                                                 </li>
105                                             </ol>
106                                         </fieldset>
107                                         &nbsp;
108                                     </div>
109                                 [% END %]
110
111                                 <div id="enterlist_tab">
112                                     <fieldset class="rows">
113                                         <legend>Or enter a list of record numbers</legend>
114                                         <ol>
115                                             <li>
116                                                 <label for="recordnumber_list">List of biblionumbers or authority ids (one per line): </label>
117                                                 <textarea rows="10" cols="30" id="recordnumber_list" name="recordnumber_list"></textarea>
118                                             </li>
119                                         </ol>
120                                     </fieldset>
121                                     &nbsp;
122                                 </div>
123
124                             </div> <!-- /#batch_mod_form -->
125
126                             <fieldset class="rows">
127                                 <legend>Use MARC Modification Template:</legend>
128                                 <ol>
129                                     <li>
130                                         <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
131                                         <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
132                                             <option value="">Select a template</option>
133                                             [% FOREACH mmt IN MarcModificationTemplatesLoop %]
134                                             <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
135                                             [% END %]
136                                         </select>
137                                     </li>
138                                 </ol>
139                             </fieldset>
140                             <fieldset class="action">
141                                 <input type="hidden" name="op" value="list" />
142                                 <input type="submit" value="Continue" class="button" />
143                                 <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
144                             </fieldset>
145                         </form> <!-- /#record_ids_selection -->
146                     [% ELSIF view == 'list' %]
147                         [% IF records %]
148                             <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post">
149                                 <label for="marc_modification_template_id" class="required">Modify record using the following template: </label>
150                                 <select name="marc_modification_template_id" id="marc_modification_template_id" required="required">
151                                     <option value="">Select a template</option>
152                                     [% FOREACH mmt IN MarcModificationTemplatesLoop %]
153                                         [% IF mmt.selected %]
154                                             <option value="[% mmt.template_id | html %]" selected="selected">[% mmt.name | html %]</option>
155                                         [% ELSE %]
156                                             <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
157                                         [% END %]
158                                     [% END %]
159                                 </select>
160                                 <div id="marcPreview" class="modal" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
161                                     <div class="modal-dialog">
162                                         <div class="modal-content">
163                                             <div class="modal-header">
164                                                 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
165                                                 <h3 id="marcPreviewLabel">MARC preview</h3>
166                                             </div>
167                                             <div class="modal-body">
168                                                 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
169                                             </div>
170                                             <div class="modal-footer">
171                                                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
172                                             </div>
173                                         </div>
174                                     </div>
175                                 </div>
176                                 [% IF recordtype == 'biblio' %]
177                                     <div id="toolbar">
178                                         <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
179                                         | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
180                                     </div>
181                                     <table id="biblios" class="records">
182                                         <thead>
183                                             <tr>
184                                                 <th>&nbsp;</th>
185                                                 <th>Biblionumber</th>
186                                                 <th>Title</th>
187                                                 <th>&nbsp;</th>
188                                             </tr>
189                                         </thead>
190                                         <tbody>
191                                             [% FOR biblio IN records %]
192                                                 <tr>
193                                                     <td><input type="checkbox" name="record_id" value="[% biblio.biblionumber | html %]" /></td>
194                                                     <td>[% biblio.biblionumber | html %]</td>
195                                                     <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]">[% biblio.title | html %]</a></td>
196                                                     <td class="actions">
197                                                         <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>
198                                                     </td>
199                                                 </tr>
200                                             [% END %]
201                                         </tbody>
202                                     </table> <!-- /#biblios -->
203                                     <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected biblios!</div>
204                                 [% ELSE %]
205                                     <div id="toolbar">
206                                         <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a>
207                                         | <a id="clearall" href="#"><i class="fa fa-remove"></i> Clear all</a>
208                                     </div>
209                                     <table id="authorities" class="records">
210                                         <thead>
211                                             <tr>
212                                                 <th></th>
213                                                 <th>Authid</th>
214                                                 <th>Summary</th>
215                                                 <th>&nbsp;</th>
216                                             </tr>
217                                         </thead>
218                                         <tbody>
219                                             [% FOR authority IN records %]
220                                                 <tr>
221                                                     <td><input type="checkbox" name="record_id" value="[% authority.authid | html %]" data-usage="[% authority.count_usage | html %]" /></td>
222                                                     <td><a href="/cgi-bin/koha/authorities/detail.pl?authid=[% authority.authid | uri %]">[% authority.authid | html %]</a></td>
223                                                     <td>[% PROCESS authresult summary=authority.summary %]</td>
224                                                     <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>
225                                                 </tr>
226                                             [% END %]
227                                         </tbody>
228                                     </table> <!-- /#authorities -->
229                                     <div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will modify all selected authorities!</div>
230                                 [% END %]
231                                 <fieldset class="action">
232                                     <input type="hidden" name="op" value="modify" />
233                                     <input type="hidden" name="recordtype" value="[% recordtype | html %]" />
234                                     <input type="submit" id="mainformsubmit" value="Modify selected records" class="button" />
235                                 </fieldset>
236                             </form> <!-- /#process -->
237                         [% ELSE %]
238                             <div class="dialog message">
239                                 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 %]
240                             </div>
241                         [% END %]
242                     [% ELSIF view == 'errors' %]
243                         [% FOR error IN errors %]
244                             [% IF error == 'no_template_defined' %]
245                                 <div class="dialog alert">
246                                     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.
247                                 </div>
248                             [% END %]
249                         [% END %]
250                      [% ELSIF view == 'enqueued' %]
251                         <div class="dialog message">
252                             The job has been enqueued! It will be processed as soon as possible (FIXME - well, it could depend on a config?)
253                             <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>
254                             | <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
255                         </div>
256                     [% ELSE %]
257                         <div class="dialog alert">
258                             No action defined for the template.
259                         </div>
260                     [% END %]
261                 </main>
262             </div> <!-- /.col-sm-10.col-sm-push-2 -->
263             <div class="col-sm-2 col-sm-pull-10">
264                 <aside>
265                     [% INCLUDE 'tools-menu.inc' %]
266                 </aside>
267             </div> <!-- /.col-sm-2.col-sm-pull-10 -->
268         </div> <!-- /.row -->
269
270 [% MACRO jsinclude BLOCK %]
271     [% Asset.js("js/tools-menu.js") | $raw %]
272     [% INCLUDE 'datatables.inc' %]
273     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
274     [% Asset.js("js/background-job-progressbar.js") | $raw %]
275     <script>
276         $(document).ready(function() {
277
278             $("#batch_mod_form").tabs();
279
280             $("input[type='radio']").click(function() {
281                 if ($(this).attr('id') == 'authority_type') {
282                     $("#show_list_option").hide();
283                 } else if ($(this).attr('id') == 'biblio_type') {
284                     $("#show_list_option").show();
285                 }
286             });
287
288             $("#selectall").click(function(e){
289                 e.preventDefault();
290                 $(".records input[type='checkbox']").each(function(){
291                     $(this).prop("checked", true);
292                 });
293             });
294
295             $("#clearall").click(function(e){
296                 e.preventDefault();
297                 $(".records input[type='checkbox']").each(function(){
298                     $(this).prop("checked", false);
299                 });
300             });
301
302             $("#selectall").click();
303
304             $("table#biblios").dataTable($.extend(true, {}, dataTablesDefaults, {
305                 "aoColumnDefs": [
306                     { "aTargets": [0, 3], "bSortable": false, "bSearchable": false },
307                     { "aTargets": [1], "sType": "num-html" }
308                 ],
309                 "sDom": 't',
310                 "aaSorting": [],
311                 "bPaginate": false
312             }));
313
314             $("table#authorities").dataTable($.extend(true, {}, dataTablesDefaults, {
315                 "aoColumnDefs": [
316                     { "aTargets": [0, 3], "bSortable": false, "bSearchable": false },
317                     { "aTargets": [1], "sType": "num-html" }
318                 ],
319                 "sDom": 't',
320                 "aaSorting": [],
321                 "bPaginate": false
322             }));
323
324             $("#mainformsubmit").click(function() {
325                 if ($("input[type=checkbox][name='record_id']:checked").length == 0) {
326                     alert(_("Please select at least one record to process"));
327                     return false;
328                 }
329                 if ($("#marc_modification_template_id").val() <= 0) {
330                     alert(_("Please select a modification template."));
331                     return false;
332                 }
333                 return true;
334             });
335
336             $("#record_ids_selection").on("submit", function(e) {
337                 var tab = $(this).find('.ui-tabs-active:first a').attr('href');
338                 if (tab == '#uploadfile_tab') {
339                     $("#shelf_number").empty('');
340                     $("#recordnumber_list").val('');
341                 } else if (tab == '#shelves_tab') {
342                     $("#uploadfile").val('')
343                     $("#recordnumber_list").val('');
344                 } else { // enterlist
345                     $("#uploadfile").val('')
346                     $("#shelf_number").empty('');
347                 }
348             });
349
350             $("#marc_modification_template_id").change(function() {
351                 var url = "/cgi-bin/koha/svc/records/preview?"
352                 var mmtid = $(this).val();
353                 $("a.previewMARC").each(function() {
354                     $(this).attr("href", url + "record_type=" + $(this).attr("data-record_type") + "&record_id=" + $(this).attr("data-record_id") + "&mmtid=" + mmtid);
355                 });
356             });
357
358             $("body").on("click", ".previewMARC", function(e) {
359                 e.preventDefault();
360                 var ltitle = $(this).text();
361                 var page = $(this).attr("href");
362                 $("#marcPreviewLabel").text(ltitle);
363                 $("#marcPreview .modal-body").load(page + " div");
364                 $('#marcPreview').modal({ show: true });
365             });
366             $("#marcPreview").on("hidden.bs.modal", function() {
367                 $("#marcPreviewLabel").html("");
368                 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
369             });
370
371             $("#add_bibs_to_list").change(function(){
372                 var selected = $("#add_bibs_to_list").find("option:selected");
373                 if ( selected.attr("class") == "shelf" ){
374                     var shelfnumber = selected.attr("value");
375                     var bibs = new Array();
376                     [% FOREACH message IN messages %]
377                         [% IF message.code == 'biblio_modified' %]
378                             bibs.push("biblionumber="+[% message.biblionumber | html %]);
379                         [% END %]
380                     [% END %]
381                     var bibstring = bibs.join("&");
382                     window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&'+bibstring, 'popup', 'width=500,height=500,toolbar=false,scrollbars=yes,resizeable=yes');
383                     return false;
384                 }
385             });
386
387         });
388     </script>
389 [% END %]
390
391 [% INCLUDE 'intranet-bottom.inc' %]