Bug 19754: Move template JavaScript to the footer: Acquisitions, part 2
authorOwen Leonard <oleonard@myacpl.org>
Tue, 5 Dec 2017 17:17:15 +0000 (17:17 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Feb 2018 13:58:09 +0000 (10:58 -0300)
This patch modifies some staff client acquisitions templates so that
JavaScript is included in the footer instead of the header.

To test, apply the patch and test the JavaScript-driven features of the
modified templates: All button controls, DataTables functionality, tabs,
etc.

- Acquisitions -> Invoices
  - Datepickers
  - Search for invoices
    - Datatable
- Acquisitions -> Late orders
  - Datepickers, datatables, selection controls (when searching by
    vendor)
- Acquisitions -> Vendor -> Basket -> Add to basket -> From an existing
  record -> Search
  - Datatables, View MARC modal
- Acquisitions -> Vendor -> Basket -> Add to basket -> From a new
  (empty) record
  - Form validation, inactive fund control, add users to notify on
    receiving.
- Acquisitions -> Vendor -> Basket -> Add to basket -> From a
  subscription -> Search
  - Datatables, show only renewed, show/hide search form
- Acquisitions -> Vendor -> Basket -> Add to basket -> From a suggestion
  - Datatables, "Show" controls
- Acquisitions
  - "Ordered" link in table of funds
    - Datatables
- Acquisitions -> Vendor -> Receive shipment -> Invoice -> Receive
  - Datepickers, item add form plugins (test with AcqCreateItem set to
    'receiving an order.'

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/acqui/invoices.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt

index 765b46c..79cbc6a 100644 (file)
@@ -1,89 +1,11 @@
 [% USE KohaDates %]
 [% USE Branches %]
-
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Invoices</title>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'datatables.inc' %]
-[% INCLUDE 'calendar.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-$(document).ready(function() {
-    $(".delete_invoice").click(function(){
-        return confirmDelete(_("Are you sure you want to delete this invoice?"));
-    });
-
-    var resultst = $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
-        bPaginate: false,
-        aoColumnDefs: [
-            { "bSortable": false, "aTargets": [1, -1] },
-            { "bVisible": false, "aTargets": [0] },
-            { "sType": "title-string", "aTargets" : [ "title-string" ] }
-        ]
-    }));
-
-    $("#show_only_subscription").prop("checked", false);
 
-    $("#show_only_subscription").click(function(){
-        if ( $(this).prop("checked") ) {
-            resultst.fnFilter( "1", 0, true );
-        } else {
-            resultst.fnFilter( '', 0 );
-        }
-    });
-
-    $('#merge').click(function (ev) {
-        var booksellerid;
-        var mismatch;
-        var invoices = [ ];
-        if ($('.select-invoice:checked').size() < 2) {
-            alert(_("You must select at least two invoices to merge."));
-            return false;
-        }
-        $('.select-invoice:checked').each(function () {
-            var row = $(this).parents('tr');
-            booksellerid = booksellerid || $(row).attr('data-booksellerid');
-            if (booksellerid !== $(row).attr('data-booksellerid')) {
-                mismatch = true;
-            }
-            invoices.push({ 'invoiceid': $(row).attr('data-invoiceid'),
-                            'invoicenumber': $(row).find('td:nth-child(2) a').text(),
-                            'shipmentdate': $(row).attr('data-shipmentdate'),
-                            'billingdate': $(row).attr('data-billingdate'),
-                            'shipmentcost': $(row).attr('data-shipmentcost'),
-                            'shipment_budgetid': $(row).attr('data-shipment_budgetid'),
-                            'closedate': $(row).attr('data-closedate'), });
-            $('#merge_invoice_form').append('<input type="hidden" name="merge" value="' + $(row).attr('data-invoiceid') + '" />');
-        });
-        if (mismatch) {
-            alert(_("All invoices for merging must be from the same vendor"));
-        } else {
-            $('#merge_table tbody').empty();
-            $.each(invoices, function (idx, invoice) {
-                var row = $('<tr data-invoiceid="' + invoice.invoiceid + '"><td>' + invoice.invoicenumber + '</td><td>' + invoice.shipmentdate + '</td><td>' + invoice.billingdate + '</td><td>' + invoice.shipmentcost + '</td></tr>');
-                $(row).appendTo('#merge_table tbody');
-                $(row).click(function () {
-                    $('#merge_table tbody tr').removeClass('active');
-                    $(this).addClass('active');
-                    $('#merge_invoicenumber').text(invoice.invoicenumber);
-                    $.each(['invoiceid', 'shipmentdate', 'billingdate', 'shipmentcost', 'shipment_budgetid'], function (idx, prop) {
-                        $('#merge_' + prop).val(invoice[prop]);
-                    });
-                    if (invoice.closedate) {
-                        $('#merge_status').text(_("Closed on %s").format(invoice.closedate));
-                    } else {
-                        $('#merge_status').text(_("Open"));
-                    }
-                });
-            });
-            $('#merge_table tbody tr:first').click();
-            $('#merge_invoices').show();
-        }
-    });
-});
-//]]>
-</script>
 </head>
 
 <body id="acq_invoices" class="acq">
