4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Stage MARC records for import › Cataloging › 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 [% WRAPPER 'header.inc' %]
16 [% INCLUDE 'cat-search.inc' %]
19 [% WRAPPER 'sub-header.inc' %]
20 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
23 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
26 <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</a>
29 [% IF ( uploadmarc ) %]
31 <a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>
34 <a href="#" aria-current="page">
40 <a href="#" aria-current="page">
41 Stage MARC records for import
49 <div class="main container-fluid">
51 <div class="col-sm-10 col-sm-push-2">
54 [% FOREACH message IN messages %]
55 [% IF message.type == 'success' %]
56 <div class="dialog message">
57 [% ELSIF message.type == 'warning' %]
58 <div class="dialog alert">
59 [% ELSIF message.type == 'error' %]
60 <div class="dialog alert" style="margin:auto;">
62 [% IF message.code == 'cannot_enqueue_job' %]
63 <span>Cannot enqueue this job.</span>
65 [% IF message.error %]
66 <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
72 <div id="toolbar" class="btn-toolbar">
73 <a class="btn btn-default" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
74 <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>
78 <div class="dialog message">
79 <p>The job has been enqueued! It will be processed as soon as possible.</p>
80 [% INCLUDE "job_progress.inc" job_id=job_id %]
81 <p><a class="job_details" 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>
82 <div id="job_callback"></div>
85 <h1>Stage MARC records for import</h1>
87 <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>
88 <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>
90 <form method="post" id="uploadfile" enctype="multipart/form-data">
91 <fieldset class="rows" id="uploadform">
92 <legend>Upload a file to stage</legend>
95 <div id="fileuploadform">
96 <label for="fileToUpload">File: </label>
97 <input type="file" id="fileToUpload" name="fileToUpload" />
102 <fieldset class="action">
103 <button id="fileuploadbutton" class="btn btn-primary">Upload file</button>
104 <button id="fileuploadcancel">Cancel</button>
107 <div id="fileuploadpanel">
108 <div id="fileuploadstatus" class="progress_panel">Upload progress:
109 <progress id="fileuploadprogress" max="100" value="0"></progress>
110 <span class="fileuploadpercent">0</span>%
112 <div id="fileuploadfailed"></div>
116 <fieldset class="rows" id="profile_fieldset">
117 <legend>Pre-fill values with profile?</legend>
120 <label for="profile">Profile: </label>
121 <select name="profile" id="profile">
122 <option value="">Do not use profile</option>
124 <div class="hint">When you select a profile it pre-fills your form with profile values.</div>
125 <div class="hint">Later you can modify your form and that's what matters on import.</div>
130 <form method="post" id="processfile" enctype="multipart/form-data">
131 [% IF basketno && booksellerid %]
132 <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
133 <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
135 <input type="hidden" name="profile_id" id="profile_id"/>
136 <fieldset class="rows">
137 <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
138 <input type="hidden" name="runinbackground" id="runinbackground" value="" />
139 <input type="hidden" name="completedJobID" id="completedJobID" value="" />
140 <legend>Settings</legend>
142 <label for="comments">Comments about this file: </label>
143 <input type="text" id="comments" name="comments" />
147 <label for='record_type'>Record type:</label>
148 <select name='record_type' id='record_type'>
149 <option value='biblio' selected='selected'>Bibliographic</option>
150 <option value='auth'>Authority</option>
154 <label for="encoding">Character encoding: </label>
155 <select name="encoding" id="encoding">
156 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
157 <option value="MARC-8">MARC 8</option>
158 <option value="ISO_5426">ISO 5426</option>
159 <option value="ISO_6937">ISO 6937</option>
160 <option value="ISO_8859-1">ISO 8859-1</option>
161 <option value="EUC-KR">EUC-KR</option>
165 <label for='format'>Format:</label>
166 <select name='format' id='format'>
167 <option value='ISO2709'>MARC</option>
168 <option value='MARCXML'>MARCXML</option>
169 [% FOREACH p IN plugins %]
170 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
176 [% IF MarcModificationTemplatesLoop %]
177 <fieldset class="rows">
178 <legend>Modify records using a MARC modification template?</legend>
181 <label for="comments">Template: </label>
182 <select name="marc_modification_template_id" id="marc_modification_template_id">
183 <option value="">Do not use template</option>
184 [% FOREACH mmt IN MarcModificationTemplatesLoop %]
185 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
193 <fieldset class="rows">
194 <legend>Look for existing records in catalog?</legend>
195 <ol><li><label for="matcher">Record matching rule:</label>
196 <select name="matcher" id="matcher">
197 <option value="">Do not look for matching records</option>
198 [% FOREACH available_matcher IN available_matchers %]
199 <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
204 <li><label for="overlay_action">Action if matching record found: </label>
205 [% INCLUDE 'tools-overlay-action.inc' %]
207 <li><label for="nomatch_action">Action if no match is found: </label>
208 [% INCLUDE 'tools-nomatch-action.inc' %]
212 <fieldset class="rows" id="items">
213 <legend>Check for embedded item record data?</legend>
216 <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
217 <label for="parse_itemsyes">Yes</label>
220 <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
221 <label for="parse_itemsno">No (If you do not check for items while staging you may not change this option later)
226 <li><label for="item_action">How to process items: </label>
227 [% INCLUDE 'tools-item-action.inc' %]
232 <fieldset class="rows" id="save_profile">
233 <legend>Save profile</legend>
236 <label for="profile_name">Profile name:</label>
237 <input type="text" id="profile_name" name="profile_name" />
238 <button class="btn btn-default btn-xs" id="add_profile" disabled>Save profile</button>
239 <button class="btn btn-link" id="del_profile" disabled><i class="fa fa-trash"></i> <span>Remove profile</span></button>
244 <fieldset class="action">
245 <input type="submit" id="mainformsubmit" class="btn btn-primary" value="Stage for import" />
252 </div> <!-- /.col-sm-10.col-sm-push-2 -->
254 <div class="col-sm-2 col-sm-pull-10">
256 [% INCLUDE 'cat-menu.inc' %]
258 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
259 </div> <!-- /.row -->
261 [% MACRO jsinclude BLOCK %]
262 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
263 [% Asset.js("js/file-upload.js") | $raw %]
265 [% INCLUDE 'str/job_progess.inc' job_id=job_id %]
266 [% Asset.js("js/job_progess.js") | $raw %]
269 var PROFILE_SAVE_MSG = _("Profile saved");
270 var PROFILE_DEL_MSG = _("Profile deleted");
271 $(document).ready(function(){
272 $("#processfile").hide();
273 $('#profile_fieldset').hide();
274 $("#record_type").change(function() {
275 if ($(this).val() == 'auth') {
281 $("#fileuploadbutton").on("click",function(e){
285 $("#fileuploadcancel").on("click",function(e){
289 $("#mainformsubmit").on("click",function(e){
291 if ($("#fileToUpload").value == '') {
292 alert(_("Please upload a file first."));
295 $("#processfile").submit();
301 $('#profile').change(function(){
303 $("#mod_profile, #del_profile").prop("disabled",true);
304 $("#profile_id").val("");
305 $("#comments").val("");
306 $("#record_type").val('biblio').change();
307 $("#encoding").val('UTF-8').change();
308 $("#format").val('ISO2709').change();
309 $("#marc_modification_template_id").val("").change();
310 $("#matcher").val("").change();
311 $("#overlay_action").val('replace').change();
312 $("#nomatch_action").val('create_new').change();
313 $("#parse_itemsyes").prop("checked", true).change();
314 $("#item_action").val('always_add').change();
315 $("#profile_name").val('').keyup();
316 $("#del_profile span").text( _("Remove profile") );
318 const profile = $('option:selected', this).data('profile');
319 $("#profile_id").val(profile.profile_id);
320 $("#mod_profile, #del_profile").prop("disabled", null);
321 $("#del_profile span").text( _("Remove profile") + ": " + profile.name );
322 $("#comments").val(profile.comments);
323 $("#record_type").val(profile.record_type).change();
324 $("#encoding").val(profile.encoding).change();
325 $("#format").val(profile.format).change();
326 $("#marc_modification_template_id").val(profile.template_id).change();
327 $("#matcher").val(profile.matcher_id).change();
328 $("#overlay_action").val(profile.overlay_action).change();
329 $("#nomatch_action").val(profile.nomatch_action).change();
330 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
331 $("#item_action").val(profile.item_action).change();
332 $("#profile_name").val(profile.name).keyup();
336 $("#profile_name").on("change keyup", function(){
337 $("#add_profile").prop("disabled", this.value.trim()=='');
340 $("#add_profile").click(function(event) {
341 event.preventDefault();
342 var name = $("#profile_name").val().trim();
344 alert(_("Profile must have a name"));
348 var profile = $("#profile option[value!='']")
350 return $(this).data('profile');
353 return this.name == name;
357 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
362 new Promise(function(resolve, reject) {
365 comments: $("#comments").val() || null,
366 record_type: $("#record_type").val() || null,
367 encoding: $("#encoding").val() || null,
368 format: $("#format").val() || null,
369 template_id: $("#marc_modification_template_id").val() || null,
370 matcher_id: $("#matcher").val() || null,
371 overlay_action: $("#overlay_action").val() || null,
372 nomatch_action: $("#nomatch_action").val() || null,
373 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
374 item_action: $("#item_action").val() || null,
380 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
382 data: JSON.stringify(params),
383 contentType: 'application/json'
389 url: "/api/v1/import_batch_profiles/",
391 data: JSON.stringify(params),
392 contentType: 'application/json'
398 .then(function(profile) {
399 humanMsg.displayAlert(PROFILE_SAVE_MSG);
400 return getProfiles(profile.profile_id);
402 .catch(function(error) {
403 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
407 $("#del_profile").click(function(event) {
408 event.preventDefault();
409 var id = $("#profile").val();
411 if(!confirm(_("Are you sure you want to delete this profile?"))) {
414 new Promise(function(resolve, reject) {
416 url: "/api/v1/import_batch_profiles/"+id,
423 humanMsg.displayAlert(PROFILE_DEL_MSG);
424 return getProfiles();
426 .catch(function(error) {
427 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
430 [% IF job_enqueued %]
431 updateProgress([% job_id | html %], function(){
432 $.getJSON('/api/v1/jobs/[% job_id | html %]', function(job){
433 let import_batch_id = job.data.report.import_batch_id;
434 $('<p><a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=%s">%s</a></p>'.format(import_batch_id, _("View batch"))).appendTo("#job_callback");
435 let basket_id = job.data.report.basket_id;
436 let vendor_id = job.data.report.vendor_id;
437 if ( basket_id && vendor_id ) {
438 $('<p><a id="addtobasket" class="btn btn-default" href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=%s&basketno=%s&booksellerid=%s">%s</a></p>'.format(import_batch_id, basket_id, vendor_id, _("Add staged files to basket"))).appendTo("#job_callback");
445 function StartUpload() {
446 if( $('#fileToUpload').prop('files').length == 0 ) return;
447 $('#fileuploadbutton').hide();
448 $("#fileuploadfailed").hide();
449 $("#processfile").hide();
450 $('#profile_fieldset').hide();
451 $("#fileuploadstatus").show();
452 $("#uploadedfileid").val('');
453 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
454 $("#fileuploadcancel").show();
456 function CancelUpload() {
457 if( xhr ) xhr.abort();
458 $("#fileuploadstatus").hide();
459 $('#fileuploadbutton').show();
460 $("#fileuploadcancel").hide();
461 $("#fileuploadfailed").show();
462 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
464 function cbUpload( status, fileid, errors ) {
465 if( status=='done' ) {
466 $("#uploadedfileid").val( fileid );
467 $('#fileToUpload').prop('disabled',true);
468 $('#fileuploadbutton').prop('disabled',true);
469 $('#fileuploadbutton').show();
470 $("#fileuploadcancel").hide();
471 var filename=$('#fileToUpload').prop('files')[0].name;
472 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
473 $('#format').val('MARCXML');
475 $("#processfile").show();
476 $('#profile_fieldset').show();
478 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") ];
479 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
480 $('#fileuploadbutton').show();
481 $("#fileuploadcancel").hide();
482 $("#fileuploadstatus").hide();
483 $("#fileuploadfailed").show();
484 $("#fileuploadfailed").text( _("Upload status: ") +
485 ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
486 ( status=='denied'? _("Denied"): status ))
491 function getProfiles(id) {
492 const select = $("#profile");
493 $("option[value!='']", select).remove();
494 return new Promise(function(resolve, reject) {
495 $.ajax("/api/v1/import_batch_profiles")
496 .then(resolve, reject);
498 .then(function(profiles) {
499 profiles.sort( function(a, b) {
500 return a.name.localeCompare(b.name);
502 profiles.forEach(function(profile) {
503 const opt = $("<option/>");
505 if(id && profile.profile_id == id) {
506 opt.prop('selected', true);
508 opt.attr("value", profile.profile_id);
509 opt.text(profile.name);
510 opt.data("profile", profile);
522 [% INCLUDE 'intranet-bottom.inc' %]