Bug 34773: Improve translation of title tags: Cataloging tools
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / stage-marc-import.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>[% FILTER collapse %]
7     [% IF ( job_enqueued ) %]
8         [% t("Job enqueued") | html %] &rsaquo;
9     [% END %]
10     [% t("Stage MARC records for import") | html %] &rsaquo;
11     [% t("Cataloging") | html %] &rsaquo;
12     [% t("Koha") | html %]
13 [% END %]</title>
14 [% INCLUDE 'doc-head-close.inc' %]
15 <style>
16     #fileuploadstatus,#fileuploadfailed,#fileuploadcancel { display : none; }
17 </style>
18
19 [% Asset.css("css/humanmsg.css") | $raw %]
20
21 </head>
22 <body id="tools_stage-marc-import" class="tools">
23 [% WRAPPER 'header.inc' %]
24     [% INCLUDE 'cat-search.inc' %]
25 [% END %]
26
27 [% WRAPPER 'sub-header.inc' %]
28     [% WRAPPER breadcrumbs %]
29         [% WRAPPER breadcrumb_item %]
30             <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</a>
31         [% END %]
32
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>
36             [% END %]
37             [% WRAPPER breadcrumb_item bc_active= 1 %]
38                 [% t("Job enqueued") | html %]
39             [% END %]
40         [% ELSE %]
41             [% WRAPPER breadcrumb_item bc_active= 1 %]
42                 <span>Stage MARC records for import</span>
43             [% END %]
44         [% END # /IF ( job_enqueued ) %]
45     [% END #/ WRAPPER breadcrumbs %]
46 [% END #/ WRAPPER sub-header.inc %]
47
48 <div class="main container-fluid">
49     <div class="row">
50         <div class="col-sm-10 col-sm-push-2">
51             <main>
52
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;">
60           [% END %]
61           [% IF message.code == 'cannot_enqueue_job' %]
62               <span>Cannot enqueue this job.</span>
63           [% END %]
64           [% IF message.error %]
65             <span>(The error was: [% message.error | html %], see the Koha log file for more information).</span>
66           [% END %]
67           </div>
68         [% END %]
69
70         [% IF job_enqueued %]
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>
74             </div>
75
76             <h1>MARC staging</h1>
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>
83             </div>
84         [% ELSE %]
85 <h1>Stage MARC records for import</h1>
86 <ul>
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>
89 </ul>
90 <form method="post" id="uploadfile" enctype="multipart/form-data">
91 <fieldset class="rows" id="uploadform">
92 <legend>Upload a file to stage</legend>
93 <ol>
94     <li>
95         <div id="fileuploadform">
96             <label for="fileToUpload">File: </label>
97             <input type="file" id="fileToUpload" name="fileToUpload" />
98         </div>
99     </li>
100 </ol>
101 </fieldset>
102     <fieldset class="action">
103         <button id="fileuploadbutton" class="btn btn-primary">Upload file</button>
104         <button id="fileuploadcancel">Cancel</button>
105     </fieldset>
106
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>%
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     <legend>Settings</legend>
139         <ol><li>
140                 <label for="comments">Comments about this file: </label>
141                 <input type="text" id="comments" name="comments" />
142                 
143         </li>
144     <li>
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>
149         </select>
150     </li>
151         <li>
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>
160             </select>
161         </li>
162     <li>
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>
169             [% END %]
170         </select>
171     </li>
172 </ol></fieldset>
173
174   [% IF MarcModificationTemplatesLoop %]
175     <fieldset class="rows">
176       <legend>Modify records using a MARC modification template?</legend>
177       <ol>
178         <li>
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>
184               [% END %]
185           </select>
186         </li>
187       </ol>
188     </fieldset>
189   [% END %]
190
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 %])
198           </option>
199        [% END %]
200     </select>
201     </li>
202       <li><label for="overlay_action">Action if matching record found: </label>
203            [% INCLUDE 'tools-overlay-action.inc' %]
204       </li>
205       <li><label for="nomatch_action">Action if no match is found: </label>
206            [% INCLUDE 'tools-nomatch-action.inc' %]
207       </li>
208     </ol>
209   </fieldset>
210   <fieldset class="rows" id="items">
211     <legend>Check for embedded item record data?</legend>
212     <ol>
213       <li class="radio">
214         <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
215         <label for="parse_itemsyes">Yes</label>
216       </li>
217       <li class="radio">
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)
220         </label>
221       </li>
222     </ol>
223     <ol>
224       <li><label for="item_action">How to process items: </label>
225            [% INCLUDE 'tools-item-action.inc' %]
226       </li>
227     </ol>
228   </fieldset>
229
230     <fieldset class="rows" id="save_profile">
231         <legend>Save profile</legend>
232         <ol>
233             <li>
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>
238             </li>
239         </ol>
240     </fieldset>
241
242   <fieldset class="action">
243     <input type="submit" id="mainformsubmit" class="btn btn-primary" value="Stage for import" />
244   </fieldset>
245
246 </form>
247 [% END %]
248
249             </main>
250         </div> <!-- /.col-sm-10.col-sm-push-2 -->
251
252         <div class="col-sm-2 col-sm-pull-10">
253             <aside>
254                 [% INCLUDE 'cat-menu.inc' %]
255             </aside>
256         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
257      </div> <!-- /.row -->
258
259 [% MACRO jsinclude BLOCK %]
260     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
261     [% Asset.js("js/file-upload.js") | $raw %]
262
263     [% INCLUDE 'str/job_progress.inc' job_id=job_id %]
264     [% Asset.js("js/job_progress.js") | $raw %]
265     <script>
266         var xhr;
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') {
274                     $('#items').hide();
275                 } else {
276                     $('#items').show();
277                 }
278             });
279             $("#fileuploadbutton").on("click",function(e){
280                 e.preventDefault();
281                 StartUpload();
282             });
283             $("#fileuploadcancel").on("click",function(e){
284                 e.preventDefault();
285                 CancelUpload();
286             });
287             $("#mainformsubmit").on("click",function(e){
288                 e.preventDefault();
289                 if ($("#fileToUpload").value == '') {
290                     alert(_("Please upload a file first."));
291                     return false;
292                 } else {
293                     $("#processfile").submit();
294                     return true;
295                 }
296             });
297
298             getProfiles();
299             $('#profile').change(function(){
300                 if(this.value=='') {
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") );
315                 } else {
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();
331                 }
332             });
333
334             $("#profile_name").on("change keyup", function(){
335                 $("#add_profile").prop("disabled", this.value.trim()=='');
336             });
337
338             $("#add_profile").click(function(event) {
339                 event.preventDefault();
340                 var name = $("#profile_name").val().trim();
341                 if(!name) {
342                     alert(_("Profile must have a name"));
343                     return;
344                 }
345
346                 var profile = $("#profile option[value!='']")
347                     .map(function() {
348                         return $(this).data('profile');
349                     })
350                     .filter(function() {
351                         return this.name == name;
352                     });
353
354                 if(profile.length) {
355                     if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
356                         return;
357                     }
358                 }
359
360                 new Promise(function(resolve, reject) {
361
362                     const params = {
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,
373                         name: name
374                     };
375
376                     if(profile.length) {
377                         $.ajax({
378                             url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
379                             method: "PUT",
380                             data: JSON.stringify(params),
381                             contentType: 'application/json'
382                         })
383                         .done(resolve)
384                         .fail(reject);
385                     } else {
386                         $.ajax({
387                             url: "/api/v1/import_batch_profiles/",
388                             method: "POST",
389                             data: JSON.stringify(params),
390                             contentType: 'application/json'
391                         })
392                         .done(resolve)
393                         .fail(reject);
394                     }
395                 })
396                 .then(function(profile) {
397                     humanMsg.displayAlert(PROFILE_SAVE_MSG);
398                     return getProfiles(profile.profile_id);
399                 })
400                 .catch(function(error) {
401                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
402                 })
403             });
404
405             $("#del_profile").click(function(event) {
406                 event.preventDefault();
407                 var id = $("#profile").val();
408                 if(!id) return;
409                 if(!confirm(_("Are you sure you want to delete this profile?"))) {
410                     return;
411                 }
412                 new Promise(function(resolve, reject) {
413                     $.ajax({
414                         url: "/api/v1/import_batch_profiles/"+id,
415                         method: "DELETE"
416                     })
417                     .done(resolve)
418                     .fail(reject);
419                 })
420                 .then(function() {
421                     humanMsg.displayAlert(PROFILE_DEL_MSG);
422                     return getProfiles();
423                 })
424                 .catch(function(error) {
425                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
426                 })
427             });
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");
438                             }
439                         });
440                     }
441                 });
442             [% END %]
443         });
444
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();
455         }
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 ") );
463         }
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');
474                 }
475                 $("#processfile").show();
476                 $('#profile_fieldset').show();
477             } else {
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 ))
487                 );
488             }
489         }
490
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);
497             })
498             .then(function(profiles) {
499                 profiles.sort( function(a, b) {
500                   return a.name.localeCompare(b.name);
501                 });
502                 profiles.forEach(function(profile) {
503                     const opt = $("<option/>");
504                     select.append(opt);
505                     if(id && profile.profile_id == id) {
506                         opt.prop('selected', true);
507                     }
508                     opt.attr("value", profile.profile_id);
509                     opt.text(profile.name);
510                     opt.data("profile", profile);
511                 });
512             })
513             .then(function(){
514                 select.change();
515             });
516         }
517
518
519     </script>
520 [% END %]
521
522 [% INCLUDE 'intranet-bottom.inc' %]