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 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › [% IF ( uploadmarc ) %]<a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a> › Upload Results[% ELSE %]Stage MARC records for import[% END %]</div>
20 <div class="main container-fluid">
22 <div class="col-sm-10 col-sm-push-2">
25 [% IF ( uploadmarc ) %]
26 <div id="toolbar" class="btn-toolbar">
27 <a class="btn btn-default" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
28 <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>
32 <h1>Stage MARC records for import</h1>
33 [% IF ( uploadmarc ) %]
34 <p>MARC staging results :</p>
36 [% SWITCH (record_type) %]
38 <li>Processing bibliographic records</li>
40 <li>Processing authority records</li>
42 <li>[% total | html %] records in file</li>
43 <li>[% import_errors | html %] records not staged because of MARC error</li>
44 <li>[% staged | html %] records staged</li>
45 [% IF ( checked_matches ) %]
46 <li>[% matched | html %] records with at least one match in catalog per matching rule
47 "[% matcher_code | html %]"</li>
49 [% IF ( matcher_failed ) %]
50 <li>Record matching failed -- unable to retrieve selected matching rule.</li>
52 <li>Did not check for matches with existing records in catalog</li>
55 [% IF record_type == 'biblio' %]
56 <li>[% num_items | html %] item records found and staged</li>
58 [% IF ( label_batch ) %]
59 <li>New label batch created: # [% label_batch | html %] </li>
62 [% IF basketno && booksellerid %]
64 <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>
69 <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>
70 <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>
72 <form method="post" action="[% SCRIPT_NAME | html %]" id="uploadfile" enctype="multipart/form-data">
73 <fieldset class="rows" id="uploadform">
74 <legend>Stage records into the reservoir</legend>
77 <div id="fileuploadform">
78 <label for="fileToUpload">Select the file to stage: </label>
79 <input type="file" id="fileToUpload" name="fileToUpload" />
82 <fieldset class="action">
83 <button id="fileuploadbutton">Upload file</button>
84 <button id="fileuploadcancel">Cancel</button>
88 <div id="fileuploadpanel">
89 <div id="fileuploadstatus" class="progress_panel">Upload progress:
90 <progress id="fileuploadprogress" max="100" value="0">
92 <span class="fileuploadpercent">0</span>%
94 <div id="fileuploadfailed"></div>
98 <fieldset class="rows" id="profile_fieldset">
99 <legend>Profile settings</legend>
102 <label for="profile">Pre-fill values with profile</label>
103 <select name="profile" id="profile">
104 <option value="">Do not use profile</option>
106 <div class="hint">When you select a profile it pre-fills your form with profile values.</div>
107 <div class="hint">Later you can modify your form and that's what matters on import.</div>
112 <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
113 [% IF basketno && booksellerid %]
114 <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
115 <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
117 <input type="hidden" name="profile_id" id="profile_id"/>
118 <fieldset class="rows">
119 <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
120 <input type="hidden" name="runinbackground" id="runinbackground" value="" />
121 <input type="hidden" name="completedJobID" id="completedJobID" value="" />
123 <label for="comments">Comments about this file: </label>
124 <input type="text" id="comments" name="comments" />
128 <label for='record_type'>Record type:</label>
129 <select name='record_type' id='record_type'>
130 <option value='biblio' selected='selected'>Bibliographic</option>
131 <option value='auth'>Authority</option>
135 <label for="encoding">Character encoding: </label>
136 <select name="encoding" id="encoding">
137 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
138 <option value="MARC-8">MARC 8</option>
139 <option value="ISO_5426">ISO 5426</option>
140 <option value="ISO_6937">ISO 6937</option>
141 <option value="ISO_8859-1">ISO 8859-1</option>
142 <option value="EUC-KR">EUC-KR</option>
146 <label for='format'>Format:</label>
147 <select name='format' id='format'>
148 <option value='ISO2709'>MARC</option>
149 <option value='MARCXML'>MARCXML</option>
150 [% FOREACH p IN plugins %]
151 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
157 [% IF MarcModificationTemplatesLoop %]
158 <fieldset class="rows">
159 <legend>Use MARC Modification Template:</legend>
162 <label for="comments">Modify record using the following template: </label>
163 <select name="marc_modification_template_id" id="marc_modification_template_id">
164 <option value="">Do not use.</option>
165 [% FOREACH mmt IN MarcModificationTemplatesLoop %]
166 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
174 <fieldset class="rows">
175 <legend>Look for existing records in catalog?</legend>
176 <ol><li><label for="matcher">Record matching rule:</label>
177 <select name="matcher" id="matcher">
178 <option value="">Do not look for matching records</option>
179 [% FOREACH available_matcher IN available_matchers %]
180 <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
185 <li><label for="overlay_action">Action if matching record found: </label>
186 [% INCLUDE 'tools-overlay-action.inc' %]
188 <li><label for="nomatch_action">Action if no match is found: </label>
189 [% INCLUDE 'tools-nomatch-action.inc' %]
193 <fieldset class="rows" id="items">
194 <legend>Check for embedded item record data?</legend>
197 <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
198 <label for="parse_itemsyes">Yes</label>
201 <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
202 <label for="parse_itemsno">No</label>
206 <li><label for="item_action">How to process items: </label>
207 [% INCLUDE 'tools-item-action.inc' %]
211 <fieldset class="action">
212 <input type="button" id="mainformsubmit" value="Stage for import" />
213 <button id="add_profile" disabled>Save profile</button>
214 <input type="text" id="profile_name" name="profile_name" placeholder="Profile name"/>
215 <button id="del_profile" disabled>Remove profile</button>
218 <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
219 <div id="jobfailed"></div></div>
225 </div> <!-- /.col-sm-10.col-sm-push-2 -->
227 <div class="col-sm-2 col-sm-pull-10">
229 [% INCLUDE 'tools-menu.inc' %]
231 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
232 </div> <!-- /.row -->
234 [% MACRO jsinclude BLOCK %]
235 [% Asset.js("js/tools-menu.js") | $raw %]
236 [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
237 [% Asset.js("js/background-job-progressbar.js") | $raw %]
238 [% Asset.js("js/file-upload.js") | $raw %]
241 var PROFILE_SAVE_MSG = _("Profile saved");
242 var PROFILE_DEL_MSG = _("Profile deleted");
243 $(document).ready(function(){
244 $("#processfile").hide();
245 $('#profile_fieldset').hide();
246 $("#record_type").change(function() {
247 if ($(this).val() == 'auth') {
253 $("#fileuploadbutton").on("click",function(e){
257 $("#fileuploadcancel").on("click",function(e){
261 $("#mainformsubmit").on("click",function(){
262 return CheckForm( document.getElementById("processfile"));
265 $('#profile').change(function(){
267 $("#mod_profile, #del_profile").prop("disabled",true);
268 $("#profile_id").val("");
269 $("#comments").val("");
270 $("#record_type").val('biblio').change();
271 $("#encoding").val('UTF-8').change();
272 $("#format").val('ISO2709').change();
273 $("#marc_modification_template_id").val("").change();
274 $("#matcher").val("").change();
275 $("#overlay_action").val('replace').change();
276 $("#nomatch_action").val('create_new').change();
277 $("#parse_itemsyes").prop("checked", true).change();
278 $("#item_action").val('always_add').change();
279 $("#profile_name").val('').keyup();
281 const profile = $('option:selected', this).data('profile');
282 $("#profile_id").val(profile.profile_id);
283 $("#mod_profile, #del_profile").prop("disabled", null);
284 $("#comments").val(profile.comments);
285 $("#record_type").val(profile.record_type).change();
286 $("#encoding").val(profile.encoding).change();
287 $("#format").val(profile.format).change();
288 $("#marc_modification_template_id").val(profile.template_id).change();
289 $("#matcher").val(profile.matcher_id).change();
290 $("#overlay_action").val(profile.overlay_action).change();
291 $("#nomatch_action").val(profile.nomatch_action).change();
292 $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
293 $("#item_action").val(profile.item_action).change();
294 $("#profile_name").val(profile.name).keyup();
298 $("#profile_name").keyup(function(){
299 $("#add_profile").prop("disabled", this.value.trim()=='');
302 $("#add_profile").click(function(event) {
303 event.preventDefault();
304 var name = $("#profile_name").val().trim();
306 alert(_("Profile must have a name"));
310 var profile = $("#profile option[value!='']")
312 return $(this).data('profile');
315 return this.name == name;
319 if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
324 new Promise(function(resolve, reject) {
327 comments: $("#comments").val() || null,
328 record_type: $("#record_type").val() || null,
329 encoding: $("#encoding").val() || null,
330 format: $("#format").val() || null,
331 template_id: $("#marc_modification_template_id").val() || null,
332 matcher_id: $("#matcher").val() || null,
333 overlay_action: $("#overlay_action").val() || null,
334 nomatch_action: $("#nomatch_action").val() || null,
335 parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
336 item_action: $("#item_action").val() || null,
342 url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
344 data: JSON.stringify(params),
345 contentType: 'application/json'
351 url: "/api/v1/import_batch_profiles/",
353 data: JSON.stringify(params),
354 contentType: 'application/json'
360 .then(function(profile) {
361 humanMsg.displayAlert(PROFILE_SAVE_MSG);
362 return getProfiles(profile.profile_id);
364 .catch(function(error) {
365 alert(_("An error occurred")+"\n\n"+error);
369 $("#del_profile").click(function(event) {
370 event.preventDefault();
371 var id = $("#profile").val();
373 if(!confirm(_("Are you sure you want to delete this profile?"))) {
376 new Promise(function(resolve, reject) {
378 url: "/api/v1/import_batch_profiles/"+id,
385 humanMsg.displayAlert(PROFILE_DEL_MSG);
386 return getProfiles();
388 .catch(function(error) {
389 alert(_("An error occurred")+"\n\n"+error);
394 function CheckForm(f) {
395 if ($("#fileToUpload").value == '') {
396 alert(_("Please upload a file first."));
398 return submitBackgroundJob(f);
402 function StartUpload() {
403 if( $('#fileToUpload').prop('files').length == 0 ) return;
404 $('#fileuploadbutton').hide();
405 $("#fileuploadfailed").hide();
406 $("#processfile").hide();
407 $('#profile_fieldset').hide();
408 $("#fileuploadstatus").show();
409 $("#uploadedfileid").val('');
410 xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
411 $("#fileuploadcancel").show();
413 function CancelUpload() {
414 if( xhr ) xhr.abort();
415 $("#fileuploadstatus").hide();
416 $('#fileuploadbutton').show();
417 $("#fileuploadcancel").hide();
418 $("#fileuploadfailed").show();
419 $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
421 function cbUpload( status, fileid, errors ) {
422 if( status=='done' ) {
423 $("#uploadedfileid").val( fileid );
424 $('#fileToUpload').prop('disabled',true);
425 $('#fileuploadbutton').prop('disabled',true);
426 $('#fileuploadbutton').show();
427 $("#fileuploadcancel").hide();
428 var filename=$('#fileToUpload').prop('files')[0].name;
429 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
430 $('#format').val('MARCXML');
432 $("#processfile").show();
433 $('#profile_fieldset').show();
435 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") ];
436 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
437 $('#fileuploadbutton').show();
438 $("#fileuploadcancel").hide();
439 $("#fileuploadstatus").hide();
440 $("#fileuploadfailed").show();
441 $("#fileuploadfailed").text( _("Upload status: ") +
442 ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
443 ( status=='denied'? _("Denied"): status ))
448 function getProfiles(id) {
449 const select = $("#profile");
450 $("option[value!='']", select).remove();
451 return new Promise(function(resolve, reject) {
452 $.ajax("/api/v1/import_batch_profiles")
453 .then(resolve, reject);
455 .then(function(profiles) {
456 profiles.forEach(function(profile) {
457 const opt = $("<option/>");
459 if(id && profile.profile_id == id) {
460 opt.prop('selected', true);
462 opt.attr("value", profile.profile_id);
463 opt.html(profile.name);
464 opt.data("profile", profile);
476 [% INCLUDE 'intranet-bottom.inc' %]