4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Stage MARC records for import › Tools › Koha</title>
6 [% INCLUDE 'doc-head-close.inc' %]
8 #fileuploadstatus,#fileuploadfailed,#fileuploadcancel,#jobpanel,#jobstatus,#jobfailed { display : none; }
11 [% Asset.css("css/humanmsg.css") | $raw %]
14 <body id="tools_stage-marc-import" class="tools">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'cat-search.inc' %]
18 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
21 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
24 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
27 [% IF ( uploadmarc ) %]
29 <a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>
32 <a href="#" aria-current="page">
38 <a href="#" aria-current="page">
39 Stage MARC records for import
46 <div class="main container-fluid">
48 <div class="col-sm-10 col-sm-push-2">
51 [% IF ( uploadmarc ) %]
52 <div id="toolbar" class="btn-toolbar">
53 <a class="btn btn-default" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
54 <a class="btn btn-default" href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% import_batch_id | html %]"><i class="fa fa-list-ul"></i> Manage staged records</a>
58 [% IF ( uploadmarc ) %]
59 <h1>MARC staging results</h1>
61 [% SWITCH (record_type) %]
63 <li>Processing bibliographic records</li>
65 <li>Processing authority records</li>
67 <li>[% total | html %] records in file</li>
68 <li>[% import_errors | html %] records not staged because of MARC error</li>
69 <li>[% staged | html %] records staged</li>
70 [% IF ( checked_matches ) %]
71 <li>[% matched | html %] records with at least one match in catalog per matching rule
72 "[% matcher_code | html %]"</li>
74 [% IF ( matcher_failed ) %]
75 <li>Record matching failed -- unable to retrieve selected matching rule.</li>
77 <li>Did not check for matches with existing records in catalog</li>
80 [% IF record_type == 'biblio' %]
81 <li>[% num_items | html %] item records found and staged</li>
83 [% IF ( label_batch ) %]
84 <li>New label batch created: # [% label_batch | html %] </li>
87 [% IF basketno && booksellerid %]
89 <a id="addtobasket" class="btn btn-default" href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=[% import_batch_id | html %]&basketno=[% basketno | html %]&booksellerid=[% booksellerid | html %]">Add staged files to basket</a>
93 <h1>Stage MARC records for import</h1>
95 <li>Select a MARC file to stage in the import reservoir. It will be parsed, and each valid record staged for later import into the catalog.</li>
96 <li>You can enter a name for this import. It may be useful, when creating a record, to remember where the suggested MARC data comes from!</li>
98 <form method="post" action="[% SCRIPT_NAME | html %]" id="uploadfile" enctype="multipart/form-data">
99 <fieldset class="rows" id="uploadform">
100 <legend>Upload a file to stage</legend>
103 <div id="fileuploadform">
104 <label for="fileToUpload">File: </label>
105 <input type="file" id="fileToUpload" name="fileToUpload" />
109 <fieldset class="action">
110 <button id="fileuploadbutton">Upload file</button>
111 <button id="fileuploadcancel">Cancel</button>
115 <div id="fileuploadpanel">
116 <div id="fileuploadstatus" class="progress_panel">Upload progress:
117 <progress id="fileuploadprogress" max="100" value="0">
119 <span class="fileuploadpercent">0</span>%
121 <div id="fileuploadfailed"></div>
125 <fieldset class="rows" id="profile_fieldset">
126 <legend>Pre-fill values with profile?</legend>
129 <label for="profile">Profile: </label>
130 <select name="profile" id="profile">
131 <option value="">Do not use profile</option>
133 <div class="hint">When you select a profile it pre-fills your form with profile values.</div>
134 <div class="hint">Later you can modify your form and that's what matters on import.</div>
139 <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
140 [% IF basketno && booksellerid %]
141 <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
142 <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
144 <input type="hidden" name="profile_id" id="profile_id"/>
145 <fieldset class="rows">
146 <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
147 <input type="hidden" name="runinbackground" id="runinbackground" value="" />
148 <input type="hidden" name="completedJobID" id="completedJobID" value="" />
149 <legend>Settings</legend>
151 <label for="comments">Comments about this file: </label>
152 <input type="text" id="comments" name="comments" />
156 <label for='record_type'>Record type:</label>
157 <select name='record_type' id='record_type'>
158 <option value='biblio' selected='selected'>Bibliographic</option>
159 <option value='auth'>Authority</option>
163 <label for="encoding">Character encoding: </label>
164 <select name="encoding" id="encoding">
165 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
166 <option value="MARC-8">MARC 8</option>
167 <option value="ISO_5426">ISO 5426</option>
168 <option value="ISO_6937">ISO 6937</option>
169 <option value="ISO_8859-1">ISO 8859-1</option>
170 <option value="EUC-KR">EUC-KR</option>
174 <label for='format'>Format:</label>
175 <select name='format' id='format'>
176 <option value='ISO2709'>MARC</option>
177 <option value='MARCXML'>MARCXML</option>
178 [% FOREACH p IN plugins %]
179 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
185 [% IF MarcModificationTemplatesLoop %]
186 <fieldset class="rows">
187 <legend>Modify records using a MARC modification template?</legend>
190 <label for="comments">Template: </label>
191 <select name="marc_modification_template_id" id="marc_modification_template_id">
192 <option value="">Do not use template</option>
193 [% FOREACH mmt IN MarcModificationTemplatesLoop %]
194 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
202 <fieldset class="rows">
203 <legend>Look for existing records in catalog?</legend>
204 <ol><li><label for="matcher">Record matching rule:</label>
205 <select name="matcher" id="matcher">
206 <option value="">Do not look for matching records</option>
207 [% FOREACH available_matcher IN available_matchers %]
208 <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
213 <li><label for="overlay_action">Action if matching record found: </label>
214 [% INCLUDE 'tools-overlay-action.inc' %]
216 <li><label for="nomatch_action">Action if no match is found: </label>
217 [% INCLUDE 'tools-nomatch-action.inc' %]
221 <fieldset class="rows" id="items">
222 <legend>Check for embedded item record data?</legend>
225 <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
226 <label for="parse_itemsyes">Yes</label>
229 <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
230 <label for="parse_itemsno">No (If you do not check for items while staging you may not change this option later)
235 <li><label for="item_action">How to process items: </label>
236 [% INCLUDE 'tools-item-action.inc' %]
241 <fieldset class="rows" id="save_profile">
242 <legend>Save profile</legend>
245 <label for="profile_name">Profile name:</label>
246 <input type="text" id="profile_name" name="profile_name" />
247 <button class="btn btn-default btn-xs" id="add_profile" disabled>Save profile</button>
248 <button class="btn btn-link" id="del_profile" disabled><i class="fa fa-trash"></i> <span>Remove profile</span></button>
253 <fieldset class="action">
254 <input type="button" id="mainformsubmit" value="Stage for import" />
257 <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
258 <div id="jobfailed"></div></div>
264 </div> <!-- /.col-sm-10.col-sm-push-2 -->
266 <div class="col-sm-2 col-sm-pull-10">
268 [% INCLUDE 'tools-menu.inc' %]
270 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
271 </div> <!-- /.row -->
273 [% MACRO jsinclude BLOCK %]
274 [% Asset.js("js/tools-menu.js") | $raw %]
275 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
276 [% Asset.js("js/background-job-progressbar.js") | $raw %]
277 [% Asset.js("js/file-upload.js") | $raw %]
280 var PROFILE_SAVE_MSG = _("Profile saved");
281 var PROFILE_DEL_MSG = _("Profile deleted");
282 $(document).ready(function(){
283 $("#processfile").hide();
284 $('#profile_fieldset').hide();
285 $("#record_type").change(function() {
286 if ($(this).val() == 'auth') {
292 $("#fileuploadbutton").on("click",function(e){
296 $("#fileuploadcancel").on("click",function(e){
300 $("#mainformsubmit").on("click",function(){
301 return CheckForm( document.getElementById("processfile"));
304 $('#profile').change(function(){
306 $("#mod_profile, #del_profile").prop("disabled",true);
307 $("#profile_id").val("");
308 $("#comments").val("");
309 $("#record_type").val('biblio').change();
310 $("#encoding").val('UTF-8').change();
311 $("#format").val('ISO2709').change();
312 $("#marc_modification_template_id").val("").change();
313 $("#matcher").val("").change();
314 $("#overlay_action").val('replace').change();
315 $("#nomatch_action").val('create_new').change();
316 $("#parse_itemsyes").prop("checked", true).change();
317 $("#item_action").val('always_add').change();
318 $("#profile_name").val('').keyup();
319 $("#del_profile span").text( _("Remove profile") );
321 const profile = $('option:selected', this).data('profile');
322 $("#profile_id").val(profile.profile_id);
323 $("#mod_profile, #del_profile").prop("disabled", null);
324 $("#del_profile span").text( _("Remove profile") + ": " + profile.name );
325 $("#comments").val(profile.comments);
326 $("#record_type").val(profile.record_type).change();
327 $("#encoding").val(profile.encoding).change();
328 $("#format").val(profile.format).change();
329 $("#marc_modification_template_id").val(profile.template_id).change();
330 $("#matcher").val(profile.matcher_id).change();
331 $("#overlay_action").val(profile.overlay_action).change();
332 $("#nomatch_action").val(profile.nomatch_action).change();
333 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
334 $("#item_action").val(profile.item_action).change();
335 $("#profile_name").val(profile.name).keyup();
339 $("#profile_name").on("change keyup", function(){
340 $("#add_profile").prop("disabled", this.value.trim()=='');
343 $("#add_profile").click(function(event) {
344 event.preventDefault();
345 var name = $("#profile_name").val().trim();
347 alert(_("Profile must have a name"));
351 var profile = $("#profile option[value!='']")
353 return $(this).data('profile');
356 return this.name == name;
360 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
365 new Promise(function(resolve, reject) {
368 comments: $("#comments").val() || null,
369 record_type: $("#record_type").val() || null,
370 encoding: $("#encoding").val() || null,
371 format: $("#format").val() || null,
372 template_id: $("#marc_modification_template_id").val() || null,
373 matcher_id: $("#matcher").val() || null,
374 overlay_action: $("#overlay_action").val() || null,
375 nomatch_action: $("#nomatch_action").val() || null,
376 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
377 item_action: $("#item_action").val() || null,
383 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
385 data: JSON.stringify(params),
386 contentType: 'application/json'
392 url: "/api/v1/import_batch_profiles/",
394 data: JSON.stringify(params),
395 contentType: 'application/json'
401 .then(function(profile) {
402 humanMsg.displayAlert(PROFILE_SAVE_MSG);
403 return getProfiles(profile.profile_id);
405 .catch(function(error) {
406 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
410 $("#del_profile").click(function(event) {
411 event.preventDefault();
412 var id = $("#profile").val();
414 if(!confirm(_("Are you sure you want to delete this profile?"))) {
417 new Promise(function(resolve, reject) {
419 url: "/api/v1/import_batch_profiles/"+id,
426 humanMsg.displayAlert(PROFILE_DEL_MSG);
427 return getProfiles();
429 .catch(function(error) {
430 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
435 function CheckForm(f) {
436 if ($("#fileToUpload").value == '') {
437 alert(_("Please upload a file first."));
439 return submitBackgroundJob(f);
443 function StartUpload() {
444 if( $('#fileToUpload').prop('files').length == 0 ) return;
445 $('#fileuploadbutton').hide();
446 $("#fileuploadfailed").hide();
447 $("#processfile").hide();
448 $('#profile_fieldset').hide();
449 $("#fileuploadstatus").show();
450 $("#uploadedfileid").val('');
451 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
452 $("#fileuploadcancel").show();
454 function CancelUpload() {
455 if( xhr ) xhr.abort();
456 $("#fileuploadstatus").hide();
457 $('#fileuploadbutton').show();
458 $("#fileuploadcancel").hide();
459 $("#fileuploadfailed").show();
460 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
462 function cbUpload( status, fileid, errors ) {
463 if( status=='done' ) {
464 $("#uploadedfileid").val( fileid );
465 $('#fileToUpload').prop('disabled',true);
466 $('#fileuploadbutton').prop('disabled',true);
467 $('#fileuploadbutton').show();
468 $("#fileuploadcancel").hide();
469 var filename=$('#fileToUpload').prop('files')[0].name;
470 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
471 $('#format').val('MARCXML');
473 $("#processfile").show();
474 $('#profile_fieldset').show();
476 var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ];
477 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
478 $('#fileuploadbutton').show();
479 $("#fileuploadcancel").hide();
480 $("#fileuploadstatus").hide();
481 $("#fileuploadfailed").show();
482 $("#fileuploadfailed").text( _("Upload status: ") +
483 ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
484 ( status=='denied'? _("Denied"): status ))
489 function getProfiles(id) {
490 const select = $("#profile");
491 $("option[value!='']", select).remove();
492 return new Promise(function(resolve, reject) {
493 $.ajax("/api/v1/import_batch_profiles")
494 .then(resolve, reject);
496 .then(function(profiles) {
497 profiles.sort( function(a, b) {
498 return a.name.localeCompare(b.name);
500 profiles.forEach(function(profile) {
501 const opt = $("<option/>");
503 if(id && profile.profile_id == id) {
504 opt.prop('selected', true);
506 opt.attr("value", profile.profile_id);
507 opt.text(profile.name);
508 opt.data("profile", profile);
520 [% INCLUDE 'intranet-bottom.inc' %]