3 [% PROCESS 'i18n.inc' %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>[% FILTER collapse %]
7 [% IF ( job_enqueued ) %]
8 [% t("Job enqueued") | html %] ›
10 [% t("Stage MARC records for import") | html %] ›
11 [% t("Cataloging") | html %] ›
12 [% t("Koha") | html %]
14 [% INCLUDE 'doc-head-close.inc' %]
16 #fileuploadstatus,#fileuploadfailed,#fileuploadcancel { display : none; }
19 [% Asset.css("css/humanmsg.css") | $raw %]
22 <body id="tools_stage-marc-import" class="tools">
23 [% WRAPPER 'header.inc' %]
24 [% INCLUDE 'cat-search.inc' %]
27 [% WRAPPER 'sub-header.inc' %]
28 [% WRAPPER breadcrumbs %]
29 [% WRAPPER breadcrumb_item %]
30 <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</a>
33 [% IF ( job_enqueued ) %]
34 [% WRAPPER breadcrumb_item %]
35 <a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>
37 [% WRAPPER breadcrumb_item bc_active= 1 %]
38 [% t("Job enqueued") | html %]
41 [% WRAPPER breadcrumb_item bc_active= 1 %]
42 <span>Stage MARC records for import</span>
44 [% END # /IF ( job_enqueued ) %]
45 [% END #/ WRAPPER breadcrumbs %]
46 [% END #/ WRAPPER sub-header.inc %]
48 <div class="main container-fluid">
50 <div class="col-sm-10 col-sm-push-2">
53 [% FOREACH message IN messages %]
54 [% IF message.type == 'success' %]
55 <div class="dialog message">
56 [% ELSIF message.type == 'warning' %]
57 <div class="dialog alert">
58 [% ELSIF message.type == 'error' %]
59 <div class="dialog alert" style="margin:auto;">
61 [% IF message.code == 'cannot_enqueue_job' %]
62 <span>Cannot enqueue this job.</span>
64 [% IF message.error %]
65 <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
71 <div id="toolbar" class="btn-toolbar">
72 <a class="btn btn-default" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
73 <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>
77 <div class="dialog message">
78 <h1>The job has been enqueued!</h1>
79 <p>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 <legend>Settings</legend>
140 <label for="comments">Comments about this file: </label>
141 <input type="text" id="comments" name="comments" />
145 <label for='record_type'>Record type:</label>
146 <select name='record_type' id='record_type'>
147 <option value='biblio' selected='selected'>Bibliographic</option>
148 <option value='auth'>Authority</option>
152 <label for="encoding">Character encoding: </label>
153 <select name="encoding" id="encoding">
154 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
155 <option value="MARC-8">MARC 8</option>
156 <option value="ISO_5426">ISO 5426</option>
157 <option value="ISO_6937">ISO 6937</option>
158 <option value="ISO_8859-1">ISO 8859-1</option>
159 <option value="EUC-KR">EUC-KR</option>
163 <label for='format'>Format:</label>
164 <select name='format' id='format'>
165 <option value='ISO2709'>MARC</option>
166 <option value='MARCXML'>MARCXML</option>
167 [% FOREACH p IN plugins %]
168 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
174 [% IF MarcModificationTemplatesLoop %]
175 <fieldset class="rows">
176 <legend>Modify records using a MARC modification template?</legend>
179 <label for="comments">Template: </label>
180 <select name="marc_modification_template_id" id="marc_modification_template_id">
181 <option value="">Do not use template</option>
182 [% FOREACH mmt IN MarcModificationTemplatesLoop %]
183 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
191 <fieldset class="rows">
192 <legend>Look for existing records in catalog?</legend>
193 <ol><li><label for="matcher">Record matching rule:</label>
194 <select name="matcher" id="matcher">
195 <option value="">Do not look for matching records</option>
196 [% FOREACH available_matcher IN available_matchers %]
197 <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
202 <li><label for="overlay_action">Action if matching record found: </label>
203 [% INCLUDE 'tools-overlay-action.inc' %]
205 <li><label for="nomatch_action">Action if no match is found: </label>
206 [% INCLUDE 'tools-nomatch-action.inc' %]
210 <fieldset class="rows" id="items">
211 <legend>Check for embedded item record data?</legend>
214 <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
215 <label for="parse_itemsyes">Yes</label>
218 <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
219 <label for="parse_itemsno">No (If you do not check for items while staging you may not change this option later)
224 <li><label for="item_action">How to process items: </label>
225 [% INCLUDE 'tools-item-action.inc' %]
230 <fieldset class="rows" id="save_profile">
231 <legend>Save profile</legend>
234 <label for="profile_name">Profile name:</label>
235 <input type="text" id="profile_name" name="profile_name" />
236 <button class="btn btn-default btn-xs" id="add_profile" disabled>Save profile</button>
237 <button class="btn btn-link" id="del_profile" disabled><i class="fa fa-trash-can"></i> <span>Remove profile</span></button>
242 <fieldset class="action">
243 <input type="submit" id="mainformsubmit" class="btn btn-primary" value="Stage for import" />
250 </div> <!-- /.col-sm-10.col-sm-push-2 -->
252 <div class="col-sm-2 col-sm-pull-10">
254 [% INCLUDE 'cat-menu.inc' %]
256 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
257 </div> <!-- /.row -->
259 [% MACRO jsinclude BLOCK %]
260 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
261 [% Asset.js("js/file-upload.js") | $raw %]
263 [% INCLUDE 'str/job_progress.inc' job_id=job_id %]
264 [% Asset.js("js/job_progress.js") | $raw %]
267 var PROFILE_SAVE_MSG = _("Profile saved");
268 var PROFILE_DEL_MSG = _("Profile deleted");
269 $(document).ready(function(){
270 $("#processfile").hide();
271 $('#profile_fieldset').hide();
272 $("#record_type").change(function() {
273 if ($(this).val() == 'auth') {
279 $("#fileuploadbutton").on("click",function(e){
283 $("#fileuploadcancel").on("click",function(e){
287 $("#mainformsubmit").on("click",function(e){
289 if ($("#fileToUpload").value == '') {
290 alert(_("Please upload a file first."));
293 $("#processfile").submit();
299 $('#profile').change(function(){
301 $("#mod_profile, #del_profile").prop("disabled",true);
302 $("#profile_id").val("");
303 $("#comments").val("");
304 $("#record_type").val('biblio').change();
305 $("#encoding").val('UTF-8').change();
306 $("#format").val('ISO2709').change();
307 $("#marc_modification_template_id").val("").change();
308 $("#matcher").val("").change();
309 $("#overlay_action").val('replace').change();
310 $("#nomatch_action").val('create_new').change();
311 $("#parse_itemsyes").prop("checked", true).change();
312 $("#item_action").val('always_add').change();
313 $("#profile_name").val('').keyup();
314 $("#del_profile span").text( _("Remove profile") );
316 const profile = $('option:selected', this).data('profile');
317 $("#profile_id").val(profile.profile_id);
318 $("#mod_profile, #del_profile").prop("disabled", null);
319 $("#del_profile span").text( _("Remove profile") + ": " + profile.name );
320 $("#comments").val(profile.comments);
321 $("#record_type").val(profile.record_type).change();
322 $("#encoding").val(profile.encoding).change();
323 $("#format").val(profile.format).change();
324 $("#marc_modification_template_id").val(profile.template_id).change();
325 $("#matcher").val(profile.matcher_id).change();
326 $("#overlay_action").val(profile.overlay_action).change();
327 $("#nomatch_action").val(profile.nomatch_action).change();
328 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
329 $("#item_action").val(profile.item_action).change();
330 $("#profile_name").val(profile.name).keyup();
334 $("#profile_name").on("change keyup", function(){
335 $("#add_profile").prop("disabled", this.value.trim()=='');
338 $("#add_profile").click(function(event) {
339 event.preventDefault();
340 var name = $("#profile_name").val().trim();
342 alert(_("Profile must have a name"));
346 var profile = $("#profile option[value!='']")
348 return $(this).data('profile');
351 return this.name == name;
355 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
360 new Promise(function(resolve, reject) {
363 comments: $("#comments").val() || null,
364 record_type: $("#record_type").val() || null,
365 encoding: $("#encoding").val() || null,
366 format: $("#format").val() || null,
367 template_id: $("#marc_modification_template_id").val() || null,
368 matcher_id: $("#matcher").val() || null,
369 overlay_action: $("#overlay_action").val() || null,
370 nomatch_action: $("#nomatch_action").val() || null,
371 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
372 item_action: $("#item_action").val() || null,
378 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
380 data: JSON.stringify(params),
381 contentType: 'application/json'
387 url: "/api/v1/import_batch_profiles/",
389 data: JSON.stringify(params),
390 contentType: 'application/json'
396 .then(function(profile) {
397 humanMsg.displayAlert(PROFILE_SAVE_MSG);
398 return getProfiles(profile.profile_id);
400 .catch(function(error) {
401 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
405 $("#del_profile").click(function(event) {
406 event.preventDefault();
407 var id = $("#profile").val();
409 if(!confirm(_("Are you sure you want to delete this profile?"))) {
412 new Promise(function(resolve, reject) {
414 url: "/api/v1/import_batch_profiles/"+id,
421 humanMsg.displayAlert(PROFILE_DEL_MSG);
422 return getProfiles();
424 .catch(function(error) {
425 alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
428 [% IF job_enqueued %]
429 updateProgress([% job_id | html %], {
430 finish_callback : function(){
431 $.getJSON('/api/v1/jobs/[% job_id | html %]', function(job){
432 let import_batch_id = job.data.report.import_batch_id;
433 $('<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");
434 let basket_id = job.data.report.basket_id;
435 let vendor_id = job.data.report.vendor_id;
436 if ( basket_id && vendor_id ) {
437 $('<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' %]