Bug 19672: Move tools templates JavaScript to the footer: More MARC tools
authorOwen Leonard <oleonard@myacpl.org>
Tue, 21 Nov 2017 15:14:58 +0000 (15:14 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Dec 2017 14:34:22 +0000 (11:34 -0300)
This patch modifies some staff client templates from the "Tools"
section so that JavaScript is included in the footer instead of the
header.

- Automatic item modifications by age
- MARC modification templates
- Stage MARC records for import
- Staged MARC record management

To test, apply the patch and test the JavaScript-driven features of
each modified template: All button controls, DataTables functionality,
form validation, etc.

Signed-off-by: Claire Gravely <claire.gravely@bsz-bw.de>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/showdiffmarc.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt

index 44aa3ff..205b71d 100644 (file)
@@ -1,24 +1,9 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Automatic item modifications by age</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat.js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/automatic_item_modification_by_age.js"></script>
-[% IF op == 'edit_form' %]
-    <script type="text/javascript">//<![CDATA[
-      $(document).ready(function() {
-            [% IF ( op == 'edit_form' ) %]
-                $('#toolbar').fixFloat();
-            [% END %]
-          [% IF rules.size > 0 %]
-            $("#norules").hide();
-          [% ELSE %]
-            $("#rules").show();
-          [% END %]
-      });
-    //]]>
-    </script>
-[% END %]
 </head>
+
 <body id="tools_automatic_item_modification_by_age" class="tools">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
     [% INCLUDE 'tools-menu.inc' %]
   </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/automatic_item_modification_by_age.js"></script>
+    [% IF op == 'edit_form' %]
+        <script type="text/javascript">
+            $(document).ready(function() {
+                  [% IF ( op == 'edit_form' ) %]
+                      $('#toolbar').fixFloat();
+                  [% END %]
+                  [% IF rules.size > 0 %]
+                      $("#norules").hide();
+                  [% ELSE %]
+                      $("#rules").show();
+                  [% END %]
+            });
+        </script>
+    [% END %]
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 7bbb7d4..82e1e2b 100644 (file)
@@ -1,3 +1,4 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records
 [% IF ( import_batch_id ) %]
@@ -5,134 +6,7 @@
 [% END %]
 </title>
 [% INCLUDE 'doc-head-close.inc' %]
-<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[
-$(document).ready(function(){
-  $("#staged-record-matching-rules select").change(function(){
-      var str = $(this).attr("id");
-      $("#reset_"+str).parent().show();
-  });
-  $("a.reset").click(function(){
-      var str = $(this).attr("id");
-      str = str.replace("reset_","")
-      $("#"+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>'
-            );
-          },
-      }));
-        $("#import_batch_form").on("submit",function(){
-            return submitBackgroundJob( document.getElementById("import_batch_form") );
-        });
-        $("#revert_batch_form").on("submit",function(){
-            return confirm( _("Are you sure you want to undo the import of this batch into the catalog?") ) &&   submitBackgroundJob( document.getElementById("revert_batch_form") );
-        });
-    [% 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/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
-    });
-    $(".batch_form").on("submit",function(){
-        if( $(this).hasClass("batch_delete") ){
-            return confirm( _("Are you sure you want to permanently delete this batch?") );
-        } else {
-            return confirm( _("Clear all reservoir records staged in this batch?  This cannot be undone.") );
-        }
-    });
-});
-
-//]]>
-</script>
 <style type="text/css">
     #jobpanel,#jobstatus,#jobfailed { display : none; }
     span.change-status { font-style:italic; color:#666; display:none; }
@@ -504,4 +378,133 @@ $(document).ready(function(){
 [% INCLUDE 'tools-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+<script type="text/javascript" src="[% interface %]/[% theme %]/js/background-job-progressbar.js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript">
+        $(document).ready(function(){
+            $("#staged-record-matching-rules select").change(function(){
+                var str = $(this).attr("id");
+                $("#reset_"+str).parent().show();
+            });
+            $("a.reset").click(function(){
+                var str = $(this).attr("id");
+                str = str.replace("reset_","")
+                $("#"+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>'
+                      );
+                    },
+                }));
+                $("#import_batch_form").on("submit",function(){
+                    return submitBackgroundJob( document.getElementById("import_batch_form") );
+                });
+                $("#revert_batch_form").on("submit",function(){
+                    return confirm( _("Are you sure you want to undo the import of this batch into the catalog?") ) &&   submitBackgroundJob( document.getElementById("revert_batch_form") );
+                });
+            [% 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/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
+            });
+            $(".batch_form").on("submit",function(){
+                if( $(this).hasClass("batch_delete") ){
+                    return confirm( _("Are you sure you want to permanently delete this batch?") );
+                } else {
+                    return confirm( _("Clear all reservoir records staged in this batch?  This cannot be undone.") );
+                }
+            });
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 6d32500..228c8a5 100644 (file)
@@ -1,23 +1,7 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; MARC modification templates</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-    //<![CDATA[
-    var MSG_MMT_SUBFIELDS_MATCH = _("Both subfield values should be filled or empty.");
-    var MSG_MMT_DESTINATION_REQUIRED = _("The destination should be filled.");
-    var MSG_MMT_CONTROL_FIELD_EMPTY = _("If the field is a control field, the subfield should be empty");
-    var MSG_MMT_CONTROL_FIELD = _("A control field cannot be used with a regular field.");
-    var MSG_MMT_SOURCE_SUBFIELD = _("The source subfield should be filled for update.");
-    var MSG_MMT_SOURCE_FIELD = _("The source field should be filled.");
-    var MSG_MMT_EVERY = _("Every");
-    var MSG_MMT_ALL = _("All");
-    var MSG_MMT_CONFIRM_DEL_TEMPLATE = _("Are you sure you wish to delete this template?");
-    var MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION = _("Are you sure you wish to delete this template action?");
-    var MSG_MMT_EDIT_ACTION = _("Edit action %s");
-    var MSG_MMT_UPDATE_ACTION = _("Update action");
-    //]]>
-</script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/marc_modification_templates.js"></script>
 <style type="text/css">
     #add_action { display: none; }
 </style>
     </div>
   </div>
 
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript">
+        var MSG_MMT_SUBFIELDS_MATCH = _("Both subfield values should be filled or empty.");
+        var MSG_MMT_DESTINATION_REQUIRED = _("The destination should be filled.");
+        var MSG_MMT_CONTROL_FIELD_EMPTY = _("If the field is a control field, the subfield should be empty");
+        var MSG_MMT_CONTROL_FIELD = _("A control field cannot be used with a regular field.");
+        var MSG_MMT_SOURCE_SUBFIELD = _("The source subfield should be filled for update.");
+        var MSG_MMT_SOURCE_FIELD = _("The source field should be filled.");
+        var MSG_MMT_EVERY = _("Every");
+        var MSG_MMT_ALL = _("All");
+        var MSG_MMT_CONFIRM_DEL_TEMPLATE = _("Are you sure you wish to delete this template?");
+        var MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION = _("Are you sure you wish to delete this template action?");
+        var MSG_MMT_EDIT_ACTION = _("Edit action %s");
+        var MSG_MMT_UPDATE_ACTION = _("Update action");
+    </script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/marc_modification_templates.js"></script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 93edb39..b9c1307 100644 (file)
@@ -1,15 +1,7 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records &rsaquo; Compare matched records</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% interface %]/lib/jsdiff/jsdiff.min.js"></script>
-<script type="text/javascript">
-    $(document).ready(function(){
-      var diff1 = $("#col1 pre").text();
-      var diff2 = $("#col2 pre").text();
-      var diffs = diffString(diff1,diff2);
-      $("#col1 pre,#col2 pre").html(diffs);
-    });
-</script>
 <style type="text/css">
     ins { background-color: #e6ffe6; }
     del { background-color: #ffe6e6; }
@@ -17,6 +9,7 @@
     pre { padding: 10px; overflow: scroll; }
 </style>
 </head>
+
 <body id="tools_compare-marc-import" class="tools">
 
 [% INCLUDE 'header.inc' %]
     </div>
 
 <p><a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% batchid %]">Return to staged MARC batch [% batchid %]</a></p>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/lib/jsdiff/jsdiff.min.js"></script>
+    <script type="text/javascript">
+        $(document).ready(function(){
+          var diff1 = $("#col1 pre").text();
+          var diff2 = $("#col2 pre").text();
+          var diffs = diffString(diff1,diff2);
+          $("#col1 pre,#col2 pre").html(diffs);
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index acbf121..12fdef5 100644 (file)
@@ -1,91 +1,11 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Stage MARC records for import</title>
 [% INCLUDE 'doc-head-close.inc' %]
-
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/background-job-progressbar.js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/file-upload.js"></script>
-
 <style type="text/css">
     #fileuploadstatus,#fileuploadfailed,#fileuploadcancel,#jobpanel,#jobstatus,#jobfailed { display : none; }
 </style>
 
-<script type="text/javascript">
-//<![CDATA[
-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>
 </head>
 <body id="tools_stage-marc-import" class="tools">
 [% INCLUDE 'header.inc' %]
@@ -275,4 +195,86 @@ function cbUpload( status, fileid, errors ) {
 [% INCLUDE 'tools-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/background-job-progressbar.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/file-upload.js"></script>
+    <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' %]