Bug 13618: Add html filters to all the variables
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / stage-marc-import.tt
index 4846872..58d114d 100644 (file)
@@ -1,35 +1,13 @@
+[% USE raw %]
+[% USE Asset %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Stage MARC records for import</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'file-upload.inc' %]
-<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
 <style type="text/css">
-       #uploadpanel,#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
-       #fileuploadstatus,#jobstatus { margin:.4em; }
-       #fileuploadprogress,#jobprogress{ width:150px;height:10px;border:1px solid #666;background:url('/intranet-tmpl/prog/img/progress.png') -300px 0px no-repeat; }</style>
-<script type="text/javascript">
-//<![CDATA[
-$(document).ready(function(){
-       $("#processfile").hide();
-    $("#record_type").change(function() {
-        if ($(this).val() == 'auth') {
-            $('#items').hide();
-        } else {
-            $('#items').show();
-        }
-    });
-});
-function CheckForm(f) {
-    if ($("#fileToUpload").value == '') {
-        alert(_('Please upload a file first.'));
-    } else {
-        return submitBackgroundJob(f);
-    }
-    return false;
-}
+    #fileuploadstatus,#fileuploadfailed,#fileuploadcancel,#jobpanel,#jobstatus,#jobfailed { display : none; }
+</style>
 
-//]]>
-</script>
 </head>
 <body id="tools_stage-marc-import" class="tools">
 [% INCLUDE 'header.inc' %]
