Bug 32954: Standardize action fieldsets in rotating collections, suggestions, tools
[srvgit] / 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; Cataloging &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">Home</a>
24         </li>
25         <li>
26             <a href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cataloging</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 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         <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="submit" id="mainformsubmit" class="btn btn-primary" 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 'cat-menu.inc' %]
257             </aside>
258         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
259      </div> <!-- /.row -->
260
261 [% MACRO jsinclude BLOCK %]
262     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
263     [% Asset.js("js/file-upload.js") | $raw %]
264
265     [% INCLUDE 'str/job_progess.inc' job_id=job_id %]
266     [% Asset.js("js/job_progess.js") | $raw %]
267     <script>
268         var xhr;
269         var PROFILE_SAVE_MSG = _("Profile saved");
270         var PROFILE_DEL_MSG = _("Profile deleted");
271         $(document).ready(function(){
272             $("#processfile").hide();
273             $('#profile_fieldset').hide();
274             $("#record_type").change(function() {
275                 if ($(this).val() == 'auth') {
276                     $('#items').hide();
277                 } else {
278                     $('#items').show();
279                 }
280             });
281             $("#fileuploadbutton").on("click",function(e){
282                 e.preventDefault();
283                 StartUpload();
284             });
285             $("#fileuploadcancel").on("click",function(e){
286                 e.preventDefault();
287                 CancelUpload();
288             });
289             $("#mainformsubmit").on("click",function(e){
290                 e.preventDefault();
291                 if ($("#fileToUpload").value == '') {
292                     alert(_("Please upload a file first."));
293                     return false;
294                 } else {
295                     $("#processfile").submit();
296                     return true;
297                 }
298             });
299
300             getProfiles();
301             $('#profile').change(function(){
302                 if(this.value=='') {
303                     $("#mod_profile, #del_profile").prop("disabled",true);
304                     $("#profile_id").val("");
305                     $("#comments").val("");
306                     $("#record_type").val('biblio').change();
307                     $("#encoding").val('UTF-8').change();
308                     $("#format").val('ISO2709').change();
309                     $("#marc_modification_template_id").val("").change();
310                     $("#matcher").val("").change();
311                     $("#overlay_action").val('replace').change();
312                     $("#nomatch_action").val('create_new').change();
313                     $("#parse_itemsyes").prop("checked", true).change();
314                     $("#item_action").val('always_add').change();
315                     $("#profile_name").val('').keyup();
316                     $("#del_profile span").text( _("Remove profile") );
317                 } else {
318                     const profile = $('option:selected', this).data('profile');
319                     $("#profile_id").val(profile.profile_id);
320                     $("#mod_profile, #del_profile").prop("disabled", null);
321                     $("#del_profile span").text( _("Remove profile") + ": " + profile.name );
322                     $("#comments").val(profile.comments);
323                     $("#record_type").val(profile.record_type).change();
324                     $("#encoding").val(profile.encoding).change();
325                     $("#format").val(profile.format).change();
326                     $("#marc_modification_template_id").val(profile.template_id).change();
327                     $("#matcher").val(profile.matcher_id).change();
328                     $("#overlay_action").val(profile.overlay_action).change();
329                     $("#nomatch_action").val(profile.nomatch_action).change();
330                     $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
331                     $("#item_action").val(profile.item_action).change();
332                     $("#profile_name").val(profile.name).keyup();
333                 }
334             });
335
336             $("#profile_name").on("change keyup", function(){
337                 $("#add_profile").prop("disabled", this.value.trim()=='');
338             });
339
340             $("#add_profile").click(function(event) {
341                 event.preventDefault();
342                 var name = $("#profile_name").val().trim();
343                 if(!name) {
344                     alert(_("Profile must have a name"));
345                     return;
346                 }
347
348                 var profile = $("#profile option[value!='']")
349                     .map(function() {
350                         return $(this).data('profile');
351                     })
352                     .filter(function() {
353                         return this.name == name;
354                     });
355
356                 if(profile.length) {
357                     if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
358                         return;
359                     }
360                 }
361
362                 new Promise(function(resolve, reject) {
363
364                     const params = {
365                         comments: $("#comments").val() || null,
366                         record_type: $("#record_type").val() || null,
367                         encoding: $("#encoding").val() || null,
368                         format: $("#format").val() || null,
369                         template_id: $("#marc_modification_template_id").val() || null,
370                         matcher_id: $("#matcher").val() || null,
371                         overlay_action: $("#overlay_action").val() || null,
372                         nomatch_action: $("#nomatch_action").val() || null,
373                         parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
374                         item_action: $("#item_action").val() || null,
375                         name: name
376                     };
377
378                     if(profile.length) {
379                         $.ajax({
380                             url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
381                             method: "PUT",
382                             data: JSON.stringify(params),
383                             contentType: 'application/json'
384                         })
385                         .done(resolve)
386                         .fail(reject);
387                     } else {
388                         $.ajax({
389                             url: "/api/v1/import_batch_profiles/",
390                             method: "POST",
391                             data: JSON.stringify(params),
392                             contentType: 'application/json'
393                         })
394                         .done(resolve)
395                         .fail(reject);
396                     }
397                 })
398                 .then(function(profile) {
399                     humanMsg.displayAlert(PROFILE_SAVE_MSG);
400                     return getProfiles(profile.profile_id);
401                 })
402                 .catch(function(error) {
403                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
404                 })
405             });
406
407             $("#del_profile").click(function(event) {
408                 event.preventDefault();
409                 var id = $("#profile").val();
410                 if(!id) return;
411                 if(!confirm(_("Are you sure you want to delete this profile?"))) {
412                     return;
413                 }
414                 new Promise(function(resolve, reject) {
415                     $.ajax({
416                         url: "/api/v1/import_batch_profiles/"+id,
417                         method: "DELETE"
418                     })
419                     .done(resolve)
420                     .fail(reject);
421                 })
422                 .then(function() {
423                     humanMsg.displayAlert(PROFILE_DEL_MSG);
424                     return getProfiles();
425                 })
426                 .catch(function(error) {
427                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
428                 })
429             });
430             [% IF job_enqueued %]
431                 updateProgress([% job_id | html %], function(){
432                     $.getJSON('/api/v1/jobs/[% job_id | html %]', function(job){
433                         let import_batch_id = job.data.report.import_batch_id;
434                         $('<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");
435                         let basket_id = job.data.report.basket_id;
436                         let vendor_id = job.data.report.vendor_id;
437                         if ( basket_id && vendor_id ) {
438                             $('<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");
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' %]