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 [% INCLUDE 'header.inc' %]
22 [% INCLUDE 'cat-search.inc' %]
24 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
27 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
30 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
32 [% IF ( import_batch_id ) %]
34 <a href="[% script_name | url %]">Manage staged MARC records</a>
37 <a href="#" aria-current="page">
38 Batch [% import_batch_id | html %]
43 <a href="#" aria-current="page">
44 Manage staged MARC records
51 <div class="main container-fluid">
53 <div class="col-sm-10 col-sm-push-2">
55 <h1>Manage staged MARC records
56 [% IF ( import_batch_id ) %]
57 › Batch [% import_batch_id | html %]
61 [% IF ( label_batch_msg ) %]
65 <div class="dialog message">
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.
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.
77 [% IF ( did_clean ) %]
78 <div class="dialog message">Cleaned import batch #[% import_batch_id | html %]</div>
81 [% IF ( did_delete ) %]
82 <div class="dialog message">Import batch deleted successfully</div>
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>
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 %]" />
102 [% IF ( rematch_attempted ) %]
103 [% IF ( rematch_failed ) %]
104 <div class="dialog alert">Failed to apply different matching rule</div>
106 <div class="dialog message">Applied different matching rule. Number of records matched now
107 [% num_with_matches | html %]
112 [% IF ( changed_overlay_action ) %]
113 <div class="dialog message">Changed action if matching record found</div>
116 [% IF ( changed_nomatch_action ) %]
117 <div class="dialog message">Changed action if no match found</div>
120 [% IF ( changed_item_action ) %]
121 <div class="dialog message">Changed item processing option</div>
124 <fieldset class="rows" id="staged-record-matching-rules">
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' ) %]
134 [% ELSIF ( import_status == 'imported' ) %]
136 [% ELSIF ( import_status == 'importing' ) %]
138 [% ELSIF ( import_status == 'reverted' ) %]
140 [% ELSIF ( import_status == 'reverting' ) %]
142 [% ELSIF ( import_status == 'staged' ) %]
145 [% import_status | html %]
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 %])
159 <option value="[% available_matcher.matcher_id | html %]">
160 [% available_matcher.code | html %] ([% available_matcher.description | html %])
165 <span class="change-status">Changed. <a href="#" class="reset" id="reset_new_matcher_id">Reset</a></span>
167 <span class="label">Matching rule applied</span>
168 [% IF ( current_matcher_id ) %]
169 [% current_matcher_code | html %] ([% current_matcher_description | html %])
171 <span>No matching rule in effect</span>
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>
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>
188 <span>[% overlay_action | html %]</span>
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>
197 <span class="label">Action if no match found:</span>
198 [% IF ( nomatch_action == 'create_new' ) %]
200 [% ELSIF ( nomatch_action == 'ignore' ) %]
201 Ignore incoming record (its items may still be processed)
203 [% nomatch_action | html %]
207 [% IF ( record_type == 'biblio' ) %]
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>
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>
223 <span>[% item_action | html %]</span>
228 <input type ="hidden" name="item_action" value="ignore">
231 [% IF ( can_commit ) %]
232 <fieldset class="action"><input type="submit" value="Apply different matching rules" class="button" /></fieldset>
235 </fieldset> <!-- /#staged-record-matching-rules -->
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>
255 <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
257 </form> <!-- /#import_batch_form -->
259 <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
260 <div id="jobfailed"></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>
272 <div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
273 <div id="jobfailed"></div>
275 [% END # /IF can_revert %]
278 [% IF ( did_commit ) %]
279 <div class="dialog message">Completed import of records</div>
282 <td>Number of records added</td>
283 <td>[% num_added | html %]</td>
286 <td>Number of records updated</td>
287 <td>[% num_updated | html %]</td>
290 <td>Number of records ignored</td>
291 <td>[% num_ignored | html %]</td>
293 [% IF ( record_type == 'biblio' ) %]
295 <td>Number of items added</td>
296 <td>[% num_items_added | html %]</td>
299 <td>Number of items replaced</td>
300 <td>[% num_items_replaced | html %]</td>
303 <td>Number of items ignored because of duplicate barcode</td>
304 <td>[% num_items_errored | html %]</td>
308 [% END #/ IF did_commit %]
310 [% IF ( did_revert ) %]
311 <div class="dialog message">Success: Import reversed</div>
314 <td>Number of records deleted</td>
315 <td>[% num_deleted | html %]</td>
317 [% IF ( record_type == 'biblio' ) %]
319 <td>Number of items deleted</td>
320 <td>[% num_items_deleted | html %]</td>
323 <td>Number of records not deleted due to items on loan</td>
324 <td>[% num_errors | html %]</td>
328 <td>Number of records changed back</td>
329 <td>[% num_reverted | html %]</td>
332 <td>Number of records ignored</td>
333 <td>[% num_ignored | html %]</td>
336 [% END # /IF did_revert%]
338 [% END # /IF batch_info %]
340 <br style="clear:both;" />
342 [% IF ( batch_list ) %]
344 [% PROCESS pagination %]
360 [% FOREACH batch_lis IN batch_list %]
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>
368 [% IF ( batch_lis.import_status == 'cleaned' ) %]
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' ) %]
381 <span>[% batch_lis.import_status | html %]</span>
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 %]&op=create_labels">Create label batch</a>)
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>
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>
407 [% END # /FOREACH batch_lis %]
411 [% PROCESS pagination %]
413 [% END # /IF batch_lis %]
415 [% IF import_batch_id && !did_clean %]
416 <table id="records-table">
423 <th>Match details</th>
424 <th><abbr title="Differences between the original bibliographic record and the imported">Diff</abbr></th>
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>
437 <div class="modal-body">
438 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
440 <div class="modal-footer">
441 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
445 </div> <!-- /#marcPreview -->
446 [% END # /IF import_batch_id %]
449 </div> <!-- /.col-sm-10.col-sm-push-2 -->
450 <div class="col-sm-2 col-sm-pull-10">
452 [% INCLUDE 'tools-menu.inc' %]
454 </div> <!-- .col-sm-2.col-sm-pull-10 -->
455 </div> <!-- /.row -->
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' %]
463 $(document).ready(function() {
464 $("#staged-record-matching-rules select").change(function() {
465 var str = $(this).attr("id");
466 $("#reset_" + str).parent().show();
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();
475 [% IF import_batch_id %]
476 $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
481 "sAjaxSource": 'batch_records_ajax.pl',
482 "sPaginationType": "full_numbers",
483 "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
485 { "mDataProp": "import_record_id" },
486 { "mDataProp": "citation" },
487 { "mDataProp": "status" },
488 { "mDataProp": "overlay_status" },
491 { "mDataProp": "matched" }
493 "fnServerData": function(sSource, aoData, fnCallback) {
494 aoData.push({ "name": "import_batch_id", "value": [% import_batch_id | html %] });
501 'success': function(json) {
506 "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
507 [% IF(record_type == 'auth') %]
508 var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
510 var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
512 [% IF(record_type == 'auth') %]
513 var record_edit_url = "/cgi-bin/koha/authorities/authorities.pl?authid=";
515 var record_edit_url = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
518 var additional_details = "";
519 if( aData['author'] ){
520 additional_details += " " + aData['author'] + " ";
524 additional_details += " (" + aData['isbn'] + ") ";
528 additional_details += " (" + aData['issn'] + ") ";
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
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") :
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']
551 if ( aData['matches'].length > 0 ) {
554 $('td:eq(4)', nRow).html('<ul class="matches"></ul>');
555 $('td:eq(5)', nRow).html('<ul class="matches"></ul>');
558 if( aData['status'] == "imported" || aData['status'] == "ignored" ){
559 disabled = ' disabled ';
561 aData['matches'].forEach(function(item,index){
562 if( item.chosen == 1 ){
563 checked = 'checked="checked"';
566 [% IF(item.record_type == 'auth') -%]
567 var matching_msg = _("Matches authority %s (score=%s):%s");
569 var matching_msg = _("Matches bibliographic record %s (score=%s):%s");
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 + '> ';
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>')
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>');
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> </li>');
591 if (aData['diff_url']) {
592 $('td:eq(5)', nRow).html(
593 '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
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>'
608 $("#import_batch_form").on("submit", function() {
609 return submitBackgroundJob(document.getElementById("import_batch_form"));
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"));
616 $("body").on("change", ".chosen", function(e) {
617 let apimethod = "DELETE";
619 if( $(this).val() != 'none' ){
621 apidata = JSON.stringify({ candidate_match_id: $(this).val() });
624 url: '/api/v1/import/[% import_batch_id | html %]/records/'+$(this).data('import_record_id')+'/matches/chosen',
627 }).fail(function(){ alert("Unable to update match choices"); return false; });
630 $("body").on("click", ".previewMARC", function(e) {
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 });
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>");
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?"));
646 return confirm(_("Clear all reservoir records staged in this batch? This cannot be undone."));
653 [% INCLUDE 'intranet-bottom.inc' %]
654 [% BLOCK pagination %]
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>
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>
668 <li><a class="nav" href="[% page.script_name | url %]?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li>
671 [% IF ( current_page < pages.size() ) %]
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>
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>