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="/cgi-bin/koha/tools/manage-marc-import.pl">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 %]
60 [% FOREACH message IN messages %]
61 [% IF message.type == 'success' %]
62 <div class="dialog message">
63 [% ELSIF message.type == 'warning' %]
64 <div class="dialog alert">
65 [% ELSIF message.type == 'error' %]
66 <div class="dialog alert" style="margin:auto;">
68 [% IF message.code == 'cannot_enqueue_job' %]
69 <span>Cannot enqueue this job.</span>
71 [% IF message.error %]
72 <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
78 <div class="dialog message">
79 <p>The job has been enqueued! It will be processed as soon as possible.</p>
80 <p><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>
83 [% ELSIF ( label_batch_msg ) %]
87 <div class="dialog message">
90 [% IF ( label_batch_msg == "error" ) %]
91 <span>Error attempting to create label batch. Please ask your system administrator to check the log for more details.</span>
93 <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.
99 [% IF ( did_clean ) %]
100 <div class="dialog message">Cleaned import batch #[% import_batch_id | html %]</div>
103 [% IF ( did_delete ) %]
104 <div class="dialog message">Import batch deleted successfully</div>
107 [% UNLESS batch_list || batch_info || job_enqueued %]
108 <div class="dialog message">
109 <p>No records have been staged.</p>
110 <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
114 [% IF ( batch_info ) %]
115 [% IF ( can_commit ) %]
117 <input type="hidden" name="op" value="redo-matching" />
118 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
119 <input type="hidden" name="current_matcher_id" value="[% current_matcher_id | html %]" />
122 [% IF ( rematch_attempted ) %]
123 [% IF ( rematch_failed ) %]
124 <div class="dialog alert">Failed to apply different matching rule</div>
126 <div class="dialog message">Applied different matching rule. Number of records matched now
127 [% num_with_matches | html %]
132 [% IF ( changed_overlay_action ) %]
133 <div class="dialog message">Changed action if matching record found</div>
136 [% IF ( changed_nomatch_action ) %]
137 <div class="dialog message">Changed action if no match found</div>
140 [% IF ( changed_item_action ) %]
141 <div class="dialog message">Changed item processing option</div>
144 [% UNLESS job_enqueued %]
145 <fieldset class="rows" id="staged-record-matching-rules">
147 <li><span class="label">File name:</span> [% file_name | html %]</li>
148 <li><span class="label">Profile:</span> [% IF (profile) %][% profile | html %][% ELSE %](none)[% END %]</li>
149 <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments | html %][% ELSE %](none)[% END %]</li>
150 <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
151 <li><span class="label">Staged:</span> [% upload_timestamp | $KohaDates with_hours=1 %]</li>
152 <li><span class="label">Status:</span>
153 [% IF ( import_status == 'cleaned' ) %]
155 [% ELSIF ( import_status == 'imported' ) %]
156 <span>Imported</span>
157 [% ELSIF ( import_status == 'importing' ) %]
158 <span>Importing</span>
159 [% ELSIF ( import_status == 'reverted' ) %]
160 <span>Reverted</span>
161 [% ELSIF ( import_status == 'reverting' ) %]
162 <span>Reverting</span>
163 [% ELSIF ( import_status == 'staged' ) %]
166 [% import_status | html %]
170 [% IF ( can_commit ) %]
171 <label for="new_matcher_id">Matching rule applied:</label>
172 <select name="new_matcher_id" id="new_matcher_id">
173 <option value="">Do not look for matching records</option>
174 [% FOREACH available_matcher IN available_matchers %]
175 [% IF ( available_matcher.selected ) %]
176 <option value="[% available_matcher.matcher_id | html %]" selected="selected">
177 [% available_matcher.code | html %] ([% available_matcher.description | html %])
180 <option value="[% available_matcher.matcher_id | html %]">
181 [% available_matcher.code | html %] ([% available_matcher.description | html %])
186 <span class="change-status">Changed. <a href="#" class="reset" id="reset_new_matcher_id">Reset</a></span>
188 <span class="label">Matching rule applied</span>
189 [% IF ( current_matcher_id ) %]
190 [% current_matcher_code | html %] ([% current_matcher_description | html %])
192 <span>No matching rule in effect</span>
197 [% IF ( can_commit ) %]
198 <label for="overlay_action">Action if matching record found:</label>
199 [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>
201 <span class="label">Action if matching record found:</span>
202 [% IF ( overlay_action == 'replace' ) %]
203 <span>Replace existing record with incoming record</span>
204 [% ELSIF ( overlay_action == 'create_new' ) %]
205 <span>Add incoming record</span>
206 [% ELSIF ( overlay_action == 'ignore' ) %]
207 <span>Ignore incoming record (its items may still be processed)</span>
209 <span>[% overlay_action | html %]</span>
214 [% IF ( can_commit ) %]
215 <label for="nomatch_action">Action if no match found:</label>
216 [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>
218 <span class="label">Action if no match found:</span>
219 [% IF ( nomatch_action == 'create_new' ) %]
221 [% ELSIF ( nomatch_action == 'ignore' ) %]
222 Ignore incoming record (its items may still be processed)
224 [% nomatch_action | html %]
228 [% IF ( record_type == 'biblio' ) %]
230 [% IF ( can_commit ) %]
231 <label for="item_action">Item processing:</label>
232 [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>
234 <span class="label">Item processing:</span>
235 [% IF ( item_action == 'always_add' ) %]
236 <span>Always add items</span>
237 [% ELSIF ( item_action == 'add_only_for_matches' ) %]
238 <span>Add items only if matching bib was found</span>
239 [% ELSIF ( item_action == 'add_only_for_new' ) %]
240 <span>Add items only if no matching bib was found</span>
241 [% ELSIF ( item_action == 'ignore' ) %]
242 <span>Ignore items</span>
244 <span>[% item_action | html %]</span>
249 <input type ="hidden" name="item_action" value="ignore">
252 [% IF ( can_commit ) %]
253 <fieldset class="action"><input type="submit" value="Apply different matching rules" class="button" /></fieldset>
256 </fieldset> <!-- /#staged-record-matching-rules -->
259 [% IF ( can_commit ) %]
260 <form method="post" id="import_batch_form">
261 <input type="hidden" name="op" value="commit-batch" />
262 <input type="hidden" name="runinbackground" value="" />
263 <input type="hidden" name="completedJobID" value="" />
264 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
265 <fieldset class="action">
266 [% IF ( record_type != 'auth' ) %]
267 Add new bibliographic records into this framework:
268 <select name="framework" id="frameworks">
269 <option value="">Default</option>
270 [% FOREACH framework IN frameworks %]
271 <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
276 <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
278 </form> <!-- /#import_batch_form -->
280 <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
281 <div id="jobfailed"></div>
283 [% END # /IF can_commit %]
284 [% IF ( can_revert ) %]
285 <form method="post" id="revert_batch_form">
286 <input type="hidden" name="op" value="revert-batch" />
287 <input type="hidden" name="runinbackground" value="" />
288 <input type="hidden" name="completedJobID" value="" />
289 <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" />
290 <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" /></fieldset>
293 <div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
294 <div id="jobfailed"></div>
296 [% END # /IF can_revert %]
300 [% END # /IF batch_info %]
302 <br style="clear:both;" />
304 [% IF ( batch_list ) %]
306 [% PROCESS pagination %]
322 [% FOREACH batch_lis IN batch_list %]
324 <td>[% batch_lis.import_batch_id | html %]</td>
325 <td><a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td>
326 <td>[% batch_lis.profile | html %]</td>
327 <td>[% batch_lis.comments | html %]</td>
328 <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
330 [% IF ( batch_lis.import_status == 'cleaned' ) %]
332 [% ELSIF ( batch_lis.import_status == 'imported' ) %]
333 <span>Imported</span>
334 [% ELSIF ( batch_lis.import_status == 'importing' ) %]
335 <span>Importing</span>
336 [% ELSIF ( batch_lis.import_status == 'reverted' ) %]
337 <span>Reverted</span>
338 [% ELSIF ( batch_lis.import_status == 'reverting' ) %]
339 <span>Reverting</span>
340 [% ELSIF ( batch_lis.import_status == 'staged' ) %]
343 <span>[% batch_lis.import_status | html %]</span>
346 <td>[% batch_lis.upload_timestamp | $KohaDates with_hours=1 %]</td>
347 <td>[% batch_lis.num_records | html %]</td>
348 <td>[% batch_lis.num_items | html %]
349 [% IF ( batch_lis.num_items && batch_lis.import_status == 'imported' ) %]
350 (<a href="?import_batch_id=[% batch_lis.import_batch_id | uri %]&op=create_labels">Create label batch</a>)
354 [% IF ( batch_lis.can_clean ) %]
355 <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">
356 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
357 <input type="hidden" name="op" value="clean-batch" />
358 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-eraser"></i> Clean</button>
360 [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
361 <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">
362 <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id | html %]" />
363 <input type="hidden" name="op" value="delete-batch" />
364 <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</button>
369 [% END # /FOREACH batch_lis %]
373 [% PROCESS pagination %]
375 [% END # /IF batch_lis %]
377 [% IF import_batch_id && !did_clean %]
378 <table id="records-table">
385 <th>Match details</th>
386 <th><abbr title="Differences between the original bibliographic record and the imported">Diff</abbr></th>
392 <div id="marcPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
393 <div class="modal-dialog modal-wide">
394 <div class="modal-content">
395 <div class="modal-header">
396 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
397 <h3 id="marcPreviewLabel">MARC preview</h3>
399 <div class="modal-body">
400 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
402 <div class="modal-footer">
403 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
407 </div> <!-- /#marcPreview -->
408 [% END # /IF import_batch_id %]
411 </div> <!-- /.col-sm-10.col-sm-push-2 -->
412 <div class="col-sm-2 col-sm-pull-10">
414 [% INCLUDE 'tools-menu.inc' %]
416 </div> <!-- .col-sm-2.col-sm-pull-10 -->
417 </div> <!-- /.row -->
419 [% MACRO jsinclude BLOCK %]
420 [% Asset.js("js/tools-menu.js") | $raw %]
421 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
422 [% INCLUDE 'datatables.inc' %]
424 $(document).ready(function() {
425 $("#staged-record-matching-rules select").change(function() {
426 var str = $(this).attr("id");
427 $("#reset_" + str).parent().show();
429 $("a.reset").click(function() {
430 var str = $(this).attr("id");
431 str = str.replace("reset_", "")
432 $("#" + str + " option[selected='selected']").attr("selected", "selected");
433 $(this).parent().hide();
436 [% IF import_batch_id %]
437 $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
442 "sAjaxSource": 'batch_records_ajax.pl',
443 "sPaginationType": "full_numbers",
444 "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
446 { "mDataProp": "import_record_id" },
447 { "mDataProp": "citation" },
448 { "mDataProp": "status" },
449 { "mDataProp": "overlay_status" },
450 { "mDataProp": null, "sDefaultContent": "" },
451 { "mDataProp": null, "sDefaultContent": "" },
452 { "mDataProp": "matched" }
454 "fnServerData": function(sSource, aoData, fnCallback) {
455 aoData.push({ "name": "import_batch_id", "value": [% import_batch_id | html %] });
462 'success': function(json) {
467 "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
468 [% IF(record_type == 'auth') %]
469 var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
471 var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
473 [% IF(record_type == 'auth') %]
474 var record_edit_url = "/cgi-bin/koha/authorities/authorities.pl?authid=";
476 var record_edit_url = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=";
479 var additional_details = "";
480 if( aData['author'] ){
481 additional_details += " " + aData['author'] + " ";
485 additional_details += " (" + aData['isbn'] + ") ";
489 additional_details += " (" + aData['issn'] + ") ";
492 $('td:eq(1)', nRow).html(
493 '<a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=' + aData['import_record_id'] + '&viewas=html" class="previewMARC">' + aData['citation'] + '</a> ' + additional_details
496 $('td:eq(2)', nRow).html(
497 aData['status'] == 'imported' ? _("Imported") :
498 aData['status'] == 'ignored' ? _("Ignored") :
499 aData['status'] == 'reverted' ? _("Reverted") :
500 aData['status'] == 'staged' ? _("Staged") :
501 aData['status'] == 'error' ? _("Error") :
505 $('td:eq(3)', nRow).html(
506 aData['overlay_status'] == 'no_match' ? _("No match") :
507 aData['overlay_status'] == 'match_applied' ? _("Match applied") :
508 aData['overlay_status'] == 'auto_match' ? _("Match found") :
509 aData['overlay_status']
512 if ( aData['matches'].length > 0 ) {
515 $('td:eq(4)', nRow).html('<ul class="matches"></ul>');
516 $('td:eq(5)', nRow).html('<ul class="matches"></ul>');
519 if( aData['status'] == "imported" || aData['status'] == "ignored" ){
520 disabled = ' disabled ';
522 aData['matches'].forEach(function(item,index){
523 if( item.chosen == 1 ){
524 checked = 'checked="checked"';
527 [% IF(item.record_type == 'auth') -%]
528 var matching_msg = _("Matches authority %s (score=%s):%s");
530 var matching_msg = _("Matches bibliographic record %s (score=%s):%s");
532 var match_option = "";
533 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 + '> ';
535 var diff_url = '/cgi-bin/koha/tools/showdiffmarc.pl?batchid=%s&importid=%s&id=%s&type=%s';
536 var match_citation = '';
537 if( item.title ){ match_citation += item.title + ' ' }
538 if( item.author ){ match_citation += item.author }
539 $('td:eq(4) ul', nRow).append('<li><label for="import_record_id_'+aData['import_record_id']+'_match_'+index+'">'+match_option+
540 matching_msg.format(item.candidate_match_id, item.score,
541 '<a target="_blank" href="' + record_details_url
542 + item.candidate_match_id + '">' + match_citation + '</a></label></li>')
544 $('td:eq(5) ul', nRow).append('<li><a href="'
545 + diff_url.format( [% import_batch_id | html %], aData['import_record_id'], item.candidate_match_id, item.record_type) + '">' + _("View") + '</a></li>');
548 if( !any_checked ){ checked = 'checked="checked"'; }
549 $('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>');
550 $('td:eq(5) ul', nRow).prepend('<li> </li>');
552 if (aData['diff_url']) {
553 $('td:eq(5)', nRow).html(
554 '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
557 if (aData['matched']) {
558 $('td:eq(6)', nRow).html(
559 '<a class="btn btn-default btn-xs" target="_blank" href="' + record_details_url
560 + aData['matched'] + '"><i class="fa fa-eye"></i> ' + _("View") + '</a> '
561 [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
562 + '<a class="btn btn-default btn-xs" target="_blank" href="' + record_edit_url
563 + aData['matched'] + '"><i class="fa fa-pencil"></i> ' + _("Edit") + '</a>'
569 $("#import_batch_form").on("submit", function() {
570 return submitBackgroundJob(document.getElementById("import_batch_form"));
572 $("#revert_batch_form").on("submit", function() {
573 return confirm(_("Are you sure you want to undo the import of this batch into the catalog?")) && submitBackgroundJob(document.getElementById("revert_batch_form"));
577 $("body").on("change", ".chosen", function(e) {
578 let apimethod = "DELETE";
580 if( $(this).val() != 'none' ){
582 apidata = JSON.stringify({ candidate_match_id: $(this).val() });
585 url: '/api/v1/import_batches/[% import_batch_id | html %]/records/'+$(this).data('import_record_id')+'/matches/chosen',
588 contentType: 'application/json'
589 }).fail(function(){ alert(_("Unable to update match choices")); return false; });
592 $("body").on("click", ".previewMARC", function(e) {
594 var ltitle = $(this).text();
595 var page = $(this).attr("href");
596 $("#marcPreviewLabel").text(ltitle);
597 $("#marcPreview .modal-body").load(page + " table");
598 $('#marcPreview').modal({ show: true });
600 $("#marcPreview").on("hidden.bs.modal", function() {
601 $("#marcPreviewLabel").html("");
602 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + _("Loading") + "</div>");
604 $(".batch_form").on("submit", function() {
605 if ($(this).hasClass("batch_delete")) {
606 return confirm(_("Are you sure you want to permanently delete this batch?"));
608 return confirm(_("Clear all reservoir records staged in this batch? This cannot be undone."));
615 [% INCLUDE 'intranet-bottom.inc' %]
616 [% BLOCK pagination %]
618 <ul class="pagination">
619 [% FOREACH page IN pages %]
620 [% IF ( page.current_page && page.page_number > 1 ) %]
621 <li><a href="?offset=0" class="nav"><i class="fa fa-fw fa-angle-double-left"></i> First</a></li>
622 <li><a href="?offset=[% offset - results_per_page | uri %]"><i class="fa fa-fw fa-angle-left"></i> Previous</a></li>
625 [% FOREACH page IN pages %]
626 [% IF ( page.current_page ) %]
627 [% SET current_page = page.page_number %]
628 <li class="active"><span class="current">[% page.page_number | html %]</span></li>
630 <li><a class="nav" href="?offset=[% page.offset | uri %]">[% page.page_number | html %]</a></li>
633 [% IF ( current_page < pages.size() ) %]
635 <a href="?offset=[% offset + results_per_page | uri %]" class="nav">Next <i class="fa fa-fw fa-angle-right"></i></a>
638 <a href="?offset=[% ( results_per_page * ( pages.size - 1 ) ) | uri %]" class="nav">Last <i class="fa fa-fw fa-angle-double-right"></i></a>