Bug 30952: Staff interface redesign (header)
[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>Stage MARC records for import &rsaquo; Tools &rsaquo; Koha</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 [% WRAPPER 'header.inc' %]
16     [% INCLUDE 'cat-search.inc' %]
17 [% END %]
18
19 [% WRAPPER 'sub-header.inc' %]
20 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
21     <ol>
22         <li>
23             <a href="/cgi-bin/koha/mainpage.pl"><i class="fa fa-home"></i></a>
24         </li>
25         <li>
26             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
27         </li>
28
29         [% IF ( uploadmarc ) %]
30             <li>
31                 <a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>
32             </li>
33             <li>
34                 <a href="#" aria-current="page">
35                     MARC staging results
36                 </a>
37             </li>
38         [% ELSE %]
39             <li>
40                 <a href="#" aria-current="page">
41                     Stage MARC records for import
42                 </a>
43             </li>
44         [% END %]
45     </ol>
46 </nav>
47 [% END %]
48
49 <div class="main container-fluid">
50     <div class="row">
51         <div class="col-sm-10 col-sm-push-2">
52             <main>
53
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;">
61           [% END %]
62           [% IF message.code == 'cannot_enqueue_job' %]
63               <span>Cannot enqueue this job.</span>
64           [% END %]
65           [% IF message.error %]
66             <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
67           [% END %]
68           </div>
69         [% END %]
70
71         [% IF job_enqueued %]
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>
75             </div>
76
77             <h1>MARC staging</h1>
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>
83         [% ELSE %]
84 <h1>Stage MARC records for import</h1>
85 <ul>
86     <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>
87     <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>
88 </ul>
89 <form method="post" id="uploadfile" enctype="multipart/form-data">
90 <fieldset class="rows" id="uploadform">
91 <legend>Upload a file to stage</legend>
92 <ol>
93     <li>
94         <div id="fileuploadform">
95             <label for="fileToUpload">File: </label>
96             <input type="file" id="fileToUpload" name="fileToUpload" />
97         </div>
98     </li>
99 </ol>
100     <fieldset class="action">
101         <button id="fileuploadbutton">Upload file</button>
102         <button id="fileuploadcancel">Cancel</button>
103     </fieldset>
104 </fieldset>
105
106     <div id="fileuploadpanel">
107         <div id="fileuploadstatus" class="progress_panel">Upload progress:
108             <progress id="fileuploadprogress" max="100" value="0">
109             </progress>
110             <span class="fileuploadpercent">0</span>%
111         </div>
112         <div id="fileuploadfailed"></div>
113     </div>
114 </form>
115
116 <fieldset class="rows" id="profile_fieldset">
117     <legend>Pre-fill values with profile?</legend>
118     <ol>
119         <li>
120             <label for="profile">Profile: </label>
121             <select name="profile" id="profile">
122                 <option value="">Do not use profile</option>
123             </select>
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>
126         </li>
127     </ol>
128 </fieldset>
129
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 %]" />
134 [% END %]
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>
141         <ol><li>
142                 <label for="comments">Comments about this file: </label>
143                 <input type="text" id="comments" name="comments" />
144                 
145         </li>
146     <li>
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>
151         </select>
152     </li>
153         <li>
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>
162             </select>
163         </li>
164     <li>
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>
171             [% END %]
172         </select>
173     </li>
174 </ol></fieldset>
175
176   [% IF MarcModificationTemplatesLoop %]
177     <fieldset class="rows">
178       <legend>Modify records using a MARC modification template?</legend>
179       <ol>
180         <li>
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>
186               [% END %]
187           </select>
188         </li>
189       </ol>
190     </fieldset>
191   [% END %]
192
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 %])
200           </option>
201        [% END %]
202     </select>
203     </li>
204       <li><label for="overlay_action">Action if matching record found: </label>
205            [% INCLUDE 'tools-overlay-action.inc' %]
206       </li>
207       <li><label for="nomatch_action">Action if no match is found: </label>
208            [% INCLUDE 'tools-nomatch-action.inc' %]
209       </li>
210     </ol>
211   </fieldset>
212   <fieldset class="rows" id="items">
213     <legend>Check for embedded item record data?</legend>
214     <ol>
215       <li class="radio">
216         <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
217         <label for="parse_itemsyes">Yes</label>
218       </li>
219       <li class="radio">
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)
222         </label>
223       </li>
224     </ol>
225     <ol>
226       <li><label for="item_action">How to process items: </label>
227            [% INCLUDE 'tools-item-action.inc' %]
228       </li>
229     </ol>
230   </fieldset>
231
232     <fieldset class="rows" id="save_profile">
233         <legend>Save profile</legend>
234         <ol>
235             <li>
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>
240             </li>
241         </ol>
242     </fieldset>
243
244   <fieldset class="action">
245     <input type="button" id="mainformsubmit" value="Stage for import" />
246   </fieldset>
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/file-upload.js") | $raw %]
265
266     [% INCLUDE 'str/job_progess.inc' job_id=job_id %]
267     [% Asset.js("js/job_progess.js") | $raw %]
268     <script>
269         var xhr;
270         var PROFILE_SAVE_MSG = _("Profile saved");
271         var PROFILE_DEL_MSG = _("Profile deleted");
272         $(document).ready(function(){
273             $("#processfile").hide();
274             $('#profile_fieldset').hide();
275             $("#record_type").change(function() {
276                 if ($(this).val() == 'auth') {
277                     $('#items').hide();
278                 } else {
279                     $('#items').show();
280                 }
281             });
282             $("#fileuploadbutton").on("click",function(e){
283                 e.preventDefault();
284                 StartUpload();
285             });
286             $("#fileuploadcancel").on("click",function(e){
287                 e.preventDefault();
288                 CancelUpload();
289             });
290             $("#mainformsubmit").on("click",function(e){
291                 e.preventDefault();
292                 if ($("#fileToUpload").value == '') {
293                     alert(_("Please upload a file first."));
294                     return false;
295                 } else {
296                     $("#processfile").submit();
297                     return true;
298                 }
299             });
300
301             getProfiles();
302             $('#profile').change(function(){
303                 if(this.value=='') {
304                     $("#mod_profile, #del_profile").prop("disabled",true);
305                     $("#profile_id").val("");
306                     $("#comments").val("");
307                     $("#record_type").val('biblio').change();
308                     $("#encoding").val('UTF-8').change();
309                     $("#format").val('ISO2709').change();
310                     $("#marc_modification_template_id").val("").change();
311                     $("#matcher").val("").change();
312                     $("#overlay_action").val('replace').change();
313                     $("#nomatch_action").val('create_new').change();
314                     $("#parse_itemsyes").prop("checked", true).change();
315                     $("#item_action").val('always_add').change();
316                     $("#profile_name").val('').keyup();
317                     $("#del_profile span").text( _("Remove profile") );
318                 } else {
319                     const profile = $('option:selected', this).data('profile');
320                     $("#profile_id").val(profile.profile_id);
321                     $("#mod_profile, #del_profile").prop("disabled", null);
322                     $("#del_profile span").text( _("Remove profile") + ": " + profile.name );
323                     $("#comments").val(profile.comments);
324                     $("#record_type").val(profile.record_type).change();
325                     $("#encoding").val(profile.encoding).change();
326                     $("#format").val(profile.format).change();
327                     $("#marc_modification_template_id").val(profile.template_id).change();
328                     $("#matcher").val(profile.matcher_id).change();
329                     $("#overlay_action").val(profile.overlay_action).change();
330                     $("#nomatch_action").val(profile.nomatch_action).change();
331                     $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
332                     $("#item_action").val(profile.item_action).change();
333                     $("#profile_name").val(profile.name).keyup();
334                 }
335             });
336
337             $("#profile_name").on("change keyup", function(){
338                 $("#add_profile").prop("disabled", this.value.trim()=='');
339             });
340
341             $("#add_profile").click(function(event) {
342                 event.preventDefault();
343                 var name = $("#profile_name").val().trim();
344                 if(!name) {
345                     alert(_("Profile must have a name"));
346                     return;
347                 }
348
349                 var profile = $("#profile option[value!='']")
350                     .map(function() {
351                         return $(this).data('profile');
352                     })
353                     .filter(function() {
354                         return this.name == name;
355                     });
356
357                 if(profile.length) {
358                     if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
359                         return;
360                     }
361                 }
362
363                 new Promise(function(resolve, reject) {
364
365                     const params = {
366                         comments: $("#comments").val() || null,
367                         record_type: $("#record_type").val() || null,
368                         encoding: $("#encoding").val() || null,
369                         format: $("#format").val() || null,
370                         template_id: $("#marc_modification_template_id").val() || null,
371                         matcher_id: $("#matcher").val() || null,
372                         overlay_action: $("#overlay_action").val() || null,
373                         nomatch_action: $("#nomatch_action").val() || null,
374                         parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
375                         item_action: $("#item_action").val() || null,
376                         name: name
377                     };
378
379                     if(profile.length) {
380                         $.ajax({
381                             url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
382                             method: "PUT",
383                             data: JSON.stringify(params),
384                             contentType: 'application/json'
385                         })
386                         .done(resolve)
387                         .fail(reject);
388                     } else {
389                         $.ajax({
390                             url: "/api/v1/import_batch_profiles/",
391                             method: "POST",
392                             data: JSON.stringify(params),
393                             contentType: 'application/json'
394                         })
395                         .done(resolve)
396                         .fail(reject);
397                     }
398                 })
399                 .then(function(profile) {
400                     humanMsg.displayAlert(PROFILE_SAVE_MSG);
401                     return getProfiles(profile.profile_id);
402                 })
403                 .catch(function(error) {
404                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
405                 })
406             });
407
408             $("#del_profile").click(function(event) {
409                 event.preventDefault();
410                 var id = $("#profile").val();
411                 if(!id) return;
412                 if(!confirm(_("Are you sure you want to delete this profile?"))) {
413                     return;
414                 }
415                 new Promise(function(resolve, reject) {
416                     $.ajax({
417                         url: "/api/v1/import_batch_profiles/"+id,
418                         method: "DELETE"
419                     })
420                     .done(resolve)
421                     .fail(reject);
422                 })
423                 .then(function() {
424                     humanMsg.displayAlert(PROFILE_DEL_MSG);
425                     return getProfiles();
426                 })
427                 .catch(function(error) {
428                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
429                 })
430             });
431             [% IF job_enqueued %]
432                 updateProgress([% job_id | html %]);
433             [% END %]
434         });
435
436         function StartUpload() {
437             if( $('#fileToUpload').prop('files').length == 0 ) return;
438             $('#fileuploadbutton').hide();
439             $("#fileuploadfailed").hide();
440             $("#processfile").hide();
441             $('#profile_fieldset').hide();
442             $("#fileuploadstatus").show();
443             $("#uploadedfileid").val('');
444             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
445             $("#fileuploadcancel").show();
446         }
447         function CancelUpload() {
448             if( xhr ) xhr.abort();
449             $("#fileuploadstatus").hide();
450             $('#fileuploadbutton').show();
451             $("#fileuploadcancel").hide();
452             $("#fileuploadfailed").show();
453             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
454         }
455         function cbUpload( status, fileid, errors ) {
456             if( status=='done' ) {
457                 $("#uploadedfileid").val( fileid );
458                 $('#fileToUpload').prop('disabled',true);
459                 $('#fileuploadbutton').prop('disabled',true);
460                 $('#fileuploadbutton').show();
461                 $("#fileuploadcancel").hide();
462                 var filename=$('#fileToUpload').prop('files')[0].name;
463                 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
464                     $('#format').val('MARCXML');
465                 }
466                 $("#processfile").show();
467                 $('#profile_fieldset').show();
468             } else {
469                 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") ];
470                 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
471                 $('#fileuploadbutton').show();
472                 $("#fileuploadcancel").hide();
473                 $("#fileuploadstatus").hide();
474                 $("#fileuploadfailed").show();
475                 $("#fileuploadfailed").text( _("Upload status: ") +
476                     ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
477                     ( status=='denied'? _("Denied"): status ))
478                 );
479             }
480         }
481
482         function getProfiles(id) {
483             const select = $("#profile");
484             $("option[value!='']", select).remove();
485             return new Promise(function(resolve, reject) {
486                 $.ajax("/api/v1/import_batch_profiles")
487                 .then(resolve, reject);
488             })
489             .then(function(profiles) {
490                 profiles.sort( function(a, b) {
491                   return a.name.localeCompare(b.name);
492                 });
493                 profiles.forEach(function(profile) {
494                     const opt = $("<option/>");
495                     select.append(opt);
496                     if(id && profile.profile_id == id) {
497                         opt.prop('selected', true);
498                     }
499                     opt.attr("value", profile.profile_id);
500                     opt.text(profile.name);
501                     opt.data("profile", profile);
502                 });
503             })
504             .then(function(){
505                 select.change();
506             });
507         }
508
509
510     </script>
511 [% END %]
512
513 [% INCLUDE 'intranet-bottom.inc' %]