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 <h1>Stage MARC records for import</h1>
59 [% IF ( uploadmarc ) %]
60 <p>MARC staging results :</p>
62 [% SWITCH (record_type) %]
64 <li>Processing bibliographic records</li>
66 <li>Processing authority records</li>
68 <li>[% total | html %] records in file</li>
69 <li>[% import_errors | html %] records not staged because of MARC error</li>
70 <li>[% staged | html %] records staged</li>
71 [% IF ( checked_matches ) %]
72 <li>[% matched | html %] records with at least one match in catalog per matching rule
73 "[% matcher_code | html %]"</li>
75 [% IF ( matcher_failed ) %]
76 <li>Record matching failed -- unable to retrieve selected matching rule.</li>
78 <li>Did not check for matches with existing records in catalog</li>
81 [% IF record_type == 'biblio' %]
82 <li>[% num_items | html %] item records found and staged</li>
84 [% IF ( label_batch ) %]
85 <li>New label batch created: # [% label_batch | html %] </li>
88 [% IF basketno && booksellerid %]
90 <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>
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' %]
240 <fieldset class="action">
241 <input type="button" id="mainformsubmit" value="Stage for import" />
242 <button id="add_profile" disabled>Save profile</button>
243 <input type="text" id="profile_name" name="profile_name" placeholder="Profile name"/>
244 <button id="del_profile" disabled>Remove profile</button>
247 <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
248 <div id="jobfailed"></div></div>
254 </div> <!-- /.col-sm-10.col-sm-push-2 -->
256 <div class="col-sm-2 col-sm-pull-10">
258 [% INCLUDE 'tools-menu.inc' %]
260 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
261 </div> <!-- /.row -->
263 [% MACRO jsinclude BLOCK %]
264 [% Asset.js("js/tools-menu.js") | $raw %]
265 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
266 [% Asset.js("js/background-job-progressbar.js") | $raw %]
267 [% Asset.js("js/file-upload.js") | $raw %]
270 var PROFILE_SAVE_MSG = _("Profile saved");
271 var PROFILE_DEL_MSG = _("Profile deleted");
272 $(document).ready(function(){
273 $("#processfile").hide();
274 $('#profile_fieldset').hide();
275 $("#record_type").change(function() {
276 if ($(this).val() == 'auth') {
282 $("#fileuploadbutton").on("click",function(e){
286 $("#fileuploadcancel").on("click",function(e){
290 $("#mainformsubmit").on("click",function(){
291 return CheckForm( document.getElementById("processfile"));
294 $('#profile').change(function(){
296 $("#mod_profile, #del_profile").prop("disabled",true);
297 $("#profile_id").val("");
298 $("#comments").val("");
299 $("#record_type").val('biblio').change();
300 $("#encoding").val('UTF-8').change();
301 $("#format").val('ISO2709').change();
302 $("#marc_modification_template_id").val("").change();
303 $("#matcher").val("").change();
304 $("#overlay_action").val('replace').change();
305 $("#nomatch_action").val('create_new').change();
306 $("#parse_itemsyes").prop("checked", true).change();
307 $("#item_action").val('always_add').change();
308 $("#profile_name").val('').keyup();
310 const profile = $('option:selected', this).data('profile');
311 $("#profile_id").val(profile.profile_id);
312 $("#mod_profile, #del_profile").prop("disabled", null);
313 $("#comments").val(profile.comments);
314 $("#record_type").val(profile.record_type).change();
315 $("#encoding").val(profile.encoding).change();
316 $("#format").val(profile.format).change();
317 $("#marc_modification_template_id").val(profile.template_id).change();
318 $("#matcher").val(profile.matcher_id).change();
319 $("#overlay_action").val(profile.overlay_action).change();
320 $("#nomatch_action").val(profile.nomatch_action).change();
321 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
322 $("#item_action").val(profile.item_action).change();
323 $("#profile_name").val(profile.name).keyup();
327 $("#profile_name").keyup(function(){
328 $("#add_profile").prop("disabled", this.value.trim()=='');
331 $("#add_profile").click(function(event) {
332 event.preventDefault();
333 var name = $("#profile_name").val().trim();
335 alert(_("Profile must have a name"));
339 var profile = $("#profile option[value!='']")
341 return $(this).data('profile');
344 return this.name == name;
348 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
353 new Promise(function(resolve, reject) {
356 comments: $("#comments").val() || null,
357 record_type: $("#record_type").val() || null,
358 encoding: $("#encoding").val() || null,
359 format: $("#format").val() || null,
360 template_id: $("#marc_modification_template_id").val() || null,
361 matcher_id: $("#matcher").val() || null,
362 overlay_action: $("#overlay_action").val() || null,
363 nomatch_action: $("#nomatch_action").val() || null,
364 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
365 item_action: $("#item_action").val() || null,
371 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
373 data: JSON.stringify(params),
374 contentType: 'application/json'
380 url: "/api/v1/import_batch_profiles/",
382 data: JSON.stringify(params),
383 contentType: 'application/json'
389 .then(function(profile) {
390 humanMsg.displayAlert(PROFILE_SAVE_MSG);
391 return getProfiles(profile.profile_id);
393 .catch(function(error) {
394 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
398 $("#del_profile").click(function(event) {
399 event.preventDefault();
400 var id = $("#profile").val();
402 if(!confirm(_("Are you sure you want to delete this profile?"))) {
405 new Promise(function(resolve, reject) {
407 url: "/api/v1/import_batch_profiles/"+id,
414 humanMsg.displayAlert(PROFILE_DEL_MSG);
415 return getProfiles();
417 .catch(function(error) {
418 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
423 function CheckForm(f) {
424 if ($("#fileToUpload").value == '') {
425 alert(_("Please upload a file first."));
427 return submitBackgroundJob(f);
431 function StartUpload() {
432 if( $('#fileToUpload').prop('files').length == 0 ) return;
433 $('#fileuploadbutton').hide();
434 $("#fileuploadfailed").hide();
435 $("#processfile").hide();
436 $('#profile_fieldset').hide();
437 $("#fileuploadstatus").show();
438 $("#uploadedfileid").val('');
439 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
440 $("#fileuploadcancel").show();
442 function CancelUpload() {
443 if( xhr ) xhr.abort();
444 $("#fileuploadstatus").hide();
445 $('#fileuploadbutton').show();
446 $("#fileuploadcancel").hide();
447 $("#fileuploadfailed").show();
448 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
450 function cbUpload( status, fileid, errors ) {
451 if( status=='done' ) {
452 $("#uploadedfileid").val( fileid );
453 $('#fileToUpload').prop('disabled',true);
454 $('#fileuploadbutton').prop('disabled',true);
455 $('#fileuploadbutton').show();
456 $("#fileuploadcancel").hide();
457 var filename=$('#fileToUpload').prop('files')[0].name;
458 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
459 $('#format').val('MARCXML');
461 $("#processfile").show();
462 $('#profile_fieldset').show();
464 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") ];
465 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
466 $('#fileuploadbutton').show();
467 $("#fileuploadcancel").hide();
468 $("#fileuploadstatus").hide();
469 $("#fileuploadfailed").show();
470 $("#fileuploadfailed").text( _("Upload status: ") +
471 ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
472 ( status=='denied'? _("Denied"): status ))
477 function getProfiles(id) {
478 const select = $("#profile");
479 $("option[value!='']", select).remove();
480 return new Promise(function(resolve, reject) {
481 $.ajax("/api/v1/import_batch_profiles")
482 .then(resolve, reject);
484 .then(function(profiles) {
485 profiles.forEach(function(profile) {
486 const opt = $("<option/>");
488 if(id && profile.profile_id == id) {
489 opt.prop('selected', true);
491 opt.attr("value", profile.profile_id);
492 opt.text(profile.name);
493 opt.data("profile", profile);
505 [% INCLUDE 'intranet-bottom.inc' %]