@@ -367,4 +289,85 @@ $(document).ready(function() {
     [% INCLUDE 'acquisitions-menu.inc' %]
   </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    [% INCLUDE 'calendar.inc' %]
+    <script type="text/javascript">
+        $(document).ready(function() {
+            $(".delete_invoice").click(function(){
+                return confirmDelete(_("Are you sure you want to delete this invoice?"));
+            });
+            var resultst = $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
+                bPaginate: false,
+                aoColumnDefs: [
+                    { "bSortable": false, "aTargets": [1, -1] },
+                    { "bVisible": false, "aTargets": [0] },
+                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                ]
+            }));
+
+            $("#show_only_subscription").prop("checked", false);
+
+            $("#show_only_subscription").click(function(){
+                if ( $(this).prop("checked") ) {
+                    resultst.fnFilter( "1", 0, true );
+                } else {
+                    resultst.fnFilter( '', 0 );
+                }
+            });
+
+            $('#merge').click(function (ev) {
+                var booksellerid;
+                var mismatch;
+                var invoices = [ ];
+                if ($('.select-invoice:checked').size() < 2) {
+                    alert(_("You must select at least two invoices to merge."));
+                    return false;
+                }
+                $('.select-invoice:checked').each(function () {
+                    var row = $(this).parents('tr');
+                    booksellerid = booksellerid || $(row).attr('data-booksellerid');
+                    if (booksellerid !== $(row).attr('data-booksellerid')) {
+                        mismatch = true;
+                    }
+                    invoices.push({ 'invoiceid': $(row).attr('data-invoiceid'),
+                                    'invoicenumber': $(row).find('td:nth-child(2) a').text(),
+                                    'shipmentdate': $(row).attr('data-shipmentdate'),
+                                    'billingdate': $(row).attr('data-billingdate'),
+                                    'shipmentcost': $(row).attr('data-shipmentcost'),
+                                    'shipment_budgetid': $(row).attr('data-shipment_budgetid'),
+                                    'closedate': $(row).attr('data-closedate'), });
+                    $('#merge_invoice_form').append('<input type="hidden" name="merge" value="' + $(row).attr('data-invoiceid') + '" />');
+                });
+                if (mismatch) {
+                    alert(_("All invoices for merging must be from the same vendor"));
+                } else {
+                    $('#merge_table tbody').empty();
+                    $.each(invoices, function (idx, invoice) {
+                        var row = $('<tr data-invoiceid="' + invoice.invoiceid + '"><td>' + invoice.invoicenumber + '</td><td>' + invoice.shipmentdate + '</td><td>' + invoice.billingdate + '</td><td>' + invoice.shipmentcost + '</td></tr>');
+                        $(row).appendTo('#merge_table tbody');
+                        $(row).click(function () {
+                            $('#merge_table tbody tr').removeClass('active');
+                            $(this).addClass('active');
+                            $('#merge_invoicenumber').text(invoice.invoicenumber);
+                            $.each(['invoiceid', 'shipmentdate', 'billingdate', 'shipmentcost', 'shipment_budgetid'], function (idx, prop) {
+                                $('#merge_' + prop).val(invoice[prop]);
+                            });
+                            if (invoice.closedate) {
+                                $('#merge_status').text(_("Closed on %s").format(invoice.closedate));
+                            } else {
+                                $('#merge_status').text(_("Open"));
+                            }
+                        });
+                    });
+                    $('#merge_table tbody tr:first').click();
+                    $('#merge_invoices').show();
+                }
+            });
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 97797ad..4c142a1 100644 (file)
@@ -1,73 +1,13 @@
 [% USE KohaDates %]
 [% USE Branches %]
 [% USE ColumnsSettings %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Late orders</title>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'datatables.inc' %]
-[% INCLUDE 'columns_settings.inc' %]
-<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min_[% KOHA_VERSION %].js"></script>
-[% INCLUDE 'calendar.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-
-var late_orderst;
-function check_uncheck() {
-    var all_nodes = $(late_orderst.fnGetNodes());
-    if ( $(all_nodes).find("input:checkbox[name=ordernumber]:checked").length > 0) {
-        var booksellerid = $(all_nodes).find("input:checkbox[name=ordernumber]:checked:first").attr("data-booksellerid");
-        $(all_nodes).find("input:checkbox[name=ordernumber][data-booksellerid!="+booksellerid+"]").prop('disabled', true);
-    } else {
-        $("input:checkbox[name=ordernumber]").prop('disabled', false);
-    }
-}
-
-$(document).ready(function() {
-
-    var columns_settings = [% ColumnsSettings.GetColumns( 'acqui', 'lateorders', 'late_orders', 'json' ) %];
-    late_orderst = KohaTable("late_orders", {
-        "aoColumnDefs": [
-            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
-            { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
-            { "sType": "title-string", "aTargets" : [ "title-string" ] }
-        ],
-        "sPaginationType": "four_button",
-        "bAutoWidth": false,
-        "fnDrawCallback": function() {
-            if ( typeof late_orderst != 'undefined' ) {
-                check_uncheck();
-                $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
-            };
-        }
-    }, columns_settings );
-    $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
-    $('#CheckAll').click(function(){ $(late_orderst.fnGetNodes()).find("td").checkCheckboxes();});
-    $('#CheckNone').click(function(){ $(late_orderst.fnGetNodes()).find("td").unCheckCheckboxes();});
-
-    // Generates a dynamic link for exporting the selection's data as CSV
-    $("#ExportSelected").click(function() {
-        var all_nodes = $(late_orderst.fnGetNodes());
-        var selected = $(all_nodes).find("input[name='ordernumber']:checked");
-
-        if (selected.length == 0) {
-            alert(_("Please select at least one item to export."));
-            return false;
-        }
-
-        // Building the url from currently checked boxes
-        var url = '/cgi-bin/koha/acqui/lateorders-export.pl?op=export';
-        for (var i = 0; i < selected.length; i++) {
-            url += '&amp;ordernumber=' + selected[i].value;
-        }
-        // And redirecting to the CSV page
-        location.href = url;
-        return false;
-    });
-});
-//]]>
-</script>
 </head>
+
 <body id="acq_lateorders" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
@@ -249,4 +189,68 @@ $(document).ready(function() {
 [% INCLUDE 'acquisitions-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    [% INCLUDE 'columns_settings.inc' %]
+    <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'calendar.inc' %]
+    <script type="text/javascript">
+        var late_orderst;
+        function check_uncheck() {
+            var all_nodes = $(late_orderst.fnGetNodes());
+            if ( $(all_nodes).find("input:checkbox[name=ordernumber]:checked").length > 0) {
+                var booksellerid = $(all_nodes).find("input:checkbox[name=ordernumber]:checked:first").attr("data-booksellerid");
+                $(all_nodes).find("input:checkbox[name=ordernumber][data-booksellerid!="+booksellerid+"]").prop('disabled', true);
+            } else {
+                $("input:checkbox[name=ordernumber]").prop('disabled', false);
+            }
+        }
+
+        $(document).ready(function() {
+
+            var columns_settings = [% ColumnsSettings.GetColumns( 'acqui', 'lateorders', 'late_orders', 'json' ) %];
+            late_orderst = KohaTable("late_orders", {
+                "aoColumnDefs": [
+                    { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
+                    { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
+                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                ],
+                "sPaginationType": "four_button",
+                "bAutoWidth": false,
+                "fnDrawCallback": function() {
+                    if ( typeof late_orderst != 'undefined' ) {
+                        check_uncheck();
+                        $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
+                    };
+                }
+            }, columns_settings );
+            $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
+            $('#CheckAll').click(function(){ $(late_orderst.fnGetNodes()).find("td").checkCheckboxes();});
+            $('#CheckNone').click(function(){ $(late_orderst.fnGetNodes()).find("td").unCheckCheckboxes();});
+
+            // Generates a dynamic link for exporting the selection's data as CSV
+            $("#ExportSelected").click(function() {
+                var all_nodes = $(late_orderst.fnGetNodes());
+                var selected = $(all_nodes).find("input[name='ordernumber']:checked");
+
+                if (selected.length == 0) {
+                    alert(_("Please select at least one item to export."));
+                    return false;
+                }
+
+                // Building the url from currently checked boxes
+                var url = '/cgi-bin/koha/acqui/lateorders-export.pl?op=export';
+                for (var i = 0; i < selected.length; i++) {
+                    url += '&amp;ordernumber=' + selected[i].value;
+                }
+                // And redirecting to the CSV page
+                location.href = url;
+                return false;
+            });
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 3f96abc..5d9a0ac 100644 (file)
@@ -1,34 +1,10 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Search existing records</title>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
- $(document).ready(function() {
-    var resultst = $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
-        'sDom': 't',
-        'bPaginate': false,
-        'bFilter': false,
-        'bInfo': false,
-        'bSort': false,
-    } ) );
-    $(".previewMARC").on("click", 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>");
-    });
- });
- //]]>
-</script>
 </head>
+
 <body id="acq_neworderbiblio" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
 [% INCLUDE 'acquisitions-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript">
+         $(document).ready(function() {
+            var resultst = $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
+                'sDom': 't',
+                'bPaginate': false,
+                'bFilter': false,
+                'bInfo': false,
+                'bSort': false,
+            } ) );
+            $(".previewMARC").on("click", 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>");
+            });
+         });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 3bad339..f9b4a15 100644 (file)
+[% USE Koha %]
 [% USE KohaDates %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
-[% USE Koha %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Basket [% basketno %] &rsaquo; [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber %])[% ELSE %]New order[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/acq_[% KOHA_VERSION %].js"></script>
-[% INCLUDE 'additem.js.inc' %]
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/additem_[% KOHA_VERSION %].js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/cataloging_[% KOHA_VERSION %].js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/prevent_submit_[% KOHA_VERSION %].js"></script>
-<script type="text/javascript">
-//<![CDATA[
-actTotal = "";
-
-function Check(ff) {
-    [% IF (AcqCreateItemOrdering) %]
-        // Remove last itemblock if it is not in items_list
-        var lastitemblock = $("#outeritemblock > div:last");
-        var tobedeleted = true;
-        var listitems = $("#items_list tr");
-        $(listitems).each(function(){
-            if($(this).attr('idblock') == $(lastitemblock).attr('id')){
-                tobedeleted = false;
-            }
-        });
-        if(tobedeleted){
-            $(lastitemblock).remove();
-        }
-    [% END %]
-
-    var ok=0;
-    var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
-
-    _alertString +="-------------------------------------------------------------------\n\n";
-
-    if ( isNull(ff.title,1)  &&  isNull(ff.entertitle,1)   ){
-        ok=1;
-                    _alertString += "\n- " + _("Title cannot be empty");
-    }
-    
-    if(isNull(ff.budget_id,1)){
-               ok=1;
-        _alertString += "\n- "+ _("You must select a fund");
-    }
-
-    if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
-        ok=1;
-                    _alertString += "\n- " + _("Quantity must be greater than '0'");
-    }
-
-    if (!(isNum(ff.listprice,0))){
-        ok=1;
-                    _alertString += "\n- " + _("Vendor price must be a number");
-    }
-
-    if (!(isNum(ff.total,0))){
-        ok=1;
-                    _alertString += "\n- " + _("Total must be a number");
-    }
-
-    if (totalExceedsBudget(ff.budget_id.value, ff.total.value  )  ) {
-        ok=1;
-        _alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
-    }
-
-    if ( ff.field_value ) {
-        var empty_item_mandatory = CheckMandatorySubfields(ff);
-        if (empty_item_mandatory > 0) {
-            ok = 1;
-            _alertString +=
-                "\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
-        }
-
-    }
-
-    if (ok) {
-        alert(_alertString);
-        [% IF (AcqCreateItemOrdering) %]
-            if(tobedeleted) {
-                $(lastitemblock).appendTo('#outeritemblock');
-            }
-        [% END %]
-        return false;
-    }
-
-    [% IF (AcqCreateItemOrdering) %]
-        if(check_additem('[% UniqueItemFields %]') == false) {
-            alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
-            if(tobedeleted) {
-                $(lastitemblock).appendTo('#outeritemblock');
-            }
-            return false;
-        }
-    [% END %]
-}
-
-$(document).ready(function() 
-    {
-        [% IF AcqCreateItemOrdering and not basket.is_standing %]
-            cloneItemBlock(0, '[% UniqueItemFields %]');
-        [% END %]
-
-        [% IF ( suggestionid ) %]updateCosts();[% END %]
-        $("#quantity").change(function() {
-            updateCosts();
-        });
-
-        //We apply the fonction only for modify option
-        [% IF ( quantityrec ) %]
-        [% IF ( acqcreate ) %]
-        $('#quantity').blur(function() 
-        {
-            // if user decreases the quantity
-            if($(this).val() < [% quantityrec %]) 
-            {
-                alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
-                return true;
-            } 
-            else 
-            {
-                // if user increases the quantity
-                alert(_("You can't add a new item, please create a new order line"));
-                // and we replace the original value
-                $(this).val([% quantityrec %])
-                updateCosts(); // blur is invoked after change which updated values
-                return false;
-            }
-        });
-        [% END %]
-        [% END %]
-        
-        //keep a copy of all budgets before removing the inactives
-        disabledBudgetsCopy = $('#budget_id').html();
-        $('#budget_id .b_inactive').remove();
-
-        $('#showallbudgets').click(function() {
-            if ($(this).is(":checked")) {
-                $('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
-            }
-            else {
-                $('#budget_id .b_inactive').remove();
-            }
-        });
-
-        $("#budget_id").change(function(){
-            var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
-            var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
-            var sort1 = $(destination_sort1).val() || "";
-            if ( destination_sort1.length < 1 ) {
-                destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
-            }
-            var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
-            var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
-            var sort2 = $(destination_sort2).val() || "";
-            if ( destination_sort2.length < 1 ) {
-                destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
-            }
-            getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
-            getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
-        });
-        $("#budget_id").change();
-    });
-
-    function UserSearchPopup(f) {
-        window.open(
-            "/cgi-bin/koha/acqui/add_user_search.pl",
-            'UserSearchPopup',
-            'width=740, height=450, scrollbars=yes, toolbar=no,'
-         );
-    }
-
-    function add_user(borrowernumber, borrowername) {
-        var ids = $("#users_ids").val();
-        if(ids.length > 0) {
-            ids = ids.split(':');
-        } else {
-            ids = new Array;
-        }
-        if (ids.indexOf(borrowernumber.toString()) < 0) {
-            ids.push(borrowernumber);
-            $("#users_ids").val(ids.join(':'));
-            var li = '<li id="user_'+borrowernumber+'">'+borrowername
-                + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
-                + _("Delete user") + '</a>]</li>';
-            $("#users_names").append(li);
-            return 0;
-        }
-        return -1;
-    }
-
-    function del_user(borrowernumber) {
-      $("#user_"+borrowernumber).remove();
-      var ids = $("#users_ids").val().split(':');
-      ids.splice(ids.indexOf(borrowernumber.toString()), 1);
-      $("#users_ids").val(ids.join(':'));
-    }
-//]]>
-</script>
 </head>
+
 <body id="acq_neworderempty" class="acq">
 
 [% INCLUDE 'header.inc' %]
@@ -679,4 +487,195 @@ $(document).ready(function()
 [% INCLUDE 'acquisitions-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acq_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'additem.js.inc' %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/additem_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/cataloging_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/prevent_submit_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript">
+        actTotal = "";
+
+        function Check(ff) {
+            [% IF (AcqCreateItemOrdering) %]
+                // Remove last itemblock if it is not in items_list
+                var lastitemblock = $("#outeritemblock > div:last");
+                var tobedeleted = true;
+                var listitems = $("#items_list tr");
+                $(listitems).each(function(){
+                    if($(this).attr('idblock') == $(lastitemblock).attr('id')){
+                        tobedeleted = false;
+                    }
+                });
+                if(tobedeleted){
+                    $(lastitemblock).remove();
+                }
+            [% END %]
+
+            var ok=0;
+            var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
+
+            _alertString +="-------------------------------------------------------------------\n\n";
+
+            if ( isNull(ff.title,1)  &&  isNull(ff.entertitle,1)   ){
+                ok=1;
+                            _alertString += "\n- " + _("Title cannot be empty");
+            }
+
+            if(isNull(ff.budget_id,1)){
+                ok=1;
+                _alertString += "\n- "+ _("You must select a fund");
+            }
+
+            if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
+                ok=1;
+                            _alertString += "\n- " + _("Quantity must be greater than '0'");
+            }
+
+            if (!(isNum(ff.listprice,0))){
+                ok=1;
+                            _alertString += "\n- " + _("Vendor price must be a number");
+            }
+
+            if (!(isNum(ff.total,0))){
+                ok=1;
+                            _alertString += "\n- " + _("Total must be a number");
+            }
+
+            if (totalExceedsBudget(ff.budget_id.value, ff.total.value  )  ) {
+                ok=1;
+                _alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
+            }
+
+            if ( ff.field_value ) {
+                var empty_item_mandatory = CheckMandatorySubfields(ff);
+                if (empty_item_mandatory > 0) {
+                    ok = 1;
+                    _alertString +=
+                        "\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
+                }
+
+            }
+
+            if (ok) {
+                alert(_alertString);
+                [% IF (AcqCreateItemOrdering) %]
+                    if(tobedeleted) {
+                        $(lastitemblock).appendTo('#outeritemblock');
+                    }
+                [% END %]
+                return false;
+            }
+
+            [% IF (AcqCreateItemOrdering) %]
+                if(check_additem('[% UniqueItemFields %]') == false) {
+                    alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
+                    if(tobedeleted) {
+                        $(lastitemblock).appendTo('#outeritemblock');
+                    }
+                    return false;
+                }
+            [% END %]
+        }
+
+        $(document).ready(function(){
+            [% IF AcqCreateItemOrdering and not basket.is_standing %]
+                cloneItemBlock(0, '[% UniqueItemFields %]');
+            [% END %]
+
+            [% IF ( suggestionid ) %]updateCosts();[% END %]
+            $("#quantity").change(function() {
+                updateCosts();
+            });
+
+            //We apply the fonction only for modify option
+            [% IF ( quantityrec ) %]
+                [% IF ( acqcreate ) %]
+                    $('#quantity').blur(function(){
+                        // if user decreases the quantity
+                        if($(this).val() < [% quantityrec %]){
+                            alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
+                            return true;
+                        } else {
+                            // if user increases the quantity
+                            alert(_("You can't add a new item, please create a new order line"));
+                            // and we replace the original value
+                            $(this).val([% quantityrec %])
+                            updateCosts(); // blur is invoked after change which updated values
+                            return false;
+                        }
+                    });
+                [% END %]
+            [% END %]
+
+            //keep a copy of all budgets before removing the inactives
+            disabledBudgetsCopy = $('#budget_id').html();
+            $('#budget_id .b_inactive').remove();
+
+            $('#showallbudgets').click(function() {
+                if ($(this).is(":checked")) {
+                    $('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
+                }
+                else {
+                    $('#budget_id .b_inactive').remove();
+                }
+            });
+
+            $("#budget_id").change(function(){
+                var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
+                var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
+                var sort1 = $(destination_sort1).val() || "";
+                if ( destination_sort1.length < 1 ) {
+                    destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
+                }
+                var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
+                var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
+                var sort2 = $(destination_sort2).val() || "";
+                if ( destination_sort2.length < 1 ) {
+                    destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
+                }
+                getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
+                getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
+            });
+            $("#budget_id").change();
+        });
+
+        function UserSearchPopup(f) {
+            window.open(
+                "/cgi-bin/koha/acqui/add_user_search.pl",
+                'UserSearchPopup',
+                'width=740, height=450, scrollbars=yes, toolbar=no,'
+             );
+        }
+
+        function add_user(borrowernumber, borrowername) {
+            var ids = $("#users_ids").val();
+            if(ids.length > 0) {
+                ids = ids.split(':');
+            } else {
+                ids = new Array;
+            }
+        if (ids.indexOf(borrowernumber.toString()) < 0) {
+                ids.push(borrowernumber);
+                $("#users_ids").val(ids.join(':'));
+                var li = '<li id="user_'+borrowernumber+'">'+borrowername
+                    + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
+                    + _("Delete user") + '</a>]</li>';
+                $("#users_names").append(li);
+                return 0;
+            }
+            return -1;
+        }
+
+        function del_user(borrowernumber) {
+            $("#user_"+borrowernumber).remove();
+            var ids = $("#users_ids").val().split(':');
+            ids.splice(ids.indexOf(borrowernumber.toString()), 1);
+            $("#users_ids").val(ids.join(':'));
+        }
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 8af7639..38491d8 100644 (file)
@@ -1,42 +1,13 @@
 [% USE KohaDates %]
 [% USE Branches %]
 [% USE Koha %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials [% biblionumber %]</title>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-    function updateRowsVisibility(show_only_renewed) {
-        if ( show_only_renewed ) {
-            $("#srlt [data-reneweddate='']").hide();
-        } else {
-            $("#srlt > tbody > tr").show();
-        }
-    }
-
-    $(document).ready(function() {
-        $("#srlt").dataTable($.extend(true, {}, dataTablesDefaults, {
-            "aoColumnDefs": [
-                { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
-                { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
-                { "sType": "title-string", "aTargets" : [ "title-string" ] }
-            ],
-            "sPaginationType": "four_button"
-        } ) )
-
-        $("#show_only_renewed").click(function(){
-            updateRowsVisibility( $(this).is(":checked") );
-        });
-        $("#show_only_renewed").prop('checked', false);
-        updateRowsVisibility(false);
-
-        $("#advsearch_form").show();
-    });
- //]]>
-</script>
 </head>
+
 <body id="acq_newordersubscription" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
         [% INCLUDE 'acquisitions-menu.inc' %]
     </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript">
+        function updateRowsVisibility(show_only_renewed) {
+            if ( show_only_renewed ) {
+                $("#srlt [data-reneweddate='']").hide();
+            } else {
+                $("#srlt > tbody > tr").show();
+            }
+        }
+
+        $(document).ready(function() {
+            $("#srlt").dataTable($.extend(true, {}, dataTablesDefaults, {
+                "aoColumnDefs": [
+                    { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
+                    { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
+                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                ],
+                "sPaginationType": "four_button"
+            }));
+
+            $("#show_only_renewed").click(function(){
+                updateRowsVisibility( $(this).is(":checked") );
+            });
+            $("#show_only_renewed").prop('checked', false);
+            updateRowsVisibility(false);
+
+            $("#advsearch_form").show();
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 1274b47..a8f9c41 100644 (file)
@@ -1,30 +1,10 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Add order from a suggestion</title>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
- $(document).ready(function() {
-    var suggestionst = $("#suggestionst").dataTable($.extend(true, {}, dataTablesDefaults, {
-        "aoColumnDefs": [
-            { "aTargets": [ 0 ],  "bVisible": false, "bSearchable": true }, // must be searchable for fnFilter
-            { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
-        ],
-        "sPaginationType": "four_button"
-    } ) );
-    $("#show_only_mine").on('click', function(e){
-        e.preventDefault();
-        suggestionst.fnFilter('^[% loggedinuser %]$', 0, true);
-    });
-    $("#show_all").on('click', function(e){
-        e.preventDefault();
-        suggestionst.fnFilter('', 0 );
-    });
- });
- //]]>
-</script>
 </head>
+
 <body id="acq_newordersuggestion" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'suggestions-add-search.inc' %]
 [% INCLUDE 'acquisitions-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript">
+    $(document).ready(function() {
+        var suggestionst = $("#suggestionst").dataTable($.extend(true, {}, dataTablesDefaults, {
+            "aoColumnDefs": [
+                { "aTargets": [ 0 ],  "bVisible": false, "bSearchable": true }, // must be searchable for fnFilter
+                { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
+            ],
+            "sPaginationType": "four_button"
+        }));
+        $("#show_only_mine").on('click', function(e){
+            e.preventDefault();
+            suggestionst.fnFilter('^[% loggedinuser %]$', 0, true);
+        });
+        $("#show_all").on('click', function(e){
+            e.preventDefault();
+            suggestionst.fnFilter('', 0 );
+        });
+     });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 1007e5c..e7c3040 100644 (file)
@@ -1,24 +1,12 @@
 [% USE KohaDates %]
 [% USE ItemTypes %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Ordered</title>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
- $(document).ready(function() {
-    $("#spent").dataTable($.extend(true, {}, dataTablesDefaults, {
-        "aoColumnDefs": [
-            { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
-            { "sType": "title-string", "aTargets" : [ "title-string" ] }
-        ],
-        "sPaginationType": "four_button"
-    } ) );
- });
- //]]>
-</script>
 </head>
+
 <body id="acq_ordered" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
 [% INCLUDE 'acquisitions-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript">
+        $(document).ready(function() {
+            $("#spent").dataTable($.extend(true, {}, dataTablesDefaults, {
+                "aoColumnDefs": [
+                    { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
+                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                ],
+                "sPaginationType": "four_button"
+            }));
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index cd52267..8ec42ad 100644 (file)
 [% USE KohaDates %]
 [% USE Branches %]
 [% USE Price %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Receipt summary for : [% name %] [% IF ( invoice ) %]invoice, [% invoice %][% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
-[% INCLUDE 'additem.js.inc' %]
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/additem_[% KOHA_VERSION %].js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/cataloging_[% KOHA_VERSION %].js"></script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/prevent_submit_[% KOHA_VERSION %].js"></script>
-<script type="text/javascript">
-//<![CDATA[
-    function Check(form) {
-        [% IF (AcqCreateItemReceiving) %]
-            var total_errors = CheckMandatorySubfields(form);
-            if (total_errors != 0) {
-                var alertString = _("Form not submitted because of the following problem(s)");
-                alertString += "\n------------------------------------------------------------------------------------\n";
-                alertString += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_errors);
-                alert(alertString);
-                return false;
-            }
-
-            if(check_additem('[% UniqueItemFields %]') == false){
-                alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
-                return false;
-            };
-
-            // Remove last itemblock if it is not in items_list
-            var lastitemblock = $("#outeritemblock > div:last");
-            var tobedeleted = true;
-            var listitems = $("#items_list tr");
-            $(listitems).each(function(){
-                if($(this).attr('idblock') == $(lastitemblock).attr('id')){
-                    tobedeleted = false;
-                }
-            });
-            if(tobedeleted){
-                $(lastitemblock).remove();
-            }
-
-            if(check_additem('[% UniqueItemFields %]') == false){
-                alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
-                if(tobedeleted) {
-                    $(lastitemblock).appendTo("#outeritemblock");
-                }
-                return false;
-            };
-        [% END %]
-
-        return true;
-    }
-
-    [% IF (AcqCreateItem == 'ordering') %]
-        var items_columns = [null, null, 'barcode', 'homebranchname',
-            'holdingbranchname', 'notforloan', 'restricted', 'location',
-            'itemcallnumber', 'copynumber', 'stocknumber', 'collection',
-            'itemtype', 'materials', 'itemnotes'];
-
-        function PopupEditPage(biblionumber, itemnumber) {
-            var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
-                + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
-            var w = window.open(url);
-            var watchClose = setInterval(function() {
-                if (w.closed) {
-                    clearTimeout(watchClose);
-                    $.getJSON('/cgi-bin/koha/catalogue/getitem-ajax.pl',
-                        {
-                            'itemnumber': itemnumber
-                        },
-                        function(item) {
-                            var tds = $("#item_"+itemnumber+" td");
-                            for(var i=2; i<tds.length; i++) {
-                                var column = items_columns[i];
-                                var text = item[column];
-                                if ( text == null ) text = '';
-                                $(tds[i]).text(text);
-                            }
-                        }
-                    );
-                }
-            }, 500);
-        }
-
-        function CalcQtyToReceive() {
-            var qty = $("input[name='items_to_receive']:checked").length;
-            $("#quantity").val(qty);
-        }
-
-        function CheckNItems(n) {
-            $("input[name='items_to_receive']").each(function() {
-                $(this).prop('checked', false);
-            });
-            $("input[name='items_to_receive']:lt("+n+")").each(function () {
-                $(this).prop('checked', true);
-            });
-        }
-    [% END %]
-
-    $(document).ready(function() {
-        [% IF (AcqCreateItemReceiving) %]
-            cloneItemBlock(0, '[% UniqueItemFields %]');
-        [% ELSIF (AcqCreateItem == 'ordering') && not subscriptionid %]
-            $("input[name='items_to_receive']").change(function() {
-                CalcQtyToReceive();
-            });
-            CalcQtyToReceive();
-            $("#quantity").keyup(function() {
-                var qty = parseInt($("#quantity").val());
-                var qtyto = parseInt($("#quantity_to_receive").val());
-                if(qty > qtyto) {
-                    $("#qtyrecerror").show();
-                } else {
-                    $("#qtyrecerror").hide();
-                }
-                CheckNItems($(this).val());
-            });
-        [% END %]
-    });
-//]]>
-</script>
 </head>
+
 <body id="acq_orderreceive" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
 [% INCLUDE 'acquisitions-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/acquisitions-menu_[% KOHA_VERSION %].js"></script>
+[% INCLUDE 'calendar.inc' %]
+    [% INCLUDE 'additem.js.inc' %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/additem_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/cataloging_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/prevent_submit_[% KOHA_VERSION %].js"></script>
+    <script type="text/javascript">
+        function Check(form) {
+            [% IF (AcqCreateItemReceiving) %]
+                var total_errors = CheckMandatorySubfields(form);
+                if (total_errors != 0) {
+                    var alertString = _("Form not submitted because of the following problem(s)");
+                    alertString += "\n------------------------------------------------------------------------------------\n";
+                    alertString += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_errors);
+                    alert(alertString);
+                    return false;
+                }
+
+                if(check_additem('[% UniqueItemFields %]') == false){
+                    alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
+                    return false;
+                };
+
+                // Remove last itemblock if it is not in items_list
+                var lastitemblock = $("#outeritemblock > div:last");
+                var tobedeleted = true;
+                var listitems = $("#items_list tr");
+                $(listitems).each(function(){
+                    if($(this).attr('idblock') == $(lastitemblock).attr('id')){
+                        tobedeleted = false;
+                    }
+                });
+                if(tobedeleted){
+                    $(lastitemblock).remove();
+                }
+
+                if(check_additem('[% UniqueItemFields %]') == false){
+                    alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
+                    if(tobedeleted) {
+                        $(lastitemblock).appendTo("#outeritemblock");
+                    }
+                    return false;
+                };
+            [% END %]
+
+            return true;
+        }
+
+        [% IF (AcqCreateItem == 'ordering') %]
+            var items_columns = [null, null, 'barcode', 'homebranchname',
+                'holdingbranchname', 'notforloan', 'restricted', 'location',
+                'itemcallnumber', 'copynumber', 'stocknumber', 'collection',
+                'itemtype', 'materials', 'itemnotes'];
+
+            function PopupEditPage(biblionumber, itemnumber) {
+                var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
+                    + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
+                var w = window.open(url);
+                var watchClose = setInterval(function() {
+                    if (w.closed) {
+                        clearTimeout(watchClose);
+                        $.getJSON('/cgi-bin/koha/catalogue/getitem-ajax.pl',
+                            {
+                                'itemnumber': itemnumber
+                            },
+                            function(item) {
+                                var tds = $("#item_"+itemnumber+" td");
+                                for(var i=2; i<tds.length; i++) {
+                                    var column = items_columns[i];
+                                    var text = item[column];
+                                    if ( text == null ) text = '';
+                                    $(tds[i]).text(text);
+                                }
+                            }
+                        );
+                    }
+                }, 500);
+            }
+
+            function CalcQtyToReceive() {
+                var qty = $("input[name='items_to_receive']:checked").length;
+                $("#quantity").val(qty);
+            }
+
+            function CheckNItems(n) {
+                $("input[name='items_to_receive']").each(function() {
+                    $(this).prop('checked', false);
+                });
+                $("input[name='items_to_receive']:lt("+n+")").each(function () {
+                    $(this).prop('checked', true);
+                });
+            }
+        [% END %]
+
+        $(document).ready(function() {
+            [% IF (AcqCreateItemReceiving) %]
+                cloneItemBlock(0, '[% UniqueItemFields %]');
+            [% ELSIF (AcqCreateItem == 'ordering') && not subscriptionid %]
+                $("input[name='items_to_receive']").change(function() {
+                    CalcQtyToReceive();
+                });
+                CalcQtyToReceive();
+                $("#quantity").keyup(function() {
+                    var qty = parseInt($("#quantity").val());
+                    var qtyto = parseInt($("#quantity_to_receive").val());
+                    if(qty > qtyto) {
+                        $("#qtyrecerror").show();
+                    } else {
+                        $("#qtyrecerror").hide();
+                    }
+                    CheckNItems($(this).val());
+                });
+            [% END %]
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]