@@ -43,6 +21,13 @@ function CheckForm(f) {
        <div id="yui-main">
        <div class="yui-b">
 
+[% IF ( uploadmarc ) %]
+<div id="toolbar" class="btn-toolbar">
+        <a class="btn btn-default btn-sm" href="/cgi-bin/koha/tools/stage-marc-import.pl"><i class="fa fa-plus"></i> Stage MARC records</a>
+        <a class="btn btn-default btn-sm" 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>
+</div>
+[% END %]
+
 <h1>Stage MARC records for import</h1>
 [% IF ( uploadmarc ) %]
 <p>MARC staging results :</p>
@@ -53,12 +38,12 @@ function CheckForm(f) {
     [% CASE 'auth' %]
         <li>Processing authority records</li>
     [% END %]
-       <li>[% total %]  records in file</li>
-       <li>[% import_errors %] records not staged because of MARC error</li>
-       <li>[% staged %] records staged</li>
+       <li>[% total | html %]  records in file</li>
+       <li>[% import_errors | html %] records not staged because of MARC error</li>
+       <li>[% staged | html %] records staged</li>
     [% IF ( checked_matches ) %]
-       <li>[% matched %] records with at least one match in catalog per matching rule 
-        &quot;[% matcher_code %]&quot;</li>
+       <li>[% matched | html %] records with at least one match in catalog per matching rule 
+        &quot;[% matcher_code | html %]&quot;</li>
     [% ELSE %]
         [% IF ( matcher_failed ) %]
           <li>Record matching failed -- unable to retrieve selected matching rule.</li>
@@ -66,19 +51,19 @@ function CheckForm(f) {
           <li>Did not check for matches with existing records in catalog</li>
         [% END %]
     [% END %]
-       <li>[% num_items %] item records found and staged</li>
+    [% IF record_type == 'biblio' %]
+        <li>[% num_items | html %] item records found and staged</li>
+    [% END %]
        [% IF ( label_batch ) %]
-         <li>New label batch created: # [% label_batch %] </li>
+         <li>New label batch created: # [% label_batch | html %] </li>
     [% END %]
-       <li><a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% import_batch_id %]">Manage staged records</a></li>
-       <li><a href="/cgi-bin/koha/tools/tools-home.pl">Back</a></li>
 </ul>
 [% ELSE %]
 <ul>
     <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>
     <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>
 </ul>
-<form method="post" action="[% SCRIPT_NAME %]" id="uploadfile" enctype="multipart/form-data">
+<form method="post" action="[% SCRIPT_NAME | html %]" id="uploadfile" enctype="multipart/form-data">
 <fieldset class="rows" id="uploadform">
 <legend>Stage records into the reservoir</legend>
 <ol>
@@ -88,14 +73,23 @@ function CheckForm(f) {
                <input type="file" id="fileToUpload" name="fileToUpload" />
         </div> </li>
 </ol>
-        <fieldset class="action"><button class="submit" onclick="return ajaxFileUpload();">Upload file</button></fieldset>
+    <fieldset class="action">
+        <button id="fileuploadbutton">Upload file</button>
+        <button id="fileuploadcancel">Cancel</button>
+    </fieldset>
 </fieldset>
                
-        <div id="uploadpanel"><div id="fileuploadstatus">Upload progress: <div id="fileuploadprogress"></div> <span id="fileuploadpercent">0</span>%</div>
-        <div id="fileuploadfailed"></div></div>
+    <div id="fileuploadpanel">
+        <div id="fileuploadstatus" class="progress_panel">Upload progress:
+            <progress id="fileuploadprogress" max="100" value="0">
+            </progress>
+            <span class="fileuploadpercent">0</span>%
+        </div>
+        <div id="fileuploadfailed"></div>
+    </div>
 </form>
 
-    <form method="post" id="processfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
+    <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
 <fieldset class="rows">
         <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
         <input type="hidden" name="runinbackground" id="runinbackground" value="" />
@@ -114,16 +108,51 @@ function CheckForm(f) {
     </li>
        <li>
                <label for="encoding">Character encoding: </label>
-            <select name="encoding" id="encoding"><option value="utf8" selected="selected">UTF-8 (Default)</option><option value="MARC-8">MARC 8</option><option value="ISO_5426">ISO 5426</option><option value="ISO_6937">ISO 6937</option><option value=ISO_8859-1">ISO 8859-1</option><option value="EUC-KR">EUC-KR</option></select>
+            <select name="encoding" id="encoding">
+                <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
+                <option value="MARC-8">MARC 8</option>
+                <option value="ISO_5426">ISO 5426</option>
+                <option value="ISO_6937">ISO 6937</option>
+                <option value="ISO_8859-1">ISO 8859-1</option>
+                <option value="EUC-KR">EUC-KR</option>
+            </select>
        </li>
+    <li>
+        <label for='format'>Format:</label>
+        <select name='format' id='format'>
+            <option value='ISO2709'>MARC</option>
+            <option value='MARCXML'>MARCXML</option>
+            [% FOREACH p IN plugins %]
+                <option value="[% p.metadata.class | html %]">[% p.metadata.name | html %] ( other format via plugin)</option>
+            [% END %]
+        </select>
+    </li>
 </ol></fieldset>
+
+  [% IF MarcModificationTemplatesLoop %]
+    <fieldset class="rows">
+      <legend>Use MARC Modification Template:</legend>
+      <ol>
+        <li>
+          <label for="comments">Modify record using the following template: </label>
+          <select name="marc_modification_template_id" id="marc_modification_template_id">
+            <option value="">Do not use.</option>
+              [% FOREACH mmt IN MarcModificationTemplatesLoop %]
+                <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option>
+              [% END %]
+          </select>
+        </li>
+      </ol>
+    </fieldset>
+  [% END %]
+
   <fieldset class="rows">
     <legend>Look for existing records in catalog?</legend>
     <ol><li><label for="matcher">Record matching rule:</label>
     <select name="matcher" id="matcher">
        <option value="">Do not look for matching records</option> 
        [% FOREACH available_matcher IN available_matchers %]
-          <option value="[% available_matcher.matcher_id %]">[% available_matcher.code %] ([% available_matcher.description %])
+          <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])
           </option>
        [% END %]
     </select>
@@ -154,9 +183,9 @@ function CheckForm(f) {
       </li>
     </ol>
   </fieldset>
-  <fieldset class="action"><input type="button" id="mainformsubmit" onclick="return CheckForm(this.form);" value="Stage for import" /></fieldset>
+  <fieldset class="action"><input type="button" id="mainformsubmit" value="Stage for import" /></fieldset>
  
-       <div id="jobpanel"><div id="jobstatus">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
+       <div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
      <div id="jobfailed"></div></div>
   
 </form>
@@ -168,4 +197,86 @@ function CheckForm(f) {
 [% INCLUDE 'tools-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    [% Asset.js("js/tools-menu.js") | $raw %]
+    [% Asset.js("js/background-job-progressbar.js") | $raw %]
+    [% Asset.js("js/file-upload.js") | $raw %]
+    <script type="text/javascript">
+        var xhr;
+        $(document).ready(function(){
+            $("#processfile").hide();
+            $("#record_type").change(function() {
+                if ($(this).val() == 'auth') {
+                    $('#items').hide();
+                } else {
+                    $('#items').show();
+                }
+            });
+            $("#fileuploadbutton").on("click",function(e){
+                e.preventDefault();
+                StartUpload();
+            });
+            $("#fileuploadcancel").on("click",function(e){
+                e.preventDefault();
+                CancelUpload();
+            });
+            $("#mainformsubmit").on("click",function(){
+                return CheckForm( document.getElementById("processfile"));
+            });
+        });
+        function CheckForm(f) {
+            if ($("#fileToUpload").value == '') {
+                alert(_("Please upload a file first."));
+            } else {
+                return submitBackgroundJob(f);
+            }
+            return false;
+        }
+        function StartUpload() {
+            if( $('#fileToUpload').prop('files').length == 0 ) return;
+            $('#fileuploadbutton').hide();
+            $("#fileuploadfailed").hide();
+            $("#processfile").hide();
+            $("#fileuploadstatus").show();
+            $("#uploadedfileid").val('');
+            xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
+            $("#fileuploadcancel").show();
+        }
+        function CancelUpload() {
+            if( xhr ) xhr.abort();
+            $("#fileuploadstatus").hide();
+            $('#fileuploadbutton').show();
+            $("#fileuploadcancel").hide();
+            $("#fileuploadfailed").show();
+            $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
+        }
+        function cbUpload( status, fileid, errors ) {
+            if( status=='done' ) {
+                $("#uploadedfileid").val( fileid );
+                $('#fileToUpload').prop('disabled',true);
+                $('#fileuploadbutton').prop('disabled',true);
+                $('#fileuploadbutton').show();
+                $("#fileuploadcancel").hide();
+                var filename=$('#fileToUpload').prop('files')[0].name;
+                if( filename.match( new RegExp(/\.[^.]+xml$/) ) ) {
+                    $('#format').val('MARCXML');
+                }
+                $("#processfile").show();
+            } else {
+                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") ];
+                var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
+                $('#fileuploadbutton').show();
+                $("#fileuploadcancel").hide();
+                $("#fileuploadstatus").hide();
+                $("#fileuploadfailed").show();
+                $("#fileuploadfailed").text( _("Upload status: ") +
+                    ( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
+                    ( status=='denied'? _("Denied"): status ))
+                );
+            }
+        }
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]