Bug 22785: Allow option to choose which record match is applied during import
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / manage-marc-import.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE KohaDates %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>
7     [% IF ( import_batch_id ) %]
8         Batch [% import_batch_id | html %] &rsaquo; [% END %]
9     Manage staged MARC records &rsaquo; Tools &rsaquo; Koha
10 </title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 [% Asset.css("css/humanmsg.css") | $raw %]
13 <style>
14     #jobpanel,#jobstatus,#jobfailed { display : none; }
15     span.change-status { font-style:italic; color:#666; display:none; }
16     ul.matches li { list-style-type:none; }
17 </style>
18 </head>
19
20 <body id="tools_manage-marc-import" class="tools">
21     [% INCLUDE 'header.inc' %]
22     [% INCLUDE 'cat-search.inc' %]
23
24     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
25         <ol>
26             <li>
27                 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
28             </li>
29             <li>
30                 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
31             </li>
32             [% IF ( import_batch_id ) %]
33                 <li>
34                     <a href="[% script_name | url %]">Manage staged MARC records</a>
35                 </li>
36                 <li>
37                     <a href="#" aria-current="page">
38                         Batch [% import_batch_id | html %]
39                     </a>
40                 </li>
41             [% ELSE %]
42                 <li>
43                     <a href="#" aria-current="page">
44                         Manage staged MARC records
45                     </a>
46                 </li>
47             [% END %]
48         </ol>
49     </nav>
50
51     <div class="main container-fluid">
52         <div class="row">
53             <div class="col-sm-10 col-sm-push-2">
54                 <main>
55                     <h1>Manage staged MARC records
56                         [% IF ( import_batch_id ) %]
57                             &rsaquo; Batch [% import_batch_id | html %]
58                         [% END %]
59                     </h1>
60
61                     [% IF ( label_batch_msg ) %]
62                         [% IF ( alert ) %]
63                             <div class="alert">
64                         [% ELSE %]
65                             <div class="dialog message">
66                         [% END %]
67                             <p><strong>
68                                 [% IF ( label_batch_msg == "error" ) %]
69                                     Error attempting to create label batch. Please ask your system administrator to check the log for more details.
70                                 [% ELSE %]
71                                     Label <a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=edit&element_id=[% label_batch_msg | uri %]" >batch #[% label_batch_msg | html %]</a> created.
72                                 [% END %]
73                             </strong></p>
74                         </div>
75                     [% END %]
76
77                     [% IF ( did_clean ) %]
78                         <div class="dialog message">Cleaned import batch #[% import_batch_id | html %]</div>
79                     [% END %]
80
81                     [% IF ( did_delete ) %]
82                         <div class="dialog message">Import batch deleted successfully</div>
83                     [% END %]
84
85                     [% UNLESS ( batch_list ) %]
86                         [% UNLESS ( batch_info ) %]
87                             <div class="dialog message">
88                                 <p>No records have been staged.</p>
89                                 <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
90                             </div>
91                         [% END %]
92                     [% END %]
93
94                     [% IF ( batch_info ) %]
95                         [% IF ( can_commit ) %]
96                             <form action="[% script_name | html %]" method="post">
97                                 <input type="hidden" name="op" value="redo-matching" />
98                                 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
99                                 <input type="hidden" name="current_matcher_id" value="[% current_matcher_id | html %]" />
100                         [% END %]
101
102                         [% IF ( rematch_attempted ) %]
103                             [% IF ( rematch_failed ) %]
104                                 <div class="dialog alert">Failed to apply different matching rule</div>
105                             [% ELSE %]
106                                 <div class="dialog message">Applied different matching rule. Number of records matched now
107                                     [% num_with_matches | html %]
108                                 </div>
109                             [% END %]
110                         [% END %]
111
112                         [% IF ( changed_overlay_action ) %]
113                             <div class="dialog message">Changed action if matching record found</div>
114                         [% END %]
115
116                         [% IF ( changed_nomatch_action ) %]
117                             <div class="dialog message">Changed action if no match found</div>
118                         [% END %]
119
120                         [% IF ( changed_item_action ) %]
121                             <div class="dialog message">Changed item processing option</div>
122                         [% END %]
123
124                         <fieldset class="rows" id="staged-record-matching-rules">
125                             <ol>
126                                 <li><span class="label">File name:</span> [% file_name | html %]</li>
127                                 <li><span class="label">Profile:</span> [% IF (profile) %][% profile | html %][% ELSE %](none)[% END %]</li>
128                                 <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments | html %][% ELSE %](none)[% END %]</li>
129                                 <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
130                                 <li><span class="label">Staged:</span> [% upload_timestamp | $KohaDates with_hours=1 %]</li>
131                                 <li><span class="label">Status:</span>
132                                     [% IF ( import_status == 'cleaned' ) %]
133                                         Cleaned
134                                     [% ELSIF ( import_status == 'imported' ) %]
135                                         Imported
136                                     [% ELSIF ( import_status == 'importing' ) %]
137                                         Importing
138                                     [% ELSIF ( import_status == 'reverted' ) %]
139                                         Reverted
140                                     [% ELSIF ( import_status == 'reverting' ) %]
141                                         Reverting
142                                     [% ELSIF ( import_status == 'staged' ) %]
143                                         Staged
144                                     [% ELSE %]
145                                         [% import_status | html %]
146                                     [% END %]
147                                 </li>
148                                 <li>
149                                     [% IF ( can_commit ) %]
150                                         <label for="new_matcher_id">Matching rule applied:</label>
151                                         <select name="new_matcher_id" id="new_matcher_id">
152                                             <option value="">Do not look for matching records</option>
153                                             [% FOREACH available_matcher IN available_matchers %]
154                                                 [% IF ( available_matcher.selected ) %]
155                                                     <option value="[% available_matcher.matcher_id | html %]" selected="selected">
156                                                         [% available_matcher.code | html %] ([% available_matcher.description | html %])
157                                                     </option>
158                                                 [% ELSE %]
159                                                     <option value="[% available_matcher.matcher_id | html %]">
160                                                         [% available_matcher.code | html %] ([% available_matcher.description | html %])
161                                                     </option>
162                                                 [% END %]
163                                             [% END %]
164                                         </select>
165                                         <span class="change-status">Changed. <a href="#" class="reset" id="reset_new_matcher_id">Reset</a></span>
166                                     [% ELSE %]
167                                         <span class="label">Matching rule applied</span>
168                                         [% IF ( current_matcher_id ) %]
169                                             [% current_matcher_code | html %] ([% current_matcher_description | html %])
170                                         [% ELSE %]
171                                             <span>No matching rule in effect</span>
172                                         [% END %]
173                                     [% END %]
174                                 </li>
175                                 <li>
176                                     [% IF ( can_commit ) %]
177                                         <label for="overlay_action">Action if matching record found:</label>
178                                         [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>
179                                     [% ELSE %]
180                                         <span class="label">Action if matching record found:</span>
181                                         [% IF ( overlay_action == 'replace' ) %]
182                                             <span>Replace existing record with incoming record</span>
183                                         [% ELSIF ( overlay_action == 'create_new' ) %]
184                                             <span>Add incoming record</span>
185                                         [% ELSIF ( overlay_action == 'ignore' ) %]
186                                             <span>Ignore incoming record (its items may still be processed)</span>
187                                         [% ELSE %]
188                                             <span>[% overlay_action | html %]</span>
189                                         [% END %]
190                                     [% END %]
191                                 </li>
192                                 <li>
193                                     [% IF ( can_commit ) %]
194                                         <label for="nomatch_action">Action if no match found:</label>
195                                         [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>
196                                     [% ELSE %]
197                                         <span class="label">Action if no match found:</span>
198                                         [% IF ( nomatch_action == 'create_new' ) %]
199                                             Add incoming record
200                                         [% ELSIF ( nomatch_action == 'ignore' ) %]
201                                             Ignore incoming record (its items may still be processed)
202                                         [% ELSE %]
203                                             [% nomatch_action | html %]
204                                         [% END %]
205                                     [% END %]
206                                 </li>
207                                 [% IF ( record_type == 'biblio' ) %]
208                                     <li>
209                                         [% IF ( can_commit ) %]
210                                             <label for="item_action">Item processing:</label>
211                                             [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>
212                                         [% ELSE %]
213                                             <span class="label">Item processing:</span>
214                                             [% IF ( item_action == 'always_add' ) %]
215                                                 <span>Always add items</span>
216                                             [% ELSIF ( item_action == 'add_only_for_matches' ) %]
217                                                 <span>Add items only if matching bib was found</span>
218                                             [% ELSIF ( item_action == 'add_only_for_new' ) %]
219                                                 <span>Add items only if no matching bib was found</span>
220                                             [% ELSIF ( item_action == 'ignore' ) %]
221                                                 <span>Ignore items</span>
222                                             [% ELSE %]
223                                                 <span>[% item_action | html %]</span>
224                                             [% END %]
225                                         [% END %]
226                                     </li>
227                                 [% ELSE %]
228                                     <input type ="hidden" name="item_action" value="ignore">
229                                 [% END %]
230                             </ol>
231                             [% IF ( can_commit ) %]
232                                     <fieldset class="action"><input type="submit" value="Apply different matching rules" class="button" /></fieldset>
233                                 </form>
234                             [% END %]
235                         </fieldset> <!-- /#staged-record-matching-rules -->
236
237                         <div>
238                             [% IF ( can_commit ) %]
239                                 <form action="[% script_name | html %]" method="post" id="import_batch_form">
240                                     <input type="hidden" name="op" value="commit-batch" />
241                                     <input type="hidden" name="runinbackground" value="" />
242                                     <input type="hidden" name="completedJobID" value="" />
243                                     <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
244                                     <fieldset class="action">
245                                         [% IF ( record_type != 'auth' ) %]
246                                             Add new bibliographic records into this framework:
247                                             <select name="framework" id="frameworks">
248                                                 <option value="">Default</option>
249                                                 [% FOREACH framework IN frameworks %]
250                                                     <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
251                                                 [% END %]
252                                             </select>
253                                         [% END %]
254                                         <br />
255                                         <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
256                                     </fieldset>
257                                 </form> <!-- /#import_batch_form -->
258                                 <div id="jobpanel">
259                                     <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
260                                     <div id="jobfailed"></div>
261                                 </div>
262                             [% END # /IF can_commit %]
263                             [% IF ( can_revert ) %]
264                                 <form action="[% script_name | html %]" method="post" id="revert_batch_form">
265                                     <input type="hidden" name="op" value="revert-batch" />
266                                     <input type="hidden" name="runinbackground" value="" />
267                                     <input type="hidden" name="completedJobID" value="" />
268                                     <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
269                                     <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" /></fieldset>
270                                 </form>
271                                 <div id="jobpanel">
272                                     <div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
273                                     <div id="jobfailed"></div>
274                                 </div>
275                             [% END # /IF can_revert %]
276                         </div>
277
278                         [% IF ( did_commit ) %]
279                             <div class="dialog message">Completed import of records</div>
280                             <table>
281                                 <tr>
282                                     <td>Number of records added</td>
283                                     <td>[% num_added | html %]</td>
284                                 </tr>
285                                 <tr>
286                                     <td>Number of records updated</td>
287                                     <td>[% num_updated | html %]</td>
288                                 </tr>
289                                 <tr>
290                                     <td>Number of records ignored</td>
291                                     <td>[% num_ignored | html %]</td>
292                                 </tr>
293                                 [% IF ( record_type == 'biblio' ) %]
294                                     <tr>
295                                         <td>Number of items added</td>
296                                         <td>[% num_items_added | html %]</td>
297                                     </tr>
298                                     <tr>
299                                         <td>Number of items replaced</td>
300                                         <td>[% num_items_replaced | html %]</td>
301                                     </tr>
302                                     <tr>
303                                         <td>Number of items ignored because of duplicate barcode</td>
304                                         <td>[% num_items_errored | html %]</td>
305                                     </tr>
306                                 [% END %]
307                             </table>
308                         [% END #/ IF did_commit %]
309
310                         [% IF ( did_revert ) %]
311                             <div class="dialog message">Success: Import reversed</div>
312                             <table>
313                                 <tr>
314                                     <td>Number of records deleted</td>
315                                     <td>[% num_deleted | html %]</td>
316                                 </tr>
317                                 [% IF ( record_type == 'biblio' ) %]
318                                     <tr>
319                                         <td>Number of items deleted</td>
320                                         <td>[% num_items_deleted | html %]</td>
321                                     </tr>
322                                     <tr>
323                                         <td>Number of records not deleted due to items on loan</td>
324                                         <td>[% num_errors | html %]</td>
325                                     </tr>
326                                 [% END %]
327                                 <tr>
328                                     <td>Number of records changed back</td>
329                                     <td>[% num_reverted | html %]</td>
330                                 </tr>
331                                 <tr>
332                                     <td>Number of records ignored</td>
333                                     <td>[% num_ignored | html %]</td>
334                                 </tr>
335                             </table>
336                         [% END  # /IF did_revert%]
337
338                     [% END # /IF batch_info %]
339
340                     <br style="clear:both;" />
341
342                     [% IF ( batch_list ) %]
343                         [% IF ( pages ) %]
344                             [% PROCESS pagination %]
345                         [% END %]
346
347                         <table>
348                             <tr>
349                                 <th>#</th>
350                                 <th>File name</th>
351                                 <th>Profile</th>
352                                 <th>Comments</th>
353                                 <th>Type</th>
354                                 <th>Status</th>
355                                 <th>Staged</th>
356                                 <th># Records</th>
357                                 <th># Items</th>
358                                 <th>Action</th>
359                             </tr>
360                             [% FOREACH batch_lis IN batch_list %]
361                                 <tr>
362                                     <td>[% batch_lis.import_batch_id | html %]</td>
363                                     <td><a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td>
364                                     <td>[% batch_lis.profile | html %]</td>
365                                     <td>[% batch_lis.comments | html %]</td>
366                                     <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
367                                     <td>
368                                         [% IF ( batch_lis.import_status == 'cleaned' ) %]
369                                             <span>Cleaned</span>
370                                         [% ELSIF ( batch_lis.import_status == 'imported' ) %]
371                                             <span>Imported</span>
372                                         [% ELSIF ( batch_lis.import_status == 'importing' ) %]
373                                             <span>Importing</span>
374                                         [% ELSIF ( batch_lis.import_status == 'reverted' ) %]
375                                             <span>Reverted</span>
376                                         [% ELSIF ( batch_lis.import_status == 'reverting' ) %]
377                                             <span>Reverting</span>
378                                         [% ELSIF ( batch_lis.import_status == 'staged' ) %]
379                                             <span>Staged</span>
380                                         [% ELSE %]
381                                             <span>[% batch_lis.import_status | html %]</span>
382                                         [% END %]
383                                     </td>
384                                     <td>[% batch_lis.upload_timestamp | $KohaDates with_hours=1 %]</td>
385                                     <td>[% batch_lis.num_records | html %]</td>
386                                     <td>[% batch_lis.num_items | html %]
387                                         [% IF ( batch_lis.num_items && batch_lis.import_status == 'imported' ) %]
388                                             (<a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]&amp;op=create_labels">Create label batch</a>)
389                                         [% END %]
390                                     </td>
391                                     <td class="actions">
392                                         [% IF ( batch_lis.can_clean ) %]
393                                             <form method="post" action="[% batch_lis.script_name | html %]" name="clean_batch_[% batch_lis.import_batch_id | html %]" id="clean_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_clean">
394                                                 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
395                                                 <input type="hidden" name="op" value="clean-batch" />
396                                                 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-eraser"></i> Clean</button>
397                                             </form>
398                                         [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
399                                             <form method="post" action="/cgi-bin/koha/tools/manage-marc-import.pl" name="delete_batch_[% batch_lis.import_batch_id | html %]" id="delete_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_delete">
400                                                 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
401                                                 <input type="hidden" name="op" value="delete-batch" />
402                                                 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</button>
403                                             </form>
404                                         [% END %]
405                                     </td>
406                                 </tr>
407                             [% END # /FOREACH batch_lis %]
408                         </table>
409
410                         [% IF ( pages ) %]
411                             [% PROCESS pagination %]
412                         [% END %]
413                     [% END # /IF batch_lis %]
414
415                     [% IF import_batch_id && !did_clean %]
416                         <table id="records-table">
417                             <thead>
418                                 <tr>
419                                     <th>#</th>
420                                     <th>Citation</th>
421                                     <th>Status</th>
422                                     <th>Match type</th>
423                                     <th>Match details</th>
424                                     <th><abbr title="Differences between the original bibliographic record and the imported">Diff</abbr></th>
425                                     <th>Record</th>
426                                 </tr>
427                             </thead>
428                         </table>
429
430                         <div id="marcPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
431                             <div class="modal-dialog modal-wide">
432                                 <div class="modal-content">
433                                     <div class="modal-header">
434                                         <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
435                                         <h3 id="marcPreviewLabel">MARC preview</h3>
436                                     </div>
437                                     <div class="modal-body">
438                                         <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
439                                     </div>
440                                     <div class="modal-footer">
441                                         <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
442                                     </div>
443                                 </div>
444                             </div>
445                         </div> <!-- /#marcPreview -->
446                     [% END # /IF import_batch_id %]
447                 </main>
448
449             </div> <!-- /.col-sm-10.col-sm-push-2 -->
450             <div class="col-sm-2 col-sm-pull-10">
451                 <aside>
452                     [% INCLUDE 'tools-menu.inc' %]
453                 </aside>
454             </div> <!-- .col-sm-2.col-sm-pull-10 -->
455         </div> <!-- /.row -->
456
457 [% MACRO jsinclude BLOCK %]
458     [% Asset.js("js/tools-menu.js") | $raw %]
459     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
460     [% Asset.js("js/background-job-progressbar.js") | $raw %]
461     [% INCLUDE 'datatables.inc' %]
462     <script>
463         $(document).ready(function() {
464             $("#staged-record-matching-rules select").change(function() {
465                 var str = $(this).attr("id");
466                 $("#reset_" + str).parent().show();
467             });
468             $("a.reset").click(function() {
469                 var str = $(this).attr("id");
470                 str = str.replace("reset_", "")
471                 $("#" + str + " option[selected='selected']").attr("selected", "selected");
472                 $(this).parent().hide();
473             });
474
475             [% IF import_batch_id %]
476                 $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
477                     "bAutoWidth": false,
478                     "bFilter": false,
479                     "bProcessing": true,
480                     "bServerSide": true,
481                     "sAjaxSource": 'batch_records_ajax.pl',
482                     "sPaginationType": "full_numbers",
483                     "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
484                     "aoColumns": [
485                         { "mDataProp": "import_record_id" },
486                         { "mDataProp": "citation" },
487                         { "mDataProp": "status" },
488                         { "mDataProp": "overlay_status" },
489                         { "mDataProp": "" },
490                         { "mDataProp": "" },
491                         { "mDataProp": "matched" }
492                     ],
493                     "fnServerData": function(sSource, aoData, fnCallback) {
494                         aoData.push({ "name": "import_batch_id", "value": [% import_batch_id | html %] });
495
496                         $.ajax({
497                             'dataType': 'json',
498                             'type': 'POST',
499                             'url': sSource,
500                             'data': aoData,
501                             'success': function(json) {
502                                 fnCallback(json);
503                             }
504                         });
505                     },
506                     "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
507                         [% IF(record_type == 'auth') %]
508                             var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
509                         [% ELSE %]
510                             var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
511                         [% END %]
512                         [% IF(record_type == 'auth') %]
513                             var record_edit_url = "/cgi-bin/koha/authorities/authorities.pl?authid=";
514                         [% ELSE %]
515                             var record_edit_url = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
516                         [% END %]
517
518                         var additional_details = "";
519                         if( aData['author'] ){
520                             additional_details += " " + aData['author'] + " ";
521                         }
522
523                         if( aData['isbn'] ){
524                             additional_details += " (" + aData['isbn'] + ") ";
525                         }
526
527                         if( aData['issn'] ){
528                             additional_details += " (" + aData['issn'] + ") ";
529                         }
530
531                         $('td:eq(1)', nRow).html(
532                             '<a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=' + aData['import_record_id'] + '&viewas=html" class="previewMARC">' + aData['citation'] + '</a> ' + additional_details
533                         );
534
535                         $('td:eq(2)', nRow).html(
536                             aData['status'] == 'imported' ? _("Imported") :
537                             aData['status'] == 'ignored' ? _("Ignored") :
538                             aData['status'] == 'reverted' ? _("Reverted") :
539                             aData['status'] == 'staged' ? _("Staged") :
540                             aData['status'] == 'error' ? _("Error") :
541                             aData['status']
542                         );
543
544                         $('td:eq(3)', nRow).html(
545                             aData['overlay_status'] == 'no_match' ? _("No match") :
546                             aData['overlay_status'] == 'match_applied' ? _("Match applied") :
547                             aData['overlay_status'] == 'auto_match' ? _("Match found") :
548                             aData['overlay_status']
549                         );
550
551                         if ( aData['matches'].length > 0 ) {
552
553                             var any_checked = 0;
554                             $('td:eq(4)', nRow).html('<ul class="matches"></ul>');
555                             $('td:eq(5)', nRow).html('<ul class="matches"></ul>');
556                             var checked = "";
557                             var disabled = "";
558                             if( aData['status'] == "imported" || aData['status'] == "ignored" ){
559                                 disabled = ' disabled ';
560                             }
561                             aData['matches'].forEach(function(item,index){
562                                 if( item.chosen == 1 ){
563                                     checked = 'checked="checked"';
564                                     any_checked = 1;
565                                 }
566                                 [% IF(item.record_type == 'auth') -%]
567                                     var matching_msg = _("Matches authority %s (score=%s):%s");
568                                 [%- ELSE -%]
569                                     var matching_msg = _("Matches bibliographic record %s (score=%s):%s");
570                                 [%- END %]
571                                     var match_option = "";
572                                     match_option = '<input type="radio" data-import_record_id="'+aData['import_record_id']+'" class="chosen" name="import_record_id_'+aData['import_record_id']+'_match" value="'+item.candidate_match_id+'" ' + checked + disabled + '> ';
573
574                                     var diff_url = '/cgi-bin/koha/tools/showdiffmarc.pl?batchid=%s&importid=%s&id=%s&type=%s';
575                                     var match_citation = '';
576                                     if( item.title  ){ match_citation += item.title + ' ' }
577                                     if( item.author ){ match_citation += item.author }
578                                 $('td:eq(4) ul', nRow).append('<li><label for="import_record_id_'+aData['import_record_id']+'_match_'+index+'">'+match_option+
579                                     matching_msg.format(item.candidate_match_id, item.score,
580                                         '<a target="_blank" href="' + record_details_url
581                                         + item.candidate_match_id + '">' + match_citation + '</a></label></li>')
582                                 );
583                                 $('td:eq(5) ul', nRow).append('<li><a href="'
584                                         + diff_url.format( [% import_batch_id | html %], aData['import_record_id'], item.candidate_match_id, item.record_type) + '">' + _("View") + '</a></li>');
585                             });
586                             checked = "";
587                             if( !any_checked ){ checked = 'checked="checked"'; }
588                             $('td:eq(4) ul', nRow).prepend('<li><label><input type="radio" data-import_record_id="'+aData['import_record_id']+'" class="chosen" name="import_record_id_'+aData['import_record_id']+'_match" value="none" ' + checked + disabled + ' > Ignore matches</label></li>');
589                             $('td:eq(5) ul', nRow).prepend('<li>&nbsp;</li>');
590                         }
591                         if (aData['diff_url']) {
592                             $('td:eq(5)', nRow).html(
593                                 '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
594                             );
595                         }
596                         if (aData['matched']) {
597                             $('td:eq(6)', nRow).html(
598                                 '<a class="btn btn-default btn-xs" target="_blank" href="' + record_details_url
599                                 + aData['matched'] + '"><i class="fa fa-eye"></i> ' + _("View") + '</a> '
600                                 [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
601                                     + '<a class="btn btn-default btn-xs" target="_blank" href="' + record_edit_url
602                                     + aData['matched'] + '"><i class="fa fa-pencil"></i> ' + _("Edit") + '</a>'
603                                 [% END %]
604                             );
605                         }
606                     },
607                 }));
608                 $("#import_batch_form").on("submit", function() {
609                     return submitBackgroundJob(document.getElementById("import_batch_form"));
610                 });
611                 $("#revert_batch_form").on("submit", function() {
612                     return confirm(_("Are you sure you want to undo the import of this batch into the catalog?")) && submitBackgroundJob(document.getElementById("revert_batch_form"));
613                 });
614             [% END %]
615
616             $("body").on("change", ".chosen", function(e) {
617                 let apimethod = "DELETE";
618                 let apidata ="";
619                 if( $(this).val() != 'none' ){
620                     apimethod = 'PUT';
621                     apidata = JSON.stringify({ candidate_match_id: $(this).val() });
622                 }
623                 $.ajax({
624                     url: '/api/v1/import/[% import_batch_id | html %]/records/'+$(this).data('import_record_id')+'/matches/chosen',
625                     method: apimethod,
626                     data: apidata
627                 }).fail(function(){ alert("Unable to update match choices"); return false; });
628             });
629
630             $("body").on("click", ".previewMARC", function(e) {
631                 e.preventDefault();
632                 var ltitle = $(this).text();
633                 var page = $(this).attr("href");
634                 $("#marcPreviewLabel").text(ltitle);
635                 $("#marcPreview .modal-body").load(page + " table");
636                 $('#marcPreview').modal({ show: true });
637             });
638             $("#marcPreview").on("hidden.bs.modal", function() {
639                 $("#marcPreviewLabel").html("");
640                 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
641             });
642             $(".batch_form").on("submit", function() {
643                 if ($(this).hasClass("batch_delete")) {
644                     return confirm(_("Are you sure you want to permanently delete this batch?"));
645                 } else {
646                     return confirm(_("Clear all reservoir records staged in this batch?  This cannot be undone."));
647                 }
648             });
649         });
650
651     </script>
652 [% END %]
653 [% INCLUDE 'intranet-bottom.inc' %]
654 [% BLOCK pagination %]
655     <nav>
656         <ul class="pagination">
657             [% FOREACH page IN pages %]
658                 [% IF ( page.current_page && page.page_number > 1 ) %]
659                     <li><a href="[% page.script_name | url %]?offset=0" class="nav"><i class="fa fa-fw fa-angle-double-left"></i> First</a></li>
660                     <li><a href="[% page.script_name | url %]?offset=[% offset - results_per_page | uri %]"><i class="fa fa-fw fa-angle-left"></i> Previous</a></li>
661                 [% END %]
662             [% END %]
663             [% FOREACH page IN pages %]
664                 [% IF ( page.current_page ) %]
665                     [% SET current_page = page.page_number %]
666                     <li class="active"><span class="current">[% page.page_number | html %]</span></li>
667                 [% ELSE %]
668                     <li><a class="nav" href="[% page.script_name | url %]?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li>
669                 [% END %]
670             [% END %]
671             [% IF ( current_page < pages.size() ) %]
672                 <li>
673                     <a href="[% page.script_name | url %]?offset=[% offset + results_per_page | uri %]" class="nav">Next <i class="fa fa-fw fa-angle-right"></i></a>
674                 </li>
675                 <li>
676                     <a href="[% page.script_name | url %]?offset=[% ( results_per_page * ( pages.size - 1 ) ) | uri %]" class="nav">Last <i class="fa fa-fw fa-angle-double-right"></i></a>
677                 </li>
678             [% END %]
679         </ul>
680     </nav>
681 [% END %]