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 [% FOREACH message IN messages %]
52 [% IF message.type == 'success' %]
53 <div class="dialog message">
54 [% ELSIF message.type == 'warning' %]
55 <div class="dialog alert">
56 [% ELSIF message.type == 'error' %]
57 <div class="dialog alert" style="margin:auto;">
59 [% IF message.code == 'cannot_enqueue_job' %]
60 <span>Cannot enqueue this job.</span>
62 [% IF message.error %]
63 <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
69 <div id="toolbar" class="btn-toolbar">
70 <a class="btn btn-default" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
71 <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>
75 <div class="dialog message">
76 <p>The job has been enqueued! It will be processed as soon as possible.</p>
77 <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>
80 <h1>Stage MARC records for import</h1>
82 <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>
83 <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>
85 <form method="post" id="uploadfile" enctype="multipart/form-data">
86 <fieldset class="rows" id="uploadform">
87 <legend>Upload a file to stage</legend>
90 <div id="fileuploadform">
91 <label for="fileToUpload">File: </label>
92 <input type="file" id="fileToUpload" name="fileToUpload" />
96 <fieldset class="action">
97 <button id="fileuploadbutton">Upload file</button>
98 <button id="fileuploadcancel">Cancel</button>
102 <div id="fileuploadpanel">
103 <div id="fileuploadstatus" class="progress_panel">Upload progress:
104 <progress id="fileuploadprogress" max="100" value="0">
106 <span class="fileuploadpercent">0</span>%
108 <div id="fileuploadfailed"></div>
112 <fieldset class="rows" id="profile_fieldset">
113 <legend>Pre-fill values with profile?</legend>
116 <label for="profile">Profile: </label>
117 <select name="profile" id="profile">
118 <option value="">Do not use profile</option>
120 <div class="hint">When you select a profile it pre-fills your form with profile values.</div>
121 <div class="hint">Later you can modify your form and that's what matters on import.</div>
126 <form method="post" id="processfile" enctype="multipart/form-data">
127 [% IF basketno && booksellerid %]
128 <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
129 <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
131 <input type="hidden" name="profile_id" id="profile_id"/>
132 <fieldset class="rows">
133 <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
134 <input type="hidden" name="runinbackground" id="runinbackground" value="" />
135 <input type="hidden" name="completedJobID" id="completedJobID" value="" />
136 <legend>Settings</legend>
138 <label for="comments">Comments about this file: </label>
139 <input type="text" id="comments" name="comments" />
143 <label for='record_type'>Record type:</label>
144 <select name='record_type' id='record_type'>
145 <option value='biblio' selected='selected'>Bibliographic</option>
146 <option value='auth'>Authority</option>
150 <label for="encoding">Character encoding: </label>
151 <select name="encoding" id="encoding">
152 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
153 <option value="MARC-8">MARC 8</option>
154 <option value="ISO_5426">ISO 5426</option>
155 <option value="ISO_6937">ISO 6937</option>
156 <option value="ISO_8859-1">ISO 8859-1</option>
157 <option value="EUC-KR">EUC-KR</option>
161 <label for='format'>Format:</label>
162 <select name='format' id='format'>
163 <option value='ISO2709'>MARC</option>
164 <option value='MARCXML'>MARCXML</option>
165 [% FOREACH p IN plugins %]
166 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
172 [% IF MarcModificationTemplatesLoop %]
173 <fieldset class="rows">
174 <legend>Modify records using a MARC modification template?</legend>
177 <label for="comments">Template: </label>
178 <select name="marc_modification_template_id" id="marc_modification_template_id">
179 <option value="">Do not use template</option>
180 [% FOREACH mmt IN MarcModificationTemplatesLoop %]
181 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
189 <fieldset class="rows">
190 <legend>Look for existing records in catalog?</legend>
191 <ol><li><label for="matcher">Record matching rule:</label>
192 <select name="matcher" id="matcher">
193 <option value="">Do not look for matching records</option>
194 [% FOREACH available_matcher IN available_matchers %]
195 <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
200 <li><label for="overlay_action">Action if matching record found: </label>
201 [% INCLUDE 'tools-overlay-action.inc' %]
203 <li><label for="nomatch_action">Action if no match is found: </label>
204 [% INCLUDE 'tools-nomatch-action.inc' %]
208 <fieldset class="rows" id="items">
209 <legend>Check for embedded item record data?</legend>
212 <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
213 <label for="parse_itemsyes">Yes</label>
216 <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
217 <label for="parse_itemsno">No (If you do not check for items while staging you may not change this option later)
222 <li><label for="item_action">How to process items: </label>
223 [% INCLUDE 'tools-item-action.inc' %]
228 <fieldset class="rows" id="save_profile">
229 <legend>Save profile</legend>
232 <label for="profile_name">Profile name:</label>
233 <input type="text" id="profile_name" name="profile_name" />
234 <button class="btn btn-default btn-xs" id="add_profile" disabled>Save profile</button>
235 <button class="btn btn-link" id="del_profile" disabled><i class="fa fa-trash"></i> <span>Remove profile</span></button>
240 <fieldset class="action">
241 <input type="button" id="mainformsubmit" value="Stage for import" />
248 </div> <!-- /.col-sm-10.col-sm-push-2 -->
250 <div class="col-sm-2 col-sm-pull-10">
252 [% INCLUDE 'tools-menu.inc' %]
254 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
255 </div> <!-- /.row -->
257 [% MACRO jsinclude BLOCK %]
258 [% Asset.js("js/tools-menu.js") | $raw %]
259 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
260 [% Asset.js("js/file-upload.js") | $raw %]
263 var PROFILE_SAVE_MSG = _("Profile saved");
264 var PROFILE_DEL_MSG = _("Profile deleted");
265 $(document).ready(function(){
266 $("#processfile").hide();
267 $('#profile_fieldset').hide();
268 $("#record_type").change(function() {
269 if ($(this).val() == 'auth') {
275 $("#fileuploadbutton").on("click",function(e){
279 $("#fileuploadcancel").on("click",function(e){
283 $("#mainformsubmit").on("click",function(e){
285 if ($("#fileToUpload").value == '') {
286 alert(_("Please upload a file first."));
289 $("#processfile").submit();
295 $('#profile').change(function(){
297 $("#mod_profile, #del_profile").prop("disabled",true);
298 $("#profile_id").val("");
299 $("#comments").val("");
300 $("#record_type").val('biblio').change();
301 $("#encoding").val('UTF-8').change();
302 $("#format").val('ISO2709').change();
303 $("#marc_modification_template_id").val("").change();
304 $("#matcher").val("").change();
305 $("#overlay_action").val('replace').change();
306 $("#nomatch_action").val('create_new').change();
307 $("#parse_itemsyes").prop("checked", true).change();
308 $("#item_action").val('always_add').change();
309 $("#profile_name").val('').keyup();
310 $("#del_profile span").text( _("Remove profile") );
312 const profile = $('option:selected', this).data('profile');
313 $("#profile_id").val(profile.profile_id);
314 $("#mod_profile, #del_profile").prop("disabled", null);
315 $("#del_profile span").text( _("Remove profile") + ": " + profile.name );
316 $("#comments").val(profile.comments);
317 $("#record_type").val(profile.record_type).change();
318 $("#encoding").val(profile.encoding).change();
319 $("#format").val(profile.format).change();
320 $("#marc_modification_template_id").val(profile.template_id).change();
321 $("#matcher").val(profile.matcher_id).change();
322 $("#overlay_action").val(profile.overlay_action).change();
323 $("#nomatch_action").val(profile.nomatch_action).change();
324 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
325 $("#item_action").val(profile.item_action).change();
326 $("#profile_name").val(profile.name).keyup();
330 $("#profile_name").on("change keyup", function(){
331 $("#add_profile").prop("disabled", this.value.trim()=='');
334 $("#add_profile").click(function(event) {
335 event.preventDefault();
336 var name = $("#profile_name").val().trim();
338 alert(_("Profile must have a name"));
342 var profile = $("#profile option[value!='']")
344 return $(this).data('profile');
347 return this.name == name;
351 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
356 new Promise(function(resolve, reject) {
359 comments: $("#comments").val() || null,
360 record_type: $("#record_type").val() || null,
361 encoding: $("#encoding").val() || null,
362 format: $("#format").val() || null,
363 template_id: $("#marc_modification_template_id").val() || null,
364 matcher_id: $("#matcher").val() || null,
365 overlay_action: $("#overlay_action").val() || null,
366 nomatch_action: $("#nomatch_action").val() || null,
367 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
368 item_action: $("#item_action").val() || null,
374 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
376 data: JSON.stringify(params),
377 contentType: 'application/json'
383 url: "/api/v1/import_batch_profiles/",
385 data: JSON.stringify(params),
386 contentType: 'application/json'
392 .then(function(profile) {
393 humanMsg.displayAlert(PROFILE_SAVE_MSG);
394 return getProfiles(profile.profile_id);
396 .catch(function(error) {
397 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
401 $("#del_profile").click(function(event) {
402 event.preventDefault();
403 var id = $("#profile").val();
405 if(!confirm(_("Are you sure you want to delete this profile?"))) {
408 new Promise(function(resolve, reject) {
410 url: "/api/v1/import_batch_profiles/"+id,
417 humanMsg.displayAlert(PROFILE_DEL_MSG);
418 return getProfiles();
420 .catch(function(error) {
421 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
426 function StartUpload() {
427 if( $('#fileToUpload').prop('files').length == 0 ) return;
428 $('#fileuploadbutton').hide();
429 $("#fileuploadfailed").hide();
430 $("#processfile").hide();
431 $('#profile_fieldset').hide();
432 $("#fileuploadstatus").show();
433 $("#uploadedfileid").val('');
434 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
435 $("#fileuploadcancel").show();
437 function CancelUpload() {
438 if( xhr ) xhr.abort();
439 $("#fileuploadstatus").hide();
440 $('#fileuploadbutton').show();
441 $("#fileuploadcancel").hide();
442 $("#fileuploadfailed").show();
443 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
445 function cbUpload( status, fileid, errors ) {
446 if( status=='done' ) {
447 $("#uploadedfileid").val( fileid );
448 $('#fileToUpload').prop('disabled',true);
449 $('#fileuploadbutton').prop('disabled',true);
450 $('#fileuploadbutton').show();
451 $("#fileuploadcancel").hide();
452 var filename=$('#fileToUpload').prop('files')[0].name;
453 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
454 $('#format').val('MARCXML');
456 $("#processfile").show();
457 $('#profile_fieldset').show();
459 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") ];
460 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
461 $('#fileuploadbutton').show();
462 $("#fileuploadcancel").hide();
463 $("#fileuploadstatus").hide();
464 $("#fileuploadfailed").show();
465 $("#fileuploadfailed").text( _("Upload status: ") +
466 ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
467 ( status=='denied'? _("Denied"): status ))
472 function getProfiles(id) {
473 const select = $("#profile");
474 $("option[value!='']", select).remove();
475 return new Promise(function(resolve, reject) {
476 $.ajax("/api/v1/import_batch_profiles")
477 .then(resolve, reject);
479 .then(function(profiles) {
480 profiles.sort( function(a, b) {
481 return a.name.localeCompare(b.name);
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' %]