Bug 26336: Add hint before and remove select after staging with no items
[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 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% IF ( uploadmarc ) %]<a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a> &rsaquo; Upload Results[% ELSE %]Stage MARC records for import[% END %]</div>
19
20 <div class="main container-fluid">
21     <div class="row">
22         <div class="col-sm-10 col-sm-push-2">
23             <main>
24
25 [% IF ( uploadmarc ) %]
26 <div id="toolbar" class="btn-toolbar">
27         <a class="btn btn-default" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
28         <a class="btn btn-default" href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% import_batch_id | html %]"><i class="fa fa-list-ul"></i> Manage staged records</a>
29 </div>
30 [% END %]
31
32 <h1>Stage MARC records for import</h1>
33 [% IF ( uploadmarc ) %]
34 <p>MARC staging results :</p>
35 <ul>
36     [% SWITCH (record_type) %]
37     [% CASE 'biblio' %]
38         <li>Processing bibliographic records</li>
39     [% CASE 'auth' %]
40         <li>Processing authority records</li>
41     [% END %]
42         <li>[% total | html %]  records in file</li>
43         <li>[% import_errors | html %] records not staged because of MARC error</li>
44         <li>[% staged | html %] records staged</li>
45     [% IF ( checked_matches ) %]
46         <li>[% matched | html %] records with at least one match in catalog per matching rule 
47         &quot;[% matcher_code | html %]&quot;</li>
48     [% ELSE %]
49         [% IF ( matcher_failed ) %]
50           <li>Record matching failed -- unable to retrieve selected matching rule.</li>
51         [% ELSE %]
52           <li>Did not check for matches with existing records in catalog</li>
53         [% END %]
54     [% END %]
55     [% IF record_type == 'biblio' %]
56         <li>[% num_items | html %] item records found and staged</li>
57     [% END %]
58         [% IF ( label_batch ) %]
59           <li>New label batch created: # [% label_batch | html %] </li>
60     [% END %]
61 </ul>
62 [% IF basketno && booksellerid %]
63 <p>
64     <a id="addtobasket" class="btn btn-default" href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=[% import_batch_id | html %]&basketno=[% basketno | html %]&booksellerid=[% booksellerid | html %]">Add staged files to basket</a>
65 </p>
66 [% END %]
67 [% ELSE %]
68 <ul>
69     <li>Select a MARC file to stage in the import reservoir.  It will be parsed, and each valid record staged for later import into the catalog.</li>
70     <li>You can enter a name for this import. It may be useful, when creating a record, to remember where the suggested MARC data comes from!</li>
71 </ul>
72 <form method="post" action="[% SCRIPT_NAME | html %]" id="uploadfile" enctype="multipart/form-data">
73 <fieldset class="rows" id="uploadform">
74 <legend>Stage records into the reservoir</legend>
75 <ol>
76         <li>
77         <div id="fileuploadform">
78                 <label for="fileToUpload">Select the file to stage: </label>
79                 <input type="file" id="fileToUpload" name="fileToUpload" />
80         </div>  </li>
81 </ol>
82     <fieldset class="action">
83         <button id="fileuploadbutton">Upload file</button>
84         <button id="fileuploadcancel">Cancel</button>
85     </fieldset>
86 </fieldset>
87                 
88     <div id="fileuploadpanel">
89         <div id="fileuploadstatus" class="progress_panel">Upload progress:
90             <progress id="fileuploadprogress" max="100" value="0">
91             </progress>
92             <span class="fileuploadpercent">0</span>%
93         </div>
94         <div id="fileuploadfailed"></div>
95     </div>
96 </form>
97
98 <fieldset class="rows" id="profile_fieldset">
99     <legend>Profile settings</legend>
100     <ol>
101         <li>
102             <label for="profile">Pre-fill values with profile</label>
103             <select name="profile" id="profile">
104                 <option value="">Do not use profile</option>
105             </select>
106             <div class="hint">When you select a profile it pre-fills your form with profile values.</div>
107             <div class="hint">Later you can modify your form and that's what matters on import.</div>
108         </li>
109     </ol>
110 </fieldset>
111
112     <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
113 [% IF basketno && booksellerid %]
114     <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
115     <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
116 [% END %]
117     <input type="hidden" name="profile_id" id="profile_id"/>
118 <fieldset class="rows">
119         <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
120         <input type="hidden" name="runinbackground" id="runinbackground" value="" />
121         <input type="hidden" name="completedJobID" id="completedJobID" value="" />
122         <ol><li>
123                 <label for="comments">Comments about this file: </label>
124                 <input type="text" id="comments" name="comments" />
125                 
126         </li>
127     <li>
128         <label for='record_type'>Record type:</label>
129         <select name='record_type' id='record_type'>
130             <option value='biblio' selected='selected'>Bibliographic</option>
131             <option value='auth'>Authority</option>
132         </select>
133     </li>
134         <li>
135                 <label for="encoding">Character encoding: </label>
136             <select name="encoding" id="encoding">
137                 <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
138                 <option value="MARC-8">MARC 8</option>
139                 <option value="ISO_5426">ISO 5426</option>
140                 <option value="ISO_6937">ISO 6937</option>
141                 <option value="ISO_8859-1">ISO 8859-1</option>
142                 <option value="EUC-KR">EUC-KR</option>
143             </select>
144         </li>
145     <li>
146         <label for='format'>Format:</label>
147         <select name='format' id='format'>
148             <option value='ISO2709'>MARC</option>
149             <option value='MARCXML'>MARCXML</option>
150             [% FOREACH p IN plugins %]
151                 <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
152             [% END %]
153         </select>
154     </li>
155 </ol></fieldset>
156
157   [% IF MarcModificationTemplatesLoop %]
158     <fieldset class="rows">
159       <legend>Use MARC Modification Template:</legend>
160       <ol>
161         <li>
162           <label for="comments">Modify record using the following template: </label>
163           <select name="marc_modification_template_id" id="marc_modification_template_id">
164             <option value="">Do not use.</option>
165               [% FOREACH mmt IN MarcModificationTemplatesLoop %]
166                 <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
167               [% END %]
168           </select>
169         </li>
170       </ol>
171     </fieldset>
172   [% END %]
173
174   <fieldset class="rows">
175     <legend>Look for existing records in catalog?</legend>
176     <ol><li><label for="matcher">Record matching rule:</label>
177     <select name="matcher" id="matcher">
178        <option value="">Do not look for matching records</option> 
179        [% FOREACH available_matcher IN available_matchers %]
180           <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
181           </option>
182        [% END %]
183     </select>
184     </li>
185       <li><label for="overlay_action">Action if matching record found: </label>
186            [% INCLUDE 'tools-overlay-action.inc' %]
187       </li>
188       <li><label for="nomatch_action">Action if no match is found: </label>
189            [% INCLUDE 'tools-nomatch-action.inc' %]
190       </li>
191     </ol>
192   </fieldset>
193   <fieldset class="rows" id="items">
194     <legend>Check for embedded item record data?</legend>
195     <ol>
196       <li class="radio">
197         <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
198         <label for="parse_itemsyes">Yes</label>
199       </li>
200       <li class="radio">
201         <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
202         <label for="parse_itemsno">No (If you do not check for items while staging you may not change this option later)
203         </label>
204       </li>
205     </ol>
206     <ol>
207       <li><label for="item_action">How to process items: </label>
208            [% INCLUDE 'tools-item-action.inc' %]
209       </li>
210     </ol>
211   </fieldset>
212   <fieldset class="action">
213     <input type="button" id="mainformsubmit" value="Stage for import" />
214     <button id="add_profile" disabled>Save profile</button>
215     <input type="text" id="profile_name" name="profile_name" placeholder="Profile name"/>
216     <button id="del_profile" disabled>Remove profile</button>
217   </fieldset>
218  
219        <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
220      <div id="jobfailed"></div></div>
221   
222 </form>
223 [% END %]
224
225             </main>
226         </div> <!-- /.col-sm-10.col-sm-push-2 -->
227
228         <div class="col-sm-2 col-sm-pull-10">
229             <aside>
230                 [% INCLUDE 'tools-menu.inc' %]
231             </aside>
232         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
233      </div> <!-- /.row -->
234
235 [% MACRO jsinclude BLOCK %]
236     [% Asset.js("js/tools-menu.js") | $raw %]
237     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
238     [% Asset.js("js/background-job-progressbar.js") | $raw %]
239     [% Asset.js("js/file-upload.js") | $raw %]
240     <script>
241         var xhr;
242         var PROFILE_SAVE_MSG = _("Profile saved");
243         var PROFILE_DEL_MSG = _("Profile deleted");
244         $(document).ready(function(){
245             $("#processfile").hide();
246             $('#profile_fieldset').hide();
247             $("#record_type").change(function() {
248                 if ($(this).val() == 'auth') {
249                     $('#items').hide();
250                 } else {
251                     $('#items').show();
252                 }
253             });
254             $("#fileuploadbutton").on("click",function(e){
255                 e.preventDefault();
256                 StartUpload();
257             });
258             $("#fileuploadcancel").on("click",function(e){
259                 e.preventDefault();
260                 CancelUpload();
261             });
262             $("#mainformsubmit").on("click",function(){
263                 return CheckForm( document.getElementById("processfile"));
264             });
265             getProfiles();
266             $('#profile').change(function(){
267                 if(this.value=='') {
268                     $("#mod_profile, #del_profile").prop("disabled",true);
269                     $("#profile_id").val("");
270                     $("#comments").val("");
271                     $("#record_type").val('biblio').change();
272                     $("#encoding").val('UTF-8').change();
273                     $("#format").val('ISO2709').change();
274                     $("#marc_modification_template_id").val("").change();
275                     $("#matcher").val("").change();
276                     $("#overlay_action").val('replace').change();
277                     $("#nomatch_action").val('create_new').change();
278                     $("#parse_itemsyes").prop("checked", true).change();
279                     $("#item_action").val('always_add').change();
280                     $("#profile_name").val('').keyup();
281                 } else {
282                     const profile = $('option:selected', this).data('profile');
283                     $("#profile_id").val(profile.profile_id);
284                     $("#mod_profile, #del_profile").prop("disabled", null);
285                     $("#comments").val(profile.comments);
286                     $("#record_type").val(profile.record_type).change();
287                     $("#encoding").val(profile.encoding).change();
288                     $("#format").val(profile.format).change();
289                     $("#marc_modification_template_id").val(profile.template_id).change();
290                     $("#matcher").val(profile.matcher_id).change();
291                     $("#overlay_action").val(profile.overlay_action).change();
292                     $("#nomatch_action").val(profile.nomatch_action).change();
293                     $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
294                     $("#item_action").val(profile.item_action).change();
295                     $("#profile_name").val(profile.name).keyup();
296                 }
297             });
298
299             $("#profile_name").keyup(function(){
300                 $("#add_profile").prop("disabled", this.value.trim()=='');
301             });
302
303             $("#add_profile").click(function(event) {
304                 event.preventDefault();
305                 var name = $("#profile_name").val().trim();
306                 if(!name) {
307                     alert(_("Profile must have a name"));
308                     return;
309                 }
310
311                 var profile = $("#profile option[value!='']")
312                     .map(function() {
313                         return $(this).data('profile');
314                     })
315                     .filter(function() {
316                         return this.name == name;
317                     });
318
319                 if(profile.length) {
320                     if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
321                         return;
322                     }
323                 }
324
325                 new Promise(function(resolve, reject) {
326
327                     const params = {
328                         comments: $("#comments").val() || null,
329                         record_type: $("#record_type").val() || null,
330                         encoding: $("#encoding").val() || null,
331                         format: $("#format").val() || null,
332                         template_id: $("#marc_modification_template_id").val() || null,
333                         matcher_id: $("#matcher").val() || null,
334                         overlay_action: $("#overlay_action").val() || null,
335                         nomatch_action: $("#nomatch_action").val() || null,
336                         parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
337                         item_action: $("#item_action").val() || null,
338                         name: name
339                     };
340
341                     if(profile.length) {
342                         $.ajax({
343                             url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
344                             method: "PUT",
345                             data: JSON.stringify(params),
346                             contentType: 'application/json'
347                         })
348                         .done(resolve)
349                         .fail(reject);
350                     } else {
351                         $.ajax({
352                             url: "/api/v1/import_batch_profiles/",
353                             method: "POST",
354                             data: JSON.stringify(params),
355                             contentType: 'application/json'
356                         })
357                         .done(resolve)
358                         .fail(reject);
359                     }
360                 })
361                 .then(function(profile) {
362                     humanMsg.displayAlert(PROFILE_SAVE_MSG);
363                     return getProfiles(profile.profile_id);
364                 })
365                 .catch(function(error) {
366                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
367                 })
368             });
369
370             $("#del_profile").click(function(event) {
371                 event.preventDefault();
372                 var id = $("#profile").val();
373                 if(!id) return;
374                 if(!confirm(_("Are you sure you want to delete this profile?"))) {
375                     return;
376                 }
377                 new Promise(function(resolve, reject) {
378                     $.ajax({
379                         url: "/api/v1/import_batch_profiles/"+id,
380                         method: "DELETE"
381                     })
382                     .done(resolve)
383                     .fail(reject);
384                 })
385                 .then(function() {
386                     humanMsg.displayAlert(PROFILE_DEL_MSG);
387                     return getProfiles();
388                 })
389                 .catch(function(error) {
390                     alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
391                 })
392             });
393         });
394
395         function CheckForm(f) {
396             if ($("#fileToUpload").value == '') {
397                 alert(_("Please upload a file first."));
398             } else {
399                 return submitBackgroundJob(f);
400             }
401             return false;
402         }
403         function StartUpload() {
404             if( $('#fileToUpload').prop('files').length == 0 ) return;
405             $('#fileuploadbutton').hide();
406             $("#fileuploadfailed").hide();
407             $("#processfile").hide();
408             $('#profile_fieldset').hide();
409             $("#fileuploadstatus").show();
410             $("#uploadedfileid").val('');
411             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
412             $("#fileuploadcancel").show();
413         }
414         function CancelUpload() {
415             if( xhr ) xhr.abort();
416             $("#fileuploadstatus").hide();
417             $('#fileuploadbutton').show();
418             $("#fileuploadcancel").hide();
419             $("#fileuploadfailed").show();
420             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
421         }
422         function cbUpload( status, fileid, errors ) {
423             if( status=='done' ) {
424                 $("#uploadedfileid").val( fileid );
425                 $('#fileToUpload').prop('disabled',true);
426                 $('#fileuploadbutton').prop('disabled',true);
427                 $('#fileuploadbutton').show();
428                 $("#fileuploadcancel").hide();
429                 var filename=$('#fileToUpload').prop('files')[0].name;
430                 if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
431                     $('#format').val('MARCXML');
432                 }
433                 $("#processfile").show();
434                 $('#profile_fieldset').show();
435             } else {
436                 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") ];
437                 var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
438                 $('#fileuploadbutton').show();
439                 $("#fileuploadcancel").hide();
440                 $("#fileuploadstatus").hide();
441                 $("#fileuploadfailed").show();
442                 $("#fileuploadfailed").text( _("Upload status: ") +
443                     ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
444                     ( status=='denied'? _("Denied"): status ))
445                 );
446             }
447         }
448
449         function getProfiles(id) {
450             const select = $("#profile");
451             $("option[value!='']", select).remove();
452             return new Promise(function(resolve, reject) {
453                 $.ajax("/api/v1/import_batch_profiles")
454                 .then(resolve, reject);
455             })
456             .then(function(profiles) {
457                 profiles.forEach(function(profile) {
458                     const opt = $("<option/>");
459                     select.append(opt);
460                     if(id && profile.profile_id == id) {
461                         opt.prop('selected', true);
462                     }
463                     opt.attr("value", profile.profile_id);
464                     opt.text(profile.name);
465                     opt.data("profile", profile);
466                 });
467             })
468             .then(function(){
469                 select.change();
470             });
471         }
472
473
474     </script>
475 [% END %]
476
477 [% INCLUDE 'intranet-bottom.inc' %]