Bug 19672: Move tools templates JavaScript to the footer: More MARC tools
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / manage-marc-import.tt
1 [% SET footerjs = 1 %]
2 [% INCLUDE 'doc-head-open.inc' %]
3 <title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records
4 [% IF ( import_batch_id ) %]
5  &rsaquo; Batch [% import_batch_id %]
6 [% END %]
7 </title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
10 <style type="text/css">
11     #jobpanel,#jobstatus,#jobfailed { display : none; }
12     span.change-status { font-style:italic; color:#666; display:none; }
13 </style>
14 </head>
15 <body id="tools_manage-marc-import" class="tools">
16 [% INCLUDE 'header.inc' %]
17 [% INCLUDE 'cat-search.inc' %]
18
19 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> 
20 [% IF ( import_batch_id ) %]
21  &rsaquo;
22  <a href="[% script_name %]">Manage staged MARC records</a>
23  &rsaquo; Batch [% import_batch_id %]
24 [% ELSE %]
25  &rsaquo; Manage staged MARC records
26 [% END %]
27 </div>
28
29 <div id="doc3" class="yui-t2">
30    
31    <div id="bd">
32         <div id="yui-main">
33         <div class="yui-b">
34
35 <h1>Manage staged MARC records
36 [% IF ( import_batch_id ) %]
37  &rsaquo; Batch [% import_batch_id %]
38 [% END %]
39 </h1>
40 [% IF ( label_batch_msg ) %]
41 [% IF ( alert ) %]
42 <div class="alert">
43 [% ELSE %]
44 <div class="dialog message">
45 [% END %]
46 <b><p>[% label_batch_msg %]</p></b>
47 </div>
48 [% END %]
49
50 [% IF ( did_clean ) %]
51   <div class="dialog message">Cleaned import batch #[% import_batch_id %]</div>
52 [% END %]
53
54 [% IF ( did_delete ) %]
55   <div class="dialog message">Import batch deleted successfully</div>
56 [% END %]
57
58 [% UNLESS ( batch_list ) %]
59    [% UNLESS ( batch_info ) %]
60    <div class="dialog message">
61      <p>No records have been staged.</p>
62      <p><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a>.</p>
63    </div>
64    [% END %]
65 [% END %]
66
67 [% IF ( batch_info ) %]
68
69 [% IF ( can_commit ) %]
70 <form action="[% script_name %]" method="post">
71 <input type="hidden" name="op" value="redo-matching" />
72 <input type="hidden" name="import_batch_id" value="[% import_batch_id %]" />
73 <input type="hidden" name="current_matcher_id" value="[% current_matcher_id %]" />
74 [% END %]
75
76   [% IF ( rematch_attempted ) %]
77     [% IF ( rematch_failed ) %]
78       <div class="dialog alert">Failed to apply different matching rule</div>
79     [% ELSE %]
80       <div class="dialog message">Applied different matching rule.  Number of records matched now
81        [% num_with_matches %]
82       </div>
83     [% END %]
84   [% END %]
85   [% IF ( changed_overlay_action ) %]
86       <div class="dialog message">Changed action if matching record found</div>
87   [% END %]
88   [% IF ( changed_nomatch_action ) %]
89       <div class="dialog message">Changed action if no match found</div>
90   [% END %]
91   [% IF ( changed_item_action ) %]
92       <div class="dialog message">Changed item processing option</div>
93   [% END %]
94
95 <fieldset class="rows" id="staged-record-matching-rules">
96   <ol>
97     <li><span class="label">File name:</span> [% file_name %]</li>
98     <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments %][% ELSE %](none)[% END %]</li>
99     <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
100     <li><span class="label">Staged:</span> [% upload_timestamp %]</li>
101     <li><span class="label">Status:</span>
102       [% IF ( import_status == 'cleaned' ) %]
103          Cleaned
104       [% ELSIF ( import_status == 'imported' ) %]
105         Imported
106       [% ELSIF ( import_status == 'importing' ) %]
107         Importing
108       [% ELSIF ( import_status == 'reverted' ) %]
109          Reverted
110       [% ELSIF ( import_status == 'reverting' ) %]
111          Reverting
112       [% ELSIF ( import_status == 'staged' ) %]
113           Staged
114       [% ELSE %]
115           [% import_status %]
116       [% END %]
117       </li>
118     <li>
119 [% IF ( can_commit ) %]<label for="new_matcher_id">Matching rule applied:</label><select name="new_matcher_id" id="new_matcher_id">
120        <option value="">Do not look for matching records</option> 
121        [% FOREACH available_matcher IN available_matchers %]
122           [% IF ( available_matcher.selected ) %]
123           <option value="[% available_matcher.matcher_id %]" selected="selected">
124              [% available_matcher.code %] ([% available_matcher.description %])
125           </option>
126           [% ELSE %]
127           <option value="[% available_matcher.matcher_id %]">
128             [% available_matcher.code %] ([% available_matcher.description %])
129           </option>
130           [% END %]
131        [% END %]
132     </select> <span class="change-status">Changed. <a href="#" class="reset" id="reset_new_matcher_id">Reset</a></span>[% ELSE %]<span class="label">Matching rule applied</span>[% IF ( current_matcher_id ) %]
133   [% current_matcher_code %] ([% current_matcher_description %])
134 [% ELSE %]
135   No matching rule in effect
136 [% END %][% END %]
137     </li>
138     <li>
139         [% IF ( can_commit ) %]
140             <label for="overlay_action">Action if matching record found:</label>
141             [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>
142         [% ELSE %]
143             <span class="label">Action if matching record found:</span>
144             [% IF ( overlay_action == 'replace' ) %]
145                 Replace existing record with incoming record
146             [% ELSIF ( overlay_action == 'create_new' ) %]
147                 Add incoming record
148             [% ELSIF ( overlay_action == 'ignore' ) %]
149                 Ignore incoming record (its items may still be processed)
150             [% ELSE %]
151                 [% overlay_action %]
152             [% END %]
153         [% END %]</li>
154      
155     <li>
156         [% IF ( can_commit ) %]
157             <label for="nomatch_action">Action if no match found:</label>
158             [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>
159         [% ELSE %]
160             <span class="label">Action if no match found:</span>
161             [% IF ( nomatch_action == 'create_new' ) %]
162                 Add incoming record
163             [% ELSIF ( nomatch_action == 'ignore' ) %]
164                 Ignore incoming record (its items may still be processed)
165             [% ELSE %]
166                 [% nomatch_action %]
167             [% END %]
168         [% END %]
169     </li>
170
171     [% IF ( record_type == 'biblio' ) %]
172     <li>
173         [% IF ( can_commit ) %]
174             <label for="item_action">Item processing:</label>
175             [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>
176         [% ELSE %]
177             <span class="label">Item processing:</span>
178             [% IF ( item_action == 'always_add' ) %]
179                 Always add items
180             [% ELSIF ( item_action == 'add_only_for_matches' ) %]
181                 Add items only if matching bib was found
182             [% ELSIF ( item_action == 'add_only_for_new' ) %]
183                 Add items only if no matching bib was found
184             [% ELSIF ( item_action == 'ignore' ) %]
185                 Ignore items
186             [% ELSE %]
187                 [% item_action %]
188             [% END %]
189         [% END %]
190     </li>
191     [% END %]
192   </ol>
193 [% IF ( can_commit ) %]<fieldset class="action"><input type="submit" value="Apply different matching rules" class="button" /></fieldset></form>[% END %]
194 </fieldset>
195
196
197 <div>
198   [% IF ( can_commit ) %]
199   <form action="[% script_name %]" method="post" id="import_batch_form">
200     <input type="hidden" name="op" value="commit-batch" />
201     <input type="hidden" name="runinbackground" value="" />
202     <input type="hidden" name="completedJobID" value="" />
203     <input type="hidden" name="import_batch_id" value="[% import_batch_id %]" />
204     <fieldset class="action">
205     [% IF ( record_type != 'auth' ) %]
206     Add new bibliographic records into this framework:
207     <select name="framework" id="frameworks">
208       <option value="">Default</option>
209       [% FOREACH framework IN frameworks %]
210           <option value="[% framework.frameworkcode %]">[% framework.frameworktext %]</option>
211       [% END %]
212     </select>
213     [% END %]
214     <br/>
215     <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
216     </fieldset>
217   </form>
218   <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
219      <div id="jobfailed"></div></div>
220   [% END %]
221   [% IF ( can_revert ) %]
222   <form action="[% script_name %]" method="post" id="revert_batch_form">
223     <input type="hidden" name="op" value="revert-batch" />
224     <input type="hidden" name="runinbackground" value="" />
225     <input type="hidden" name="completedJobID" value="" />
226     <input type="hidden" name="import_batch_id" value="[% import_batch_id %]" />
227     <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" /></fieldset>
228   </form>
229   <div id="jobpanel"><div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
230      <div id="jobfailed"></div></div>
231   [% END %]
232 </div>
233   [% IF ( did_commit ) %]
234   <div class="dialog message">Completed import of records</div>
235   <table>
236   <tr><td>Number of records added</td><td>[% num_added %]</td></tr>
237   <tr><td>Number of records updated</td><td>[% num_updated %]</td></tr>
238   <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr>
239   [% IF ( record_type == 'biblio' ) %]
240       <tr><td>Number of items added</td><td>[% num_items_added %]</td></tr>
241       <tr><td>Number of items replaced</td><td>[% num_items_replaced %]</td></tr>
242       <tr><td>Number of items ignored because of duplicate barcode</td><td>[% num_items_errored %]</td></tr>
243   [% END %]
244   </table>
245   [% END %]
246   [% IF ( did_revert ) %]
247   <div class="dialog message">Success: Import reversed</div>
248   <table>
249   <tr><td>Number of records deleted</td><td>[% num_deleted %]</td></tr>
250   [% IF ( record_type == 'biblio' ) %]
251     <tr><td>Number of items deleted</td><td>[% num_items_deleted %]</td></tr>
252     <tr><td>Number of records not deleted due to items on loan</td><td>[% num_errors %]</td></tr>
253   [% END %]
254   <tr><td>Number of records changed back</td><td>[% num_reverted %]</td></tr>
255   <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr>
256   </table>
257   [% END %]
258 [% END %]
259 <br style="clear:both;" />
260
261 [% IF ( batch_list ) %]
262   [% IF ( pages ) %]
263 <div class="pages">
264     [% FOREACH page IN pages %]
265       [% IF ( page.current_page ) %]
266       <span class="current">[% page.page_number %]</span>
267       [% ELSE %]
268       <a href="[% page.script_name %]?offset=[% page.offset %]">[% page.page_number %]</a>
269       [% END %]
270     [% END %]
271 </div>
272   [% END %]
273 <table>
274   <tr>
275     <th>#</th>
276     <th>File name</th>
277     <th>Comments</th>
278     <th>Type</th>
279     <th>Status</th>
280     <th>Staged</th>
281     <th># Records</th>
282     <th># Items</th>
283     <th>Action</th>
284   </tr>
285   [% FOREACH batch_lis IN batch_list %]
286     <tr>
287     <td>[% batch_lis.import_batch_id %]</td>
288     <td><a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]">[% batch_lis.file_name %]</a></td>
289     <td>[% batch_lis.comments %]</td>
290     <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
291     <td>
292       [% IF ( batch_lis.import_status == 'cleaned' ) %]
293          Cleaned
294       [% ELSIF ( batch_lis.import_status == 'imported' ) %]
295         Imported
296       [% ELSIF ( batch_lis.import_status == 'importing' ) %]
297         Importing
298       [% ELSIF ( batch_lis.import_status == 'reverted' ) %]
299          Reverted
300       [% ELSIF ( batch_lis.import_status == 'reverting' ) %]
301          Reverting
302       [% ELSIF ( batch_lis.import_status == 'staged' ) %]
303           Staged
304       [% ELSE %]
305           [% batch_lis.import_status %]
306       [% END %]
307     </td>
308     <td>[% batch_lis.upload_timestamp %]</td>
309     <td>[% batch_lis.num_records %]</td>
310     <td>[% batch_lis.num_items %][% IF ( batch_lis.num_items ) %] <a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]&amp;op=create_labels">(Create label batch)</a>[% END %]</td>
311     <td class="actions">
312         [% IF ( batch_lis.can_clean ) %]
313           <form method="post" action="[% batch_lis.script_name %]" name="clean_batch_[% batch_lis.import_batch_id %]" id="clean_batch_[% batch_lis.import_batch_id %]" class="batch_form batch_clean" >
314             <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id %]" />
315             <input type="hidden" name="op" value="clean-batch" />
316             <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-eraser"></i> Clean</button>
317           </form>
318         [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
319           <form method="post" action="/cgi-bin/koha/tools/manage-marc-import.pl" name="delete_batch_[% batch_lis.import_batch_id %]" id="delete_batch_[% batch_lis.import_batch_id %]" class="batch_form batch_delete">
320             <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id %]" />
321             <input type="hidden" name="op" value="delete-batch" />
322             <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</button>
323           </form>
324         [% END %]
325     </td>
326   </tr>
327   [% END %]
328 </table>
329   [% IF ( pages ) %]
330 <div class="pages">
331     [% FOREACH page IN pages %]
332       [% IF ( page.current_page ) %]
333       <span class="current">[% page.page_number %]</span>
334       [% ELSE %]
335       <a href="[% page.script_name %]?offset=[% page.offset %]">[% page.page_number %]</a>
336       [% END %]
337     [% END %]
338 </div>
339   [% END %]
340 [% END %]
341
342 [% IF import_batch_id %]
343     <table id="records-table">
344         <thead>
345             <tr>
346                 <th>#</th>
347                 <th>Citation</th>
348                 <th>Status</th>
349                 <th>Match type</th>
350                 <th>Match details</th>
351                 <th><abbr title="Differences between the original biblio and the imported">Diff</abbr></th>
352                 <th>Record</th>
353             </tr>
354         </thead>
355     </table>
356
357     <div id="marcPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
358         <div class="modal-dialog">
359         <div class="modal-content">
360         <div class="modal-header">
361             <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
362             <h3 id="marcPreviewLabel">MARC preview</h3>
363         </div>
364         <div class="modal-body">
365             <div id="loading"> <img src="[% interface %]/[% theme %]/img/spinner-small.gif" alt="" /> Loading </div>
366         </div>
367         <div class="modal-footer">
368             <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
369         </div>
370         </div>
371         </div>
372     </div>
373 [% END %]
374
375 </div>
376 </div>
377 <div class="yui-b">
378 [% INCLUDE 'tools-menu.inc' %]
379 </div>
380 </div>
381
382 [% MACRO jsinclude BLOCK %]
383     <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
384 <script type="text/javascript" src="[% interface %]/[% theme %]/js/background-job-progressbar.js"></script>
385     [% INCLUDE 'datatables.inc' %]
386     <script type="text/javascript">
387         $(document).ready(function(){
388             $("#staged-record-matching-rules select").change(function(){
389                 var str = $(this).attr("id");
390                 $("#reset_"+str).parent().show();
391             });
392             $("a.reset").click(function(){
393                 var str = $(this).attr("id");
394                 str = str.replace("reset_","")
395                 $("#"+str+" option[selected='selected']").attr("selected","selected");
396                 $(this).parent().hide();
397             });
398
399             [% IF import_batch_id %]
400                 $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
401                     "bAutoWidth": false,
402                     "bFilter": false,
403                     "bProcessing": true,
404                     "bServerSide": true,
405                     "sAjaxSource": 'batch_records_ajax.pl',
406                     "sPaginationType": "full_numbers",
407                     "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
408                     "aoColumns": [
409                         { "mDataProp": "import_record_id" },
410                         { "mDataProp": "citation" },
411                         { "mDataProp": "status" },
412                         { "mDataProp": "overlay_status" },
413                         { "mDataProp": "match_citation" },
414                         { "mDataProp": "diff_url" },
415                         { "mDataProp": "matched" }
416                     ],
417                     "fnServerData": function ( sSource, aoData, fnCallback ) {
418                         aoData.push( { "name": "import_batch_id", "value": [% import_batch_id %] } );
419
420                         $.ajax({
421                             'dataType': 'json',
422                             'type': 'POST',
423                             'url': sSource,
424                             'data': aoData,
425                             'success': function(json){
426                                 fnCallback(json);
427                             }
428                         });
429                     },
430                     "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
431                       [% IF ( record_type == 'auth' ) %]
432                           var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
433                       [% ELSE %]
434                           var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
435                       [% END %]
436
437                       $('td:eq(1)', nRow).html(
438                           '<a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=' + aData['import_record_id'] + '&viewas=html" class="previewMARC">' + aData['citation'] + '</a>'
439                       );
440
441                       $('td:eq(2)', nRow).html(
442                           aData['status'] == 'imported' ? _("Imported") :
443                           aData['status'] == 'ignored'  ? _("Ignored")  :
444                           aData['status'] == 'reverted' ? _("Reverted") :
445                           aData['status'] == 'staged'   ? _("Staged")   :
446                           aData['status'] == 'error'    ? _("Error")    :
447                           aData['status']
448                       );
449
450                       $('td:eq(3)', nRow).html(
451                           aData['overlay_status'] == 'no_match'      ? _("No match")       :
452                           aData['overlay_status'] == 'match_applied' ? _("Match applied")  :
453                           aData['overlay_status'] == 'auto_match'    ? _("Match found")    :
454                           aData['overlay_status']
455                       );
456
457                       if ( aData['match_id'] ) {
458                           [% IF ( record_type == 'auth' ) -%]
459                           var matching_msg = _("Matches authority %s (score=%s):%s");
460                           [%- ELSE -%]
461                           var matching_msg = _("Matches biblio %s (score=%s):%s");
462                           [%- END %]
463                           $('td:eq(4)', nRow).html(
464                               matching_msg.format(aData['match_id'], aData['score'],
465                               '<a target="_blank" href="' + record_details_url
466                               + aData['match_id'] + '">' + aData['match_citation'] + '</a>')
467                           );
468                       }
469                       if (aData['diff_url']){
470                           $('td:eq(5)', nRow).html(
471                               '<a href="'+aData['diff_url']+'">View</a>'
472                           );
473                       }
474                       $('td:eq(6)', nRow).html(
475                           '<a target="_blank" href="' + record_details_url
476                               + aData['matched'] + '">' + aData['matched'] + '</a>'
477                       );
478                     },
479                 }));
480                 $("#import_batch_form").on("submit",function(){
481                     return submitBackgroundJob( document.getElementById("import_batch_form") );
482                 });
483                 $("#revert_batch_form").on("submit",function(){
484                     return confirm( _("Are you sure you want to undo the import of this batch into the catalog?") ) &&   submitBackgroundJob( document.getElementById("revert_batch_form") );
485                 });
486             [% END %]
487             $("body").on("click",".previewMARC", function(e){
488                 e.preventDefault();
489                 var ltitle = $(this).text();
490                 var page = $(this).attr("href");
491                 $("#marcPreviewLabel").text(ltitle);
492                 $("#marcPreview .modal-body").load(page + " table");
493                 $('#marcPreview').modal({show:true});
494             });
495             $("#marcPreview").on("hidden", function(){
496                 $("#marcPreviewLabel").html("");
497                 $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
498             });
499             $(".batch_form").on("submit",function(){
500                 if( $(this).hasClass("batch_delete") ){
501                     return confirm( _("Are you sure you want to permanently delete this batch?") );
502                 } else {
503                     return confirm( _("Clear all reservoir records staged in this batch?  This cannot be undone.") );
504                 }
505             });
506         });
507     </script>
508 [% END %]
509
510 [% INCLUDE 'intranet-bottom.inc' %]