Bug 27846: tools and virtualshelves folders
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / stage-marc-import.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha &rsaquo; Tools &rsaquo; Stage MARC records for import</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 <style>
8     #fileuploadstatus,#fileuploadfailed,#fileuploadcancel,#jobpanel,#jobstatus,#jobfailed { display : none; }
9 </style>
10
11 [% Asset.css("css/humanmsg.css") | $raw %]
12
13 </head>
14 <body id="tools_stage-marc-import" class="tools">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'cat-search.inc' %]
17
18 <nav aria-label="Breadcrumb" class="breadcrumb">
19     <ol>
20         <li>
21             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
22         </li>
23         <li>
24             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
25         </li>
26
27         [% IF ( uploadmarc ) %]
28             <li>
29                 <a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>
30             </li>
31             <li>
32                 <a href="#" aria-current="page">
33                     Upload Results
34                 </a>
35             </li>
36         [% ELSE %]
37             <li>
38                 <a href="#" aria-current="page">
39                     Stage MARC records for import
40                 </a>
41             </li>
42         [% END %]
43     </ol>
44 </nav>
45
46 <div class="main container-fluid">
47     <div class="row">
48         <div class="col-sm-10 col-sm-push-2">
49             <main>
50
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>
55 </div>
56 [% END %]
57
58 <h1>Stage MARC records for import</h1>
59 [% IF ( uploadmarc ) %]
60 <p>MARC staging results :</p>
61 <ul>
62     [% SWITCH (record_type) %]
63     [% CASE 'biblio' %]
64         <li>Processing bibliographic records</li>
65     [% CASE 'auth' %]
66         <li>Processing authority records</li>
67     [% END %]
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         &quot;[% matcher_code | html %]&quot;</li>
74     [% ELSE %]
75         [% IF ( matcher_failed ) %]
76           <li>Record matching failed -- unable to retrieve selected matching rule.</li>
77         [% ELSE %]
78           <li>Did not check for matches with existing records in catalog</li>
79         [% END %]
80     [% END %]
81     [% IF record_type == 'biblio' %]
82         <li>[% num_items | html %] item records found and staged</li>
83     [% END %]
84         [% IF ( label_batch ) %]
85           <li>New label batch created: # [% label_batch | html %] </li>
86     [% END %]
87 </ul>
88 [% IF basketno && booksellerid %]
89 <p>
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>
91 </p>
92 [% END %]
93 [% ELSE %]
94 <ul>
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>
97 </ul>
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>
101 <ol>
102         <li>
103         <div id="fileuploadform">
104                 <label for="fileToUpload">Select the file to stage: </label>
105                 <input type="file" id="fileToUpload" name="fileToUpload" />
106         </div>  </li>
107 </ol>
108     <fieldset class="action">
109         <button id="fileuploadbutton">Upload file</button>
110         <button id="fileuploadcancel">Cancel</button>
111     </fieldset>
112 </fieldset>
113                 
114     <div id="fileuploadpanel">
115         <div id="fileuploadstatus" class="progress_panel">Upload progress:
116             <progress id="fileuploadprogress" max="100" value="0">
117             </progress>
118             <span class="fileuploadpercent">0</span>%
119         </div>
120         <div id="fileuploadfailed"></div>
121     </div>
122 </form>
123
124 <fieldset class="rows" id="profile_fieldset">
125     <legend>Profile settings</legend>
126     <ol>
127         <li>
128             <label for="profile">Pre-fill values with profile</label>
129             <select name="profile" id="profile">
130                 <option value="">Do not use profile</option>
131             </select>
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>
134         </li>
135     </ol>
136 </fieldset>
137
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 %]" />
142 [% END %]
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="" />
148         <ol><li>
149                 <label for="comments">Comments about this file: </label>
150                 <input type="text" id="comments" name="comments" />
151                 
152         </li>
153     <li>
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>
158         </select>
159     </li>
160         <li>
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>
169             </select>
170         </li>
171     <li>
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>
178             [% END %]
179         </select>
180     </li>
181 </ol></fieldset>
182
183   [% IF MarcModificationTemplatesLoop %]
184     <fieldset class="rows">
185       <legend>Use MARC Modification Template:</legend>
186       <ol>
187         <li>
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>
193               [% END %]
194           </select>
195         </li>
196       </ol>
197     </fieldset>
198   [% END %]
199
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 %])
207           </option>
208        [% END %]
209     </select>
210     </li>
211       <li><label for="overlay_action">Action if matching record found: </label>
212            [% INCLUDE 'tools-overlay-action.inc' %]
213       </li>
214       <li><label for="nomatch_action">Action if no match is found: </label>
215            [% INCLUDE 'tools-nomatch-action.inc' %]
216       </li>
217     </ol>
218   </fieldset>
219   <fieldset class="rows" id="items">
220     <legend>Check for embedded item record data?</legend>
221     <ol>
222       <li class="radio">
223         <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
224         <label for="parse_itemsyes">Yes</label>
225       </li>
226       <li class="radio">
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)
229         </label>
230       </li>
231     </ol>
232     <ol>
233       <li><label for="item_action">How to process items: </label>
234            [% INCLUDE 'tools-item-action.inc' %]
235       </li>
236     </ol>
237   </fieldset>
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>
243   </fieldset>
244  
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>
247   
248 </form>
249 [% END %]
250
251             </main>
252         </div> <!-- /.col-sm-10.col-sm-push-2 -->
253
254         <div class="col-sm-2 col-sm-pull-10">
255             <aside>
256                 [% INCLUDE 'tools-menu.inc' %]
257             </aside>
258         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
259      </div> <!-- /.row -->
260
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 %]
266     <script>
267         var xhr;
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') {
275                     $('#items').hide();
276                 } else {
277                     $('#items').show();
278                 }
279             });
280             $("#fileuploadbutton").on("click",function(e){
281                 e.preventDefault();
282                 StartUpload();
283             });
284             $("#fileuploadcancel").on("click",function(e){
285                 e.preventDefault();
286                 CancelUpload();
287             });
288             $("#mainformsubmit").on("click",function(){
289                 return CheckForm( document.getElementById("processfile"));
290             });
291             getProfiles();
292             $('#profile').change(function(){
293                 if(this.value=='') {
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();
307                 } else {
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();
322                 }
323             });
324
325             $("#profile_name").keyup(function(){
326                 $("#add_profile").prop("disabled", this.value.trim()=='');
327             });
328
329             $("#add_profile").click(function(event) {
330                 event.preventDefault();
331                 var name = $("#profile_name").val().trim();
332                 if(!name) {
333                     alert(_("Profile must have a name"));
334                     return;
335                 }
336
337                 var profile = $("#profile option[value!='']")
338                     .map(function() {
339                         return $(this).data('profile');
340                     })
341                     .filter(function() {
342                         return this.name == name;
343                     });
344
345                 if(profile.length) {
346                     if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
347                         return;
348                     }
349                 }
350
351                 new Promise(function(resolve, reject) {
352
353                     const params = {
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,
364                         name: name
365                     };
366
367                     if(profile.length) {
368                         $.ajax({
369                             url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
370                             method: "PUT",
371                             data: JSON.stringify(params),
372                             contentType: 'application/json'
373                         })
374                         .done(resolve)
375                         .fail(reject);
376                     } else {
377                         $.ajax({
378                             url: "/api/v1/import_batch_profiles/",
379                             method: "POST",
380                             data: JSON.stringify(params),
381                             contentType: 'application/json'
382                         })
383                         .done(resolve)
384                         .fail(reject);
385                     }
386                 })
387                 .then(function(profile) {
388                     humanMsg.displayAlert(PROFILE_SAVE_MSG);
389                     return getProfiles(profile.profile_id);
390                 })
391                 .catch(function(error) {
392                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
393                 })
394             });
395
396             $("#del_profile").click(function(event) {
397                 event.preventDefault();
398                 var id = $("#profile").val();
399                 if(!id) return;
400                 if(!confirm(_("Are you sure you want to delete this profile?"))) {
401                     return;
402                 }
403                 new Promise(function(resolve, reject) {
404                     $.ajax({
405                         url: "/api/v1/import_batch_profiles/"+id,
406                         method: "DELETE"
407                     })
408                     .done(resolve)
409                     .fail(reject);
410                 })
411                 .then(function() {
412                     humanMsg.displayAlert(PROFILE_DEL_MSG);
413                     return getProfiles();
414                 })
415                 .catch(function(error) {
416                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
417                 })
418             });
419         });
420
421         function CheckForm(f) {
422             if ($("#fileToUpload").value == '') {
423                 alert(_("Please upload a file first."));
424             } else {
425                 return submitBackgroundJob(f);
426             }
427             return false;
428         }
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();
439         }
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 ") );
447         }
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');
458                 }
459                 $("#processfile").show();
460                 $('#profile_fieldset').show();
461             } else {
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 ))
471                 );
472             }
473         }
474
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);
481             })
482             .then(function(profiles) {
483                 profiles.forEach(function(profile) {
484                     const opt = $("<option/>");
485                     select.append(opt);
486                     if(id && profile.profile_id == id) {
487                         opt.prop('selected', true);
488                     }
489                     opt.attr("value", profile.profile_id);
490                     opt.text(profile.name);
491                     opt.data("profile", profile);
492                 });
493             })
494             .then(function(){
495                 select.change();
496             });
497         }
498
499
500     </script>
501 [% END %]
502
503 [% INCLUDE 'intranet-bottom.inc' %]