Bug 14790 - Add OPAC view link to items editor
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / manage-marc-import.tt
index 8265b50..e1119d1 100644 (file)
@@ -1,6 +1,6 @@
 [% BLOCK final_match_link %]
     [% IF ( record.record_type == 'biblio' ) %]
-        <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.final_match_id %]">[% record.final_match_id %]</a>
+        <a target="_blank" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.final_match_id %]">[% record.final_match_id %]</a>
     [% ELSIF ( record.record_type == 'auth' ) %]
         <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record.final_match_id %]">[% record.final_match_id %]</a>
     [% END %]
         <tr>
             <td />
             [% IF ( record.record_type == 'biblio' ) %]
-                <td class="highlight" colspan="4">Matches biblio [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record_lis.match_id %]">[% record_lis.match_citation %]</a></td>
+                <td colspan="5">Matches biblio [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record_lis.match_id %]">[% record_lis.match_citation %]</a></td>
             [% ELSIF ( record.record_type == 'auth' ) %]
-                <td class="highlight" colspan="4">Matches authority [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record_lis.match_id %]">[% record_lis.match_citation %]</a></td>
+                <td colspan="5">Matches authority [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record_lis.match_id %]">[% record_lis.match_citation %]</a> |
+        <a href="/cgi-bin/koha/authorities/merge.pl?mergereference=breeding&authid=[% record_lis.match_id %]&authid=[% record_lis.import_record_id %]">Merge</a>
+                </td>
             [% END %]
         </tr>
+    [% ELSIF ( record.record_type == 'auth') %]
+        <tr data-authid="[% record_lis.import_record_id %]">
+            <td />
+            <td  colspan="4"><a href="#" class="merge_auth">Search for a record to merge in a new window</a></td>
+        </tr>
     [% END %]
 [% END %]
+
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records
 [% IF ( import_batch_id ) %]
  &rsaquo; Batch [% import_batch_id %]
 [% END %]
 </title>
-[% INCLUDE 'greybox.inc' %]
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
-<script type="text/JavaScript" language="JavaScript">
+<script type="text/javascript" src="[% interface %]/[% theme %]/js/background-job-progressbar.js"></script>
+<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
+[% INCLUDE 'datatables.inc' %]
+<script type="text/javascript">
 //<![CDATA[
