5 [% INCLUDE 'doc-head-open.inc' %]
7 [% IF ( import_batch_id ) %]
8 Batch [% import_batch_id | html %] › [% END %]
9 Manage staged MARC records › Tools › Koha
11 [% INCLUDE 'doc-head-close.inc' %]
12 [% Asset.css("css/humanmsg.css") | $raw %]
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; }
20 <body id="tools_manage-marc-import" class="tools">
21 [% WRAPPER 'header.inc' %]
22 [% INCLUDE 'cat-search.inc' %]
25 [% WRAPPER 'sub-header.inc' %]
26 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
29 <a href="/cgi-bin/koha/mainpage.pl"><i class="fa fa-home"></i></a>
32 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
34 [% IF ( import_batch_id ) %]
36 <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a>
39 <a href="#" aria-current="page">
40 Batch [% import_batch_id | html %]
45 <a href="#" aria-current="page">
46 Manage staged MARC records
54 <div class="main container-fluid">
56 <div class="col-sm-10 col-sm-push-2">
58 <h1>Manage staged MARC records
59 [% IF ( import_batch_id ) %]
60 › Batch [% import_batch_id | html %]
63 [% FOREACH message IN messages %]
64 [% IF message.type == 'success' %]
65 <div class="dialog message">
66 [% ELSIF message.type == 'warning' %]
67 <div class="dialog alert">
68 [% ELSIF message.type == 'error' %]
69 <div class="dialog alert" style="margin:auto;">
71 [% IF message.code == 'cannot_enqueue_job' %]
72 <span>Cannot enqueue this job.</span>
74 [% IF message.error %]
75 <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
81 <div class="dialog message">
82 <p>The job has been enqueued! It will be processed as soon as possible.</p>
83 <p><a class="job_details" 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>
86 [% ELSIF ( label_batch_msg ) %]
90 <div class="dialog message">
93 [% IF ( label_batch_msg == "error" ) %]
94 <span>Error attempting to create label batch. Please ask your system administrator to check the log for more details.</span>
96 <span>Label</span> <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.
102 [% IF ( did_clean ) %]
103 <div class="dialog message">Cleaned import batch #[% import_batch_id | html %]</div>
106 [% IF ( did_delete ) %]
107 <div class="dialog message">Import batch deleted successfully</div>
110 [% UNLESS batch_list || batch_info || job_enqueued %]
111 <div class="dialog message">
112 <p>No records have been staged.</p>
113 <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
117 [% IF ( batch_info ) %]
118 [% IF ( can_commit ) %]
120 <input type="hidden" name="op" value="redo-matching" />
121 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
122 <input type="hidden" name="current_matcher_id" value="[% current_matcher_id | html %]" />
125 [% IF ( rematch_attempted ) %]
126 [% IF ( rematch_failed ) %]
127 <div class="dialog alert">Failed to apply different matching rule</div>
129 <div class="dialog message">Applied different matching rule. Number of records matched now
130 [% num_with_matches | html %]
135 [% IF ( changed_overlay_action ) %]
136 <div class="dialog message">Changed action if matching record found</div>
139 [% IF ( changed_nomatch_action ) %]
140 <div class="dialog message">Changed action if no match found</div>
143 [% IF ( changed_item_action ) %]
144 <div class="dialog message">Changed item processing option</div>
147 [% UNLESS job_enqueued %]
148 <fieldset class="rows" id="staged-record-matching-rules">
150 <li><span class="label">File name:</span> [% file_name | html %]</li>
151 <li><span class="label">Profile:</span> [% IF (profile) %][% profile | html %][% ELSE %](none)[% END %]</li>
152 <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments | html %][% ELSE %](none)[% END %]</li>
153 <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
154 <li><span class="label">Staged:</span> [% upload_timestamp | $KohaDates with_hours=1 %]</li>
155 <li><span class="label">Status:</span>
156 [% IF ( import_status == 'cleaned' ) %]
158 [% ELSIF ( import_status == 'imported' ) %]
159 <span>Imported</span>
160 [% ELSIF ( import_status == 'importing' ) %]
161 <span>Importing</span>
162 [% ELSIF ( import_status == 'reverted' ) %]
163 <span>Reverted</span>
164 [% ELSIF ( import_status == 'reverting' ) %]
165 <span>Reverting</span>
166 [% ELSIF ( import_status == 'staged' ) %]
169 [% import_status | html %]
173 [% IF ( can_commit ) %]
174 <label for="new_matcher_id">Matching rule applied:</label>
175 <select name="new_matcher_id" id="new_matcher_id">
176 <option value="">Do not look for matching records</option>
177 [% FOREACH available_matcher IN available_matchers %]
178 [% IF ( available_matcher.selected ) %]
179 <option value="[% available_matcher.matcher_id | html %]" selected="selected">
180 [% available_matcher.code | html %] ([% available_matcher.description | html %])
183 <option value="[% available_matcher.matcher_id | html %]">
184 [% available_matcher.code | html %] ([% available_matcher.description | html %])
189 <span class="change-status">Changed. <a href="#" class="reset" id="reset_new_matcher_id">Reset</a></span>
191 <span class="label">Matching rule applied</span>
192 [% IF ( current_matcher_id ) %]
193 [% current_matcher_code | html %] ([% current_matcher_description | html %])
195 <span>No matching rule in effect</span>
200 [% IF ( can_commit ) %]
201 <label for="overlay_action">Action if matching record found:</label>
202 [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>
204 <span class="label">Action if matching record found:</span>
205 [% IF ( overlay_action == 'replace' ) %]
206 <span>Replace existing record with incoming record</span>
207 [% ELSIF ( overlay_action == 'create_new' ) %]
208 <span>Add incoming record</span>
209 [% ELSIF ( overlay_action == 'ignore' ) %]
210 <span>Ignore incoming record (its items may still be processed)</span>
212 <span>[% overlay_action | html %]</span>
217 [% IF ( can_commit ) %]
218 <label for="nomatch_action">Action if no match found:</label>
219 [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>
221 <span class="label">Action if no match found:</span>
222 [% IF ( nomatch_action == 'create_new' ) %]
224 [% ELSIF ( nomatch_action == 'ignore' ) %]
225 Ignore incoming record (its items may still be processed)
227 [% nomatch_action | html %]
231 [% IF ( record_type == 'biblio' ) %]
233 [% IF ( can_commit ) %]
234 <label for="item_action">Item processing:</label>
235 [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>
237 <span class="label">Item processing:</span>
238 [% IF ( item_action == 'always_add' ) %]
239 <span>Always add items</span>
240 [% ELSIF ( item_action == 'add_only_for_matches' ) %]
241 <span>Add items only if matching bib was found</span>
242 [% ELSIF ( item_action == 'add_only_for_new' ) %]
243 <span>Add items only if no matching bib was found</span>
244 [% ELSIF ( item_action == 'ignore' ) %]
245 <span>Ignore items</span>
247 <span>[% item_action | html %]</span>
252 <input type ="hidden" name="item_action" value="ignore">
255 [% IF ( can_commit ) %]
256 <fieldset class="action"><input type="submit" value="Apply different matching rules" class="button" /></fieldset>
259 </fieldset> <!-- /#staged-record-matching-rules -->
262 [% IF ( can_commit ) %]
263 <form method="post" id="import_batch_form">
264 <input type="hidden" name="op" value="commit-batch" />
265 <input type="hidden" name="runinbackground" value="" />
266 <input type="hidden" name="completedJobID" value="" />
267 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
268 <fieldset class="action">
269 [% IF ( record_type != 'auth' ) %]
270 Add new bibliographic records into this framework:
271 <select name="framework" id="frameworks">
272 <option value="">Default</option>
273 [% FOREACH framework IN frameworks %]
274 <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
279 <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
281 </form> <!-- /#import_batch_form -->
283 <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
284 <div id="jobfailed"></div>
286 [% END # /IF can_commit %]
287 [% IF ( can_revert ) %]
288 <form method="post" id="revert_batch_form">
289 <input type="hidden" name="op" value="revert-batch" />
290 <input type="hidden" name="runinbackground" value="" />
291 <input type="hidden" name="completedJobID" value="" />
292 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
293 <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" /></fieldset>
296 <div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
297 <div id="jobfailed"></div>
299 [% END # /IF can_revert %]
303 [% END # /IF batch_info %]
305 <br style="clear:both;" />
307 [% IF ( batch_list ) %]
309 [% PROCESS pagination %]
325 [% FOREACH batch_lis IN batch_list %]
327 <td>[% batch_lis.import_batch_id | html %]</td>
328 <td><a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td>
329 <td>[% batch_lis.profile | html %]</td>
330 <td>[% batch_lis.comments | html %]</td>
331 <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
333 [% IF ( batch_lis.import_status == 'cleaned' ) %]
335 [% ELSIF ( batch_lis.import_status == 'imported' ) %]
336 <span>Imported</span>
337 [% ELSIF ( batch_lis.import_status == 'importing' ) %]
338 <span>Importing</span>
339 [% ELSIF ( batch_lis.import_status == 'reverted' ) %]
340 <span>Reverted</span>
341 [% ELSIF ( batch_lis.import_status == 'reverting' ) %]
342 <span>Reverting</span>
343 [% ELSIF ( batch_lis.import_status == 'staged' ) %]
346 <span>[% batch_lis.import_status | html %]</span>
349 <td>[% batch_lis.upload_timestamp | $KohaDates with_hours=1 %]</td>
350 <td>[% batch_lis.num_records | html %]</td>
351 <td>[% batch_lis.num_items | html %]
352 [% IF ( batch_lis.num_items && batch_lis.import_status == 'imported' ) %]
353 (<a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]&op=create_labels">Create label batch</a>)
357 [% IF ( batch_lis.can_clean ) %]
358 <form method="post" name="clean_batch_[% batch_lis.import_batch_id | html %]" id="clean_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_clean">
359 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
360 <input type="hidden" name="op" value="clean-batch" />
361 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-eraser"></i> Clean</button>
363 [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
364 <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">
365 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
366 <input type="hidden" name="op" value="delete-batch" />
367 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</button>
372 [% END # /FOREACH batch_lis %]
376 [% PROCESS pagination %]
378 [% END # /IF batch_lis %]
380 [% IF import_batch_id && !did_clean %]
381 <table id="records-table">
388 <th>Match details</th>
389 <th><abbr title="Differences between the original bibliographic record and the imported">Diff</abbr></th>
395 <div id="marcPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
396 <div class="modal-dialog modal-wide">
397 <div class="modal-content">
398 <div class="modal-header">
399 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
400 <h3 id="marcPreviewLabel">MARC preview</h3>
402 <div class="modal-body">
403 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
405 <div class="modal-footer">
406 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
410 </div> <!-- /#marcPreview -->
411 [% END # /IF import_batch_id %]
414 </div> <!-- /.col-sm-10.col-sm-push-2 -->
415 <div class="col-sm-2 col-sm-pull-10">
417 [% INCLUDE 'tools-menu.inc' %]
419 </div> <!-- .col-sm-2.col-sm-pull-10 -->
420 </div> <!-- /.row -->
422 [% MACRO jsinclude BLOCK %]
423 [% Asset.js("js/tools-menu.js") | $raw %]
424 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
425 [% INCLUDE 'datatables.inc' %]
427 $(document).ready(function() {
428 $("#staged-record-matching-rules select").change(function() {
429 var str = $(this).attr("id");
430 $("#reset_" + str).parent().show();
432 $("a.reset").click(function() {
433 var str = $(this).attr("id");
434 str = str.replace("reset_", "")
435 $("#" + str + " option[selected='selected']").attr("selected", "selected");
436 $(this).parent().hide();
439 [% IF import_batch_id %]
440 $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
445 "sAjaxSource": 'batch_records_ajax.pl',
446 "sPaginationType": "full_numbers",
447 "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
449 { "mDataProp": "import_record_id" },
450 { "mDataProp": "citation" },
451 { "mDataProp": "status" },
452 { "mDataProp": "overlay_status" },
453 { "mDataProp": null, "sDefaultContent": "" },
454 { "mDataProp": null, "sDefaultContent": "" },
455 { "mDataProp": "matched" }
457 "fnServerData": function(sSource, aoData, fnCallback) {
458 aoData.push({ "name": "import_batch_id", "value": [% import_batch_id | html %] });
465 'success': function(json) {
470 "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
471 [% IF(record_type == 'auth') %]
472 var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
474 var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
476 [% IF(record_type == 'auth') %]
477 var record_edit_url = "/cgi-bin/koha/authorities/authorities.pl?authid=";
479 var record_edit_url = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
482 var additional_details = "";
483 if( aData['author'] ){
484 additional_details += " " + aData['author'] + " ";
488 additional_details += " (" + aData['isbn'] + ") ";
492 additional_details += " (" + aData['issn'] + ") ";
495 $('td:eq(1)', nRow).html(
496 '<a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=' + aData['import_record_id'] + '&viewas=html" class="previewMARC">' + aData['citation'] + '</a> ' + additional_details
499 $('td:eq(2)', nRow).html(
500 aData['status'] == 'imported' ? _("Imported") :
501 aData['status'] == 'ignored' ? _("Ignored") :
502 aData['status'] == 'reverted' ? _("Reverted") :
503 aData['status'] == 'staged' ? _("Staged") :
504 aData['status'] == 'error' ? _("Error") :
508 $('td:eq(3)', nRow).html(
509 aData['overlay_status'] == 'no_match' ? _("No match") :
510 aData['overlay_status'] == 'match_applied' ? _("Match applied") :
511 aData['overlay_status'] == 'auto_match' ? _("Match found") :
512 aData['overlay_status']
515 if ( aData['matches'].length > 0 ) {
518 $('td:eq(4)', nRow).html('<ul class="matches"></ul>');
519 $('td:eq(5)', nRow).html('<ul class="matches"></ul>');
522 if( aData['status'] == "imported" || aData['status'] == "ignored" ){
523 disabled = ' disabled ';
525 aData['matches'].forEach(function(item,index){
526 if( item.chosen == 1 ){
527 checked = 'checked="checked"';
530 [% IF(item.record_type == 'auth') -%]
531 var matching_msg = _("Matches authority %s (score=%s):%s");
533 var matching_msg = _("Matches bibliographic record %s (score=%s):%s");
535 var match_option = "";
536 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 + '> ';
538 var diff_url = '/cgi-bin/koha/tools/showdiffmarc.pl?batchid=%s&importid=%s&id=%s&type=%s';
539 var match_citation = '';
540 if( item.title ){ match_citation += item.title + ' ' }
541 if( item.author ){ match_citation += item.author }
542 $('td:eq(4) ul', nRow).append('<li><label for="import_record_id_'+aData['import_record_id']+'_match_'+index+'">'+match_option+
543 matching_msg.format(item.candidate_match_id, item.score,
544 '<a target="_blank" href="' + record_details_url
545 + item.candidate_match_id + '">' + match_citation + '</a></label></li>')
547 $('td:eq(5) ul', nRow).append('<li><a href="'
548 + diff_url.format( [% import_batch_id | html %], aData['import_record_id'], item.candidate_match_id, item.record_type) + '">' + _("View") + '</a></li>');
551 if( !any_checked ){ checked = 'checked="checked"'; }
552 $('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>');
553 $('td:eq(5) ul', nRow).prepend('<li> </li>');
555 if (aData['diff_url']) {
556 $('td:eq(5)', nRow).html(
557 '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
560 if (aData['matched']) {
561 $('td:eq(6)', nRow).html(
562 '<a class="btn btn-default btn-xs" target="_blank" href="' + record_details_url
563 + aData['matched'] + '"><i class="fa fa-eye"></i> ' + _("View") + '</a> '
564 [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
565 + '<a class="btn btn-default btn-xs" target="_blank" href="' + record_edit_url
566 + aData['matched'] + '"><i class="fa fa-pencil"></i> ' + _("Edit") + '</a>'
572 $("#import_batch_form").on("submit", function() {
573 return submitBackgroundJob(document.getElementById("import_batch_form"));
575 $("#revert_batch_form").on("submit", function() {
576 return confirm(_("Are you sure you want to undo the import of this batch into the catalog?")) && submitBackgroundJob(document.getElementById("revert_batch_form"));
580 $("body").on("change", ".chosen", function(e) {
581 let apimethod = "DELETE";
583 if( $(this).val() != 'none' ){
585 apidata = JSON.stringify({ candidate_match_id: $(this).val() });
588 url: '/api/v1/import_batches/[% import_batch_id | html %]/records/'+$(this).data('import_record_id')+'/matches/chosen',
591 contentType: 'application/json'
592 }).fail(function(){ alert(_("Unable to update match choices")); return false; });
595 $("body").on("click", ".previewMARC", function(e) {
597 var ltitle = $(this).text();
598 var page = $(this).attr("href");
599 $("#marcPreviewLabel").text(ltitle);
600 $("#marcPreview .modal-body").load(page + " table");
601 $('#marcPreview').modal({ show: true });
603 $("#marcPreview").on("hidden.bs.modal", function() {
604 $("#marcPreviewLabel").html("");
605 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
607 $(".batch_form").on("submit", function() {
608 if ($(this).hasClass("batch_delete")) {
609 return confirm(_("Are you sure you want to permanently delete this batch?"));
611 return confirm(_("Clear all reservoir records staged in this batch? This cannot be undone."));
614 [% IF job_enqueued %]
616 function() { window.location.href=$('a.job_details').attr('href'); },
617 5000, // 5 secs to read
624 [% INCLUDE 'intranet-bottom.inc' %]
625 [% BLOCK pagination %]
627 <ul class="pagination">
628 [% FOREACH page IN pages %]
629 [% IF ( page.current_page && page.page_number > 1 ) %]
630 <li><a href="?offset=0" class="nav"><i class="fa fa-fw fa-angle-double-left"></i> First</a></li>
631 <li><a href="?offset=[% offset - results_per_page | uri %]"><i class="fa fa-fw fa-angle-left"></i> Previous</a></li>
634 [% FOREACH page IN pages %]
635 [% IF ( page.current_page ) %]
636 [% SET current_page = page.page_number %]
637 <li class="active"><span class="current">[% page.page_number | html %]</span></li>
639 <li><a class="nav" href="?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li>
642 [% IF ( current_page < pages.size() ) %]
644 <a href="?offset=[% offset + results_per_page | uri %]" class="nav">Next <i class="fa fa-fw fa-angle-right"></i></a>
647 <a href="?offset=[% ( results_per_page * ( pages.size - 1 ) ) | uri %]" class="nav">Last <i class="fa fa-fw fa-angle-double-right"></i></a>