4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha › Tools › Stage MARC records for import</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>Stage records into the reservoir</legend>
103 <div id="fileuploadform">
104 <label for="fileToUpload">Select the file to stage: </label>
105 <input type="file" id="fileToUpload" name="fileToUpload" />
108 <fieldset class="action">
109 <button id="fileuploadbutton">Upload file</button>
110 <button id="fileuploadcancel">Cancel</button>
114 <div id="fileuploadpanel">
115 <div id="fileuploadstatus" class="progress_panel">Upload progress:
116 <progress id="fileuploadprogress" max="100" value="0">
118 <span class="fileuploadpercent">0</span>%
120 <div id="fileuploadfailed"></div>
124 <fieldset class="rows" id="profile_fieldset">
125 <legend>Profile settings</legend>
128 <label for="profile">Pre-fill values with profile</label>
129 <select name="profile" id="profile">
130 <option value="">Do not use profile</option>
132 <div class="hint">When you select a profile it pre-fills your form with profile values.</div>
133 <div class="hint">Later you can modify your form and that's what matters on import.</div>
138 <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
139 [% IF basketno && booksellerid %]
140 <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
141 <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
143 <input type="hidden" name="profile_id" id="profile_id"/>
144 <fieldset class="rows">
145 <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
146 <input type="hidden" name="runinbackground" id="runinbackground" value="" />
147 <input type="hidden" name="completedJobID" id="completedJobID" value="" />
149 <label for="comments">Comments about this file: </label>
150 <input type="text" id="comments" name="comments" />
154 <label for='record_type'>Record type:</label>
155 <select name='record_type' id='record_type'>
156 <option value='biblio' selected='selected'>Bibliographic</option>
157 <option value='auth'>Authority</option>
161 <label for="encoding">Character encoding: </label>
162 <select name="encoding" id="encoding">
163 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
164 <option value="MARC-8">MARC 8</option>
165 <option value="ISO_5426">ISO 5426</option>
166 <option value="ISO_6937">ISO 6937</option>
167 <option value="ISO_8859-1">ISO 8859-1</option>
168 <option value="EUC-KR">EUC-KR</option>
172 <label for='format'>Format:</label>
173 <select name='format' id='format'>
174 <option value='ISO2709'>MARC</option>
175 <option value='MARCXML'>MARCXML</option>
176 [% FOREACH p IN plugins %]
177 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
183 [% IF MarcModificationTemplatesLoop %]
184 <fieldset class="rows">
185 <legend>Use MARC Modification Template:</legend>
188 <label for="comments">Modify record using the following template: </label>
189 <select name="marc_modification_template_id" id="marc_modification_template_id">
190 <option value="">Do not use.</option>
191 [% FOREACH mmt IN MarcModificationTemplatesLoop %]
192 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
200 <fieldset class="rows">
201 <legend>Look for existing records in catalog?</legend>
202 <ol><li><label for="matcher">Record matching rule:</label>
203 <select name="matcher" id="matcher">
204 <option value="">Do not look for matching records</option>
205 [% FOREACH available_matcher IN available_matchers %]
206 <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
211 <li><label for="overlay_action">Action if matching record found: </label>
212 [% INCLUDE 'tools-overlay-action.inc' %]
214 <li><label for="nomatch_action">Action if no match is found: </label>
215 [% INCLUDE 'tools-nomatch-action.inc' %]
219 <fieldset class="rows" id="items">
220 <legend>Check for embedded item record data?</legend>
223 <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
224 <label for="parse_itemsyes">Yes</label>
227 <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
228 <label for="parse_itemsno">No (If you do not check for items while staging you may not change this option later)
233 <li><label for="item_action">How to process items: </label>
234 [% INCLUDE 'tools-item-action.inc' %]
238 <fieldset class="action">
239 <input type="button" id="mainformsubmit" value="Stage for import" />
240 <button id="add_profile" disabled>Save profile</button>
241 <input type="text" id="profile_name" name="profile_name" placeholder="Profile name"/>
242 <button id="del_profile" disabled>Remove profile</button>
245 <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
246 <div id="jobfailed"></div></div>
252 </div> <!-- /.col-sm-10.col-sm-push-2 -->
254 <div class="col-sm-2 col-sm-pull-10">
256 [% INCLUDE 'tools-menu.inc' %]
258 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
259 </div> <!-- /.row -->
261 [% MACRO jsinclude BLOCK %]
262 [% Asset.js("js/tools-menu.js") | $raw %]
263 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
264 [% Asset.js("js/background-job-progressbar.js") | $raw %]
265 [% Asset.js("js/file-upload.js") | $raw %]
268 var PROFILE_SAVE_MSG = _("Profile saved");
269 var PROFILE_DEL_MSG = _("Profile deleted");
270 $(document).ready(function(){
271 $("#processfile").hide();
272 $('#profile_fieldset').hide();
273 $("#record_type").change(function() {
274 if ($(this).val() == 'auth') {
280 $("#fileuploadbutton").on("click",function(e){
284 $("#fileuploadcancel").on("click",function(e){
288 $("#mainformsubmit").on("click",function(){
289 return CheckForm( document.getElementById("processfile"));
292 $('#profile').change(function(){
294 $("#mod_profile, #del_profile").prop("disabled",true);
295 $("#profile_id").val("");
296 $("#comments").val("");
297 $("#record_type").val('biblio').change();
298 $("#encoding").val('UTF-8').change();
299 $("#format").val('ISO2709').change();
300 $("#marc_modification_template_id").val("").change();
301 $("#matcher").val("").change();
302 $("#overlay_action").val('replace').change();
303 $("#nomatch_action").val('create_new').change();
304 $("#parse_itemsyes").prop("checked", true).change();
305 $("#item_action").val('always_add').change();
306 $("#profile_name").val('').keyup();
308 const profile = $('option:selected', this).data('profile');
309 $("#profile_id").val(profile.profile_id);
310 $("#mod_profile, #del_profile").prop("disabled", null);
311 $("#comments").val(profile.comments);
312 $("#record_type").val(profile.record_type).change();
313 $("#encoding").val(profile.encoding).change();
314 $("#format").val(profile.format).change();
315 $("#marc_modification_template_id").val(profile.template_id).change();
316 $("#matcher").val(profile.matcher_id).change();
317 $("#overlay_action").val(profile.overlay_action).change();
318 $("#nomatch_action").val(profile.nomatch_action).change();
319 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
320 $("#item_action").val(profile.item_action).change();
321 $("#profile_name").val(profile.name).keyup();
325 $("#profile_name").keyup(function(){
326 $("#add_profile").prop("disabled", this.value.trim()=='');
329 $("#add_profile").click(function(event) {
330 event.preventDefault();
331 var name = $("#profile_name").val().trim();
333 alert(_("Profile must have a name"));
337 var profile = $("#profile option[value!='']")
339 return $(this).data('profile');
342 return this.name == name;
346 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
351 new Promise(function(resolve, reject) {
354 comments: $("#comments").val() || null,
355 record_type: $("#record_type").val() || null,
356 encoding: $("#encoding").val() || null,
357 format: $("#format").val() || null,
358 template_id: $("#marc_modification_template_id").val() || null,
359 matcher_id: $("#matcher").val() || null,
360 overlay_action: $("#overlay_action").val() || null,
361 nomatch_action: $("#nomatch_action").val() || null,
362 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
363 item_action: $("#item_action").val() || null,
369 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
371 data: JSON.stringify(params),
372 contentType: 'application/json'
378 url: "/api/v1/import_batch_profiles/",
380 data: JSON.stringify(params),
381 contentType: 'application/json'
387 .then(function(profile) {
388 humanMsg.displayAlert(PROFILE_SAVE_MSG);
389 return getProfiles(profile.profile_id);
391 .catch(function(error) {
392 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
396 $("#del_profile").click(function(event) {
397 event.preventDefault();
398 var id = $("#profile").val();
400 if(!confirm(_("Are you sure you want to delete this profile?"))) {
403 new Promise(function(resolve, reject) {
405 url: "/api/v1/import_batch_profiles/"+id,
412 humanMsg.displayAlert(PROFILE_DEL_MSG);
413 return getProfiles();
415 .catch(function(error) {
416 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
421 function CheckForm(f) {
422 if ($("#fileToUpload").value == '') {
423 alert(_("Please upload a file first."));
425 return submitBackgroundJob(f);
429 function StartUpload() {
430 if( $('#fileToUpload').prop('files').length == 0 ) return;
431 $('#fileuploadbutton').hide();
432 $("#fileuploadfailed").hide();
433 $("#processfile").hide();
434 $('#profile_fieldset').hide();
435 $("#fileuploadstatus").show();
436 $("#uploadedfileid").val('');
437 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
438 $("#fileuploadcancel").show();
440 function CancelUpload() {
441 if( xhr ) xhr.abort();
442 $("#fileuploadstatus").hide();
443 $('#fileuploadbutton').show();
444 $("#fileuploadcancel").hide();
445 $("#fileuploadfailed").show();
446 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
448 function cbUpload( status, fileid, errors ) {
449 if( status=='done' ) {
450 $("#uploadedfileid").val( fileid );
451 $('#fileToUpload').prop('disabled',true);
452 $('#fileuploadbutton').prop('disabled',true);
453 $('#fileuploadbutton').show();
454 $("#fileuploadcancel").hide();
455 var filename=$('#fileToUpload').prop('files')[0].name;
456 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
457 $('#format').val('MARCXML');
459 $("#processfile").show();
460 $('#profile_fieldset').show();
462 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") ];
463 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
464 $('#fileuploadbutton').show();
465 $("#fileuploadcancel").hide();
466 $("#fileuploadstatus").hide();
467 $("#fileuploadfailed").show();
468 $("#fileuploadfailed").text( _("Upload status: ") +
469 ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
470 ( status=='denied'? _("Denied"): status ))
475 function getProfiles(id) {
476 const select = $("#profile");
477 $("option[value!='']", select).remove();
478 return new Promise(function(resolve, reject) {
479 $.ajax("/api/v1/import_batch_profiles")
480 .then(resolve, reject);
482 .then(function(profiles) {
483 profiles.forEach(function(profile) {
484 const opt = $("<option/>");
486 if(id && profile.profile_id == id) {
487 opt.prop('selected', true);
489 opt.attr("value", profile.profile_id);
490 opt.text(profile.name);
491 opt.data("profile", profile);
503 [% INCLUDE 'intranet-bottom.inc' %]