+var MSG_CONFIRM_CLEAN = _("Clear all reservoir records staged in this batch?  This cannot be undone.");
+var MSG_CONFIRM_UNDO_IMPORT = _("Are you sure you want to undo the import of this batch into the catalog?");
+var MSG_CONFIRM_DELETE = _("Are you sure you want to permanently delete this batch?");
+
 $(document).ready(function(){
   $("#staged-record-matching-rules select").change(function(){
       var str = $(this).attr("id");
@@ -39,13 +52,110 @@ $(document).ready(function(){
       $("#"+str+" option[selected='selected']").attr("selected","selected");
       $(this).parent().hide();
   });
+
+  [% IF import_batch_id %]
+      $("#records-table").dataTable($.extend(true, {}, dataTablesDefaults, {
+          "bAutoWidth": false,
+          "bFilter": false,
+          "bProcessing": true,
+          "bServerSide": true,
+          "sAjaxSource": 'batch_records_ajax.pl',
+          "sPaginationType": "full_numbers",
+          "sDom": '<"top pager"iflp>rt<"bottom pager"flp><"clear">',
+          "aoColumns": [
+              { "mDataProp": "import_record_id" },
+              { "mDataProp": "citation" },
+              { "mDataProp": "status" },
+              { "mDataProp": "overlay_status" },
+              { "mDataProp": "match_citation" },
+              { "mDataProp": "diff_url" },
+              { "mDataProp": "matched" }
+          ],
+          "fnServerData": function ( sSource, aoData, fnCallback ) {
+              aoData.push( { "name": "import_batch_id", "value": [% import_batch_id %] } );
+
+              $.ajax({
+                  'dataType': 'json',
+                  'type': 'POST',
+                  'url': sSource,
+                  'data': aoData,
+                  'success': function(json){
+                      fnCallback(json);
+                  }
+              });
+          },
+          "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+            [% IF ( record_type == 'auth' ) %]
+                var record_details_url = "/cgi-bin/koha/authorities/detail.pl?authid=";
+            [% ELSE %]
+                var record_details_url = "/cgi-bin/koha/catalogue/detail.pl?biblionumber=";
+            [% END %]
+
+            $('td:eq(1)', nRow).html(
+                '<a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=' + aData['import_record_id'] + '&viewas=html" class="previewMARC">' + aData['citation'] + '</a>'
+            );
+
+            $('td:eq(2)', nRow).html(
+                aData['status'] == 'imported' ? _("Imported") :
+                aData['status'] == 'ignored'  ? _("Ignored")  :
+                aData['status'] == 'reverted' ? _("Reverted") :
+                aData['status'] == 'staged'   ? _("Staged")   :
+                aData['status'] == 'error'    ? _("Error")    :
+                aData['status']
+            );
+
+            $('td:eq(3)', nRow).html(
+                aData['overlay_status'] == 'no_match'      ? _("No match")       :
+                aData['overlay_status'] == 'match_applied' ? _("Match applied")  :
+                aData['overlay_status'] == 'auto_match'    ? _("Match found")    :
+                aData['overlay_status']
+            );
+
+            if ( aData['match_id'] ) {
+                [% IF ( record_type == 'auth' ) -%]
+                var matching_msg = _("Matches authority %s (score=%s):%s");
+                [%- ELSE -%]
+                var matching_msg = _("Matches biblio %s (score=%s):%s");
+                [%- END %]
+                $('td:eq(4)', nRow).html(
+                    matching_msg.format(aData['match_id'], aData['score'],
+                    '<a target="_blank" href="' + record_details_url
+                    + aData['match_id'] + '">' + aData['match_citation'] + '</a>')
+                );
+            }
+            if (aData['diff_url']){
+                $('td:eq(5)', nRow).html(
+                    '<a href="'+aData['diff_url']+'">View</a>'
+                );
+            }
+            $('td:eq(6)', nRow).html(
+                '<a target="_blank" href="' + record_details_url
+                    + aData['matched'] + '">' + aData['matched'] + '</a>'
+            );
+          },
+      }));
+    [% END %]
+    $("body").on("click",".previewMARC", function(e){
+        e.preventDefault();
+        var ltitle = $(this).text();
+        var page = $(this).attr("href");
+        $("#marcPreviewLabel").text(ltitle);
+        $("#marcPreview .modal-body").load(page + " table");
+        $('#marcPreview').modal({show:true});
+    });
+    $("#marcPreview").on("hidden", function(){
+        $("#marcPreviewLabel").html("");
+        $("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/loading-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
+    });
 });
+
 //]]>
 </script>
 <style type="text/css">
        #jobpanel,#jobstatus,#jobfailed { display : none; }
        #jobstatus { margin:.4em; }
-       #jobprogress{ width:200px;height:10px;border:1px solid #666;background:url('/intranet-tmpl/prog/img/progress.png') -300px 0px no-repeat; } span.change-status { font-style:italic; color:#666; display:none; }</style>
+    #jobprogress{ width:200px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; } span.change-status { font-style:italic; color:#666; display:none; }#marcPreview { width : 80%; margin-left : -40%; } @media (max-width: 767px) { #marcPreview { margin: 0; width : auto; } }
+</style>
 </head>
 <body id="tools_manage-marc-import" class="tools">
 [% INCLUDE 'header.inc' %]
@@ -76,7 +186,7 @@ $(document).ready(function(){
 [% IF ( alert ) %]
 <div class="alert">
 [% ELSE %]
-<div class="dialog">
+<div class="dialog message">
 [% END %]
 <b><p>[% label_batch_msg %]</p></b>
 </div>
@@ -86,6 +196,10 @@ $(document).ready(function(){
   <div class="dialog message">Cleaned import batch #[% import_batch_id %]</div>
 [% END %]
 
+[% IF ( did_delete ) %]
+  <div class="dialog message">Import batch deleted successfully</div>
+[% END %]
+
 [% UNLESS ( batch_list ) %]
    [% UNLESS ( batch_info ) %]
    <div class="dialog message">
@@ -129,8 +243,24 @@ $(document).ready(function(){
     <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments %][% ELSE %](none)[% END %]</li>
     <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
     <li><span class="label">Staged:</span> [% upload_timestamp %]</li>
-    <li><span class="label">Status:</span> [% import_status %]</li>
-    <li> 
+    <li><span class="label">Status:</span>
+      [% IF ( import_status == 'cleaned' ) %]
+         Cleaned
+      [% ELSIF ( import_status == 'imported' ) %]
+        Imported
+      [% ELSIF ( import_status == 'importing' ) %]
+        Importing
+      [% ELSIF ( import_status == 'reverted' ) %]
+         Reverted
+      [% ELSIF ( import_status == 'reverting' ) %]
+         Reverting
+      [% ELSIF ( import_status == 'staged' ) %]
+          Staged
+      [% ELSE %]
+          [% import_status %]
+      [% END %]
+      </li>
+    <li>
 [% IF ( can_commit ) %]<label for="new_matcher_id">Matching rule applied:</label><select name="new_matcher_id" id="new_matcher_id">
        <option value="">Do not look for matching records</option> 
        [% FOREACH available_matcher IN available_matchers %]
@@ -150,14 +280,60 @@ $(document).ready(function(){
   No matching rule in effect
 [% END %][% END %]
     </li>
-    <li>[% IF ( can_commit ) %] <label for="overlay_action">Action if matching record found:</label>
-     [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>[% ELSE %]<span class="label">Action if matching record found:</span>[% overlay_action %][% END %]</li>
+    <li>
+        [% IF ( can_commit ) %]
+            <label for="overlay_action">Action if matching record found:</label>
+            [% INCLUDE 'tools-overlay-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_overlay_action">Reset</a></span>
+        [% ELSE %]
+            <span class="label">Action if matching record found:</span>
+            [% IF ( overlay_action == 'replace' ) %]
+                Replace existing record with incoming record
+            [% ELSIF ( overlay_action == 'create_new' ) %]
+                Add incoming record
+            [% ELSIF ( overlay_action == 'ignore' ) %]
+                Ignore incoming record (its items may still be processed)
+            [% ELSE %]
+                [% overlay_action %]
+            [% END %]
+        [% END %]</li>
      
-    <li>[% IF ( can_commit ) %]<label for="nomatch_action">Action if no match found:</label>
-     [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>[% ELSE %]<span class="label">Action if no match found:</span>[% nomatch_action %][% END %]</li>
-    
-    <li>[% IF ( can_commit ) %]<label for="item_action">Item processing:</label>
-     [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>[% ELSE %]<span class="label">Item processing:</span>[% item_action %][% END %]</li>
+    <li>
+        [% IF ( can_commit ) %]
+            <label for="nomatch_action">Action if no match found:</label>
+            [% INCLUDE 'tools-nomatch-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_nomatch_action">Reset</a></span>
+        [% ELSE %]
+            <span class="label">Action if no match found:</span>
+            [% IF ( nomatch_action == 'create_new' ) %]
+                Add incoming record
+            [% ELSIF ( nomatch_action == 'ignore' ) %]
+                Ignore incoming record (its items may still be processed)
+            [% ELSE %]
+                [% nomatch_action %]
+            [% END %]
+        [% END %]
+    </li>
+
+    [% IF ( record_type == 'biblio' ) %]
+    <li>
+        [% IF ( can_commit ) %]
+            <label for="item_action">Item processing:</label>
+            [% INCLUDE 'tools-item-action.inc' %] <span class="change-status">Changed. <a href="#" class="reset" id="reset_item_action">Reset</a></span>
+        [% ELSE %]
+            <span class="label">Item processing:</span>
+            [% IF ( item_action == 'always_add' ) %]
+                Always add items
+            [% ELSIF ( item_action == 'add_only_for_matches' ) %]
+                Add items only if matching bib was found
+            [% ELSIF ( item_action == 'add_only_for_new' ) %]
+                Add items only if no matching bib was found
+            [% ELSIF ( item_action == 'ignore' ) %]
+                Ignore items
+            [% ELSE %]
+                [% item_action %]
+            [% END %]
+        [% END %]
+    </li>
+    [% END %]
   </ol>
 [% IF ( can_commit ) %]<fieldset class="action"><input type="submit" value="Apply different matching rules" class="button" /></fieldset></form>[% END %]
 </fieldset>
@@ -173,6 +349,7 @@ $(document).ready(function(){
     <fieldset class="action">
     <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" onclick="return submitBackgroundJob(this.form);" />
     <br/>
+    [% IF ( record_type != 'auth' ) %]
     Add new bibliographic records into this framework:
     <select name="framework" id="frameworks">
       <option value="">Default</option>
@@ -180,6 +357,7 @@ $(document).ready(function(){
           <option value="[% framework.value %]">[% framework.label %]</option>
       [% END %]
     </select>
+    [% END %]
     </fieldset>
   </form>
   <div id="jobpanel"><div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
@@ -191,7 +369,7 @@ $(document).ready(function(){
     <input type="hidden" name="runinbackground" value="" />
     <input type="hidden" name="completedJobID" value="" />
     <input type="hidden" name="import_batch_id" value="[% import_batch_id %]" />
-    <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" onclick="return submitBackgroundJob(this.form);" /></fieldset>
+    <fieldset class="action"><input type="submit" class="button" name="mainformsubmit" value="Undo import into catalog" onclick="return confirm(MSG_CONFIRM_UNDO_IMPORT) && submitBackgroundJob(this.form);" /></fieldset>
   </form>
   <div id="jobpanel"><div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
      <div id="jobfailed"></div></div>
@@ -203,16 +381,21 @@ $(document).ready(function(){
   <tr><td>Number of records added</td><td>[% num_added %]</td></tr>
   <tr><td>Number of records updated</td><td>[% num_updated %]</td></tr>
   <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr>
-  <tr><td>Number of items added</td><td>[% num_items_added %]</td></tr>
-  <tr><td>Number of items ignored because of duplicate barcode</td><td>[% num_items_errored %]</td></tr>
+  [% IF ( record_type == 'biblio' ) %]
+      <tr><td>Number of items added</td><td>[% num_items_added %]</td></tr>
+      <tr><td>Number of items replaced</td><td>[% num_items_replaced %]</td></tr>
+      <tr><td>Number of items ignored because of duplicate barcode</td><td>[% num_items_errored %]</td></tr>
+  [% END %]
   </table>
   [% END %]
   [% IF ( did_revert ) %]
   <div class="dialog message">Success: Import reversed</div>
   <table>
   <tr><td>Number of records deleted</td><td>[% num_deleted %]</td></tr>
-  <tr><td>Number of items deleted</td><td>[% num_items_deleted %]</td></tr>
-  <tr><td>Number of records not deleted due to items on loan</td><td>[% num_errors %]</td></tr>
+  [% IF ( record_type == 'biblio' ) %]
+    <tr><td>Number of items deleted</td><td>[% num_items_deleted %]</td></tr>
+    <tr><td>Number of records not deleted due to items on loan</td><td>[% num_errors %]</td></tr>
+  [% END %]
   <tr><td>Number of records changed back</td><td>[% num_reverted %]</td></tr>
   <tr><td>Number of records ignored</td><td>[% num_ignored %]</td></tr>
   </table>
@@ -246,20 +429,43 @@ Page
     <th>Action</th>
   </tr>
   [% FOREACH batch_lis IN batch_list %]
-  [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
+    <tr>
     <td>[% batch_lis.import_batch_id %]</td>
     <td><a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]">[% batch_lis.file_name %]</a></td>
     <td>[% batch_lis.comments %]</td>
     <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
-    <td>[% batch_lis.import_status %]</td>
+    <td>
+      [% IF ( batch_lis.import_status == 'cleaned' ) %]
+         Cleaned
+      [% ELSIF ( batch_lis.import_status == 'imported' ) %]
+        Imported
+      [% ELSIF ( batch_lis.import_status == 'importing' ) %]
+        Importing
+      [% ELSIF ( batch_lis.import_status == 'reverted' ) %]
+         Reverted
+      [% ELSIF ( batch_lis.import_status == 'reverting' ) %]
+         Reverting
+      [% ELSIF ( batch_lis.import_status == 'staged' ) %]
+          Staged
+      [% ELSE %]
+          [% batch_lis.import_status %]
+      [% END %]
+    </td>
     <td>[% batch_lis.upload_timestamp %]</td>
     <td>[% batch_lis.num_records %]</td>
     <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>
-    <td>[% IF ( batch_lis.can_clean ) %]
+    <td class="actions">
+        [% IF ( batch_lis.can_clean ) %]
           <form method="post" action="[% batch_lis.script_name %]" name="clean_batch_[% batch_lis.import_batch_id %]" id="clean_batch_[% batch_lis.import_batch_id %]" >
             <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id %]" />
             <input type="hidden" name="op" value="clean-batch" />
-            <input type="submit" class="button" value="Clean" onclick="return confirm(_('Clear all reservoir records staged in this batch?  This cannot be undone.'));" />
+            <button class="btn btn-mini" onclick="return confirm(MSG_CONFIRM_CLEAN);"><i class="fa fa-eraser"></i> Clean</button>
+          </form>
+        [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
+          <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 %]">
+            <input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id %]" />
+            <input type="hidden" name="op" value="delete-batch" />
+            <button class="btn btn-mini" onclick="return confirm(MSG_CONFIRM_DELETE);"><i class="fa fa-trash"></i> Delete</button>
           </form>
         [% END %]
     </td>
@@ -280,60 +486,33 @@ Page
   [% END %]
 [% END %]
 
-[% IF ( record_list ) %]
-  [% IF ( pages ) %]
-<div class="pages">
-Page 
-    [% FOREACH page IN pages %]
-      [% IF ( page.current_page ) %]
-      <span class="current">[% page.page_number %]</span>
-      [% ELSE %]
-      <a class="nav" href="[% page.script_name %]?import_batch_id=[% import_batch_id %]&amp;offset=[% page.offset %]">[% page.page_number %]</a>
-      [% END %]
-    [% END %]
-</div>
-  [% END %]
-<table>
-  <tr>
-    <th>#</th>
-    <th>Citation</th>
-    <th>Status</th>
-    <th>Match?</th>
-    <th>Record</th>
-
-  </tr>
-  [% FOREACH record_lis IN record_list %]
-  [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
-    <td>[% record_lis.record_sequence %]</td>
-    <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% record_lis.import_record_id %]" rel="gb_page_center[600,500]">[% record_lis.citation %]</a></td>
-    <td>[% record_lis.status %]</td>
-    <td>[% record_lis.overlay_status %]</td>
-    <td>[% IF ( record_lis.final_match_id ) %]
-        [% PROCESS final_match_link record=record_lis %]
-        [% END %]
-    </td>
-  </tr>
-    [% PROCESS match_link record=record_lis %]
-  [% END %]
-</table>
-  [% IF ( pages ) %]
-<div class="pages">
-Page 
-    [% FOREACH page IN pages %]
-      [% IF ( page.current_page ) %]
-      <span class="current">[% page.page_number %]</span>
-      [% ELSE %]
-      <a class="nav" href="[% page.script_name %]?import_batch_id=[% import_batch_id %]&amp;offset=[% page.offset %]">[% page.page_number %]</a>
-      [% END %]
-    [% END %]
-</div>
-  [% END %]
-[% ELSE %]
-  [% IF ( batch_info ) %]
-    <div class="dialog alert">There are no records in this batch to import.
-    <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a>.</div>
+[% IF import_batch_id %]
+    <table id="records-table">
+        <thead>
+            <tr>
+                <th>#</th>
+                <th>Citation</th>
+                <th>Status</th>
+                <th>Match type</th>
+                <th>Match details</th>
+                <th><abbr title="Differences between the original biblio and the imported" lang="en">Diff</abbr></th>
+                <th>Record</th>
+            </tr>
+        </thead>
+    </table>
 
-  [% END %]
+    <div id="marcPreview" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="marcPreviewLabel" aria-hidden="true">
+        <div class="modal-header">
+            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
+            <h3 id="marcPreviewLabel">MARC preview</h3>
+        </div>
+        <div class="modal-body">
+            <div id="loading"> <img src="[% interface %]/[% theme %]/img/loading-small.gif" alt="" /> Loading </div>
+        </div>
+        <div class="modal-footer">
+            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
+        </div>
+    </div>
 [% END %]
 
 </div>