Bug 19680: Move JS to the footer: Patron and circulation tools
authorOwen Leonard <oleonard@myacpl.org>
Wed, 22 Nov 2017 19:03:15 +0000 (19:03 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Dec 2017 14:34:23 +0000 (11:34 -0300)
This patch modifies more staff client patrons and circulation tools
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
each modified template: All button controls, DataTables functionality,
form validation, etc.

  - Batch patron deletion/anonymization
  - Overdue notice/status triggers
  - Batch patron modification

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/cleanborrowers.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt

index f973d06..0d55337 100644 (file)
@@ -1,49 +1,12 @@
 [% USE Koha %]
 [% USE KohaDates %]
 [% USE Branches %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Batch patron deletion/anonymization [% IF step == 2 %]&rsaquo; Confirm[% END %][% IF step == 3 %]&rsaquo; Finished[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
-<script type="text/javascript">
-    $(document).ready(function(){
-        $("#delete_patrons_form").on("submit",function(){
-            return checkForm( this );
-        });
-    });
-
-        /**
-         *  checkForm(form)
-         *  This function check the form is correctly filled.
-         */
-          function checkForm(form) {
-              if((form.checkbox[0].checked)){
-                  if ( (!form.date1.value) && (!form.borrower_dateexpiry.value) [% IF Koha.Preference('TrackLastPatronActivity') %]&& (!form.borrower_lastseen.value) [% END %]&& (!form.borrower_categorycode.value) && (!form.patron_list_id.value)){
-                    alert(_("Please enter at least one criterion for deletion!"));
-                    return false;
-                  }
-              }
-              if((form.checkbox[1].checked)){
-                  if(!(form.date2.value)){
-                      alert(_("Please enter a date!"));
-                      return false;
-                  }
-              }
-              if(!form.checkbox[0].checked && !form.checkbox[1].checked) {
-                alert( _("Please check at least one action") );
-                return false;
-              }
-              return true;
-          }
-
-    $(document).ready(function() {
-        $('#branch').change(function() {
-            $('#selectlibrary').submit();
-        });
-    });
-</script>
-
 </head>
+
 <body id="tools_cleanborrowers" 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>
+    [% INCLUDE 'calendar.inc' %]
+    <script type="text/javascript">
+        $(document).ready(function(){
+            $("#delete_patrons_form").on("submit",function(){
+                return checkForm( this );
+            });
+
+            $('#branch').change(function() {
+                $('#selectlibrary').submit();
+            });
+        });
+
+        /**
+         *  checkForm(form)
+         *  This function check the form is correctly filled.
+         */
+        function checkForm(form) {
+            if((form.checkbox[0].checked)){
+                if ( (!form.date1.value) && (!form.borrower_dateexpiry.value) [% IF Koha.Preference('TrackLastPatronActivity') %]&& (!form.borrower_lastseen.value) [% END %]&& (!form.borrower_categorycode.value) && (!form.patron_list_id.value)){
+                  alert(_("Please enter at least one criterion for deletion!"));
+                  return false;
+                }
+            }
+            if((form.checkbox[1].checked)){
+                if(!(form.date2.value)){
+                    alert(_("Please enter a date!"));
+                    return false;
+                }
+            }
+            if(!form.checkbox[0].checked && !form.checkbox[1].checked) {
+              alert( _("Please check at least one action") );
+              return false;
+            }
+            return true;
+        }
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 7470563..53b5c0d 100644 (file)
 [% USE Koha %]
 [% USE KohaDates %]
 [% USE Branches %]
-[% INCLUDE 'doc-head-open.inc'%]
+[% SET footerjs = 1 %]
+[% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Batch patron modification</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-        var patron_attributes_lib = new Array();
-        var patron_attributes_values = new Array();
-        $(document).ready(function() {
-            [% IF borrowers %]
-                $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
-                    "sDom": 't',
-                    [% IF ( op == 'show_results' ) %]
-                        "aoColumnDefs": [
-                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
-                        ],
-                    [% ELSE %]
-                        "aoColumnDefs": [
-                            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
-                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
-                        ],
-                    [% END %]
-                    "bPaginate": false
-                }));
-                $("#selectallbutton").click(function() {
-                    $("#borrowerst").find("input:checkbox").each(function() {
-                        $(this).prop("checked", true);
-                    });
-                    return false;
-                });
-                $("#clearallbutton").click(function() {
-                    $("#borrowerst").find("input:checkbox").each(function() {
-                        $(this).prop("checked", false);
-                    });
-                    return false;
-                });
-            [% END %]
-
-            var values = new Array();
-            var lib = new Array();
-            [% FOREACH pav IN patron_attributes_values %]
-                values = new Array();
-                lib = new Array();
-                [% FOREACH option IN pav.options %]
-                    values.push("[% option.lib %]");
-                    lib.push("[% option.authorised_value %]");
-                [% END %]
-                patron_attributes_lib["[% pav.attribute_code %]"] = values;
-                patron_attributes_values["[% pav.attribute_code %]"] = lib;
-            [% END %]
-
-            $('select[name="patron_attributes"]').change(function() {
-                updateAttrValues(this);
-            } );
-
-            $('select[name="patron_attributes"]').change();
-
-            $(".clear-date").on("click",function(e){
-                e.preventDefault();
-                var fieldID = this.id.replace("clear-date-","");
-                $("#" + fieldID).val("");
-            });
-            $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
-                e.preventDefault();
-                add_attributes();
-            });
-            $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
-                e.preventDefault();
-                del_attributes(this);
-            });
-        });
-
-        function updateAttrValues (select_attr) {
-            var attr_code = $(select_attr).val();
-            var type = $(select_attr).find("option:selected").attr('data-type');
-            var category = $(select_attr).find("option:selected").attr('data-category');
-            var span = $(select_attr).parent().parent().find('span.patron_attributes_value');
-            var information_category_node = $(select_attr).parent().parent().find('span.information_category');
-            information_category_node.html("");
-            if ( category.length > 0 ) {
-                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
-            }
-            if ( type == 'select' ) {
-                var options = '<option value = ""></option>';
-                for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
-                    options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
-                }
-                span.html('<select name="patron_attributes_value">' + options + '</select>');
-            } else {
-                span.html('<input type="text" name="patron_attributes_value"/>')
-            }
-        }
-
-        function add_attributes() {
-            var li_node = $("li.attributes:last");
-            var li_clone = $(li_node).clone();
-            if ( $(li_clone).find("a.del_attributes").length == 0 ) {
-                $(li_clone).append('<a href="#" title="Delete" class="del_attributes"><i class="fa fa-fw fa-trash"></i> Delete</a>');
-            }
-            $(li_clone).find('select[name="patron_attributes"]').change(function() {
-                updateAttrValues(this);
-            } );
-
-            $(li_clone).find('select[name="patron_attributes"]').change();
-
-            $("#fields_list>ol").append(li_clone);
-            update_attr_values();
-        }
-
-        function del_attributes(a_node) {
-            $(a_node).parent('li').remove();
-            update_attr_values();
-        }
-
-        function update_attr_values() {
-            $("li.attributes").each(function(i) {
-                $(this).find("input:checkbox").val("attr"+i+"_value");
-            });
-        }
-        function clearDate(nodeid) {
-            $("#"+nodeid).val("");
-        }
-
-//]]>
-</script>
 </head>
+
 <body id="tools_modborrowers" class="tools">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
                 [% INCLUDE 'tools-menu.inc' %]
             </div>
         </div>
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript">
+        var patron_attributes_lib = new Array();
+        var patron_attributes_values = new Array();
+        $(document).ready(function() {
+            [% IF borrowers %]
+                $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
+                    "sDom": 't',
+                    [% IF ( op == 'show_results' ) %]
+                        "aoColumnDefs": [
+                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
+                        ],
+                    [% ELSE %]
+                        "aoColumnDefs": [
+                            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
+                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
+                        ],
+                    [% END %]
+                    "bPaginate": false
+                }));
+                $("#selectallbutton").click(function() {
+                    $("#borrowerst").find("input:checkbox").each(function() {
+                        $(this).prop("checked", true);
+                    });
+                    return false;
+                });
+                $("#clearallbutton").click(function() {
+                    $("#borrowerst").find("input:checkbox").each(function() {
+                        $(this).prop("checked", false);
+                    });
+                    return false;
+                });
+            [% END %]
+
+            var values = new Array();
+            var lib = new Array();
+            [% FOREACH pav IN patron_attributes_values %]
+                values = new Array();
+                lib = new Array();
+                [% FOREACH option IN pav.options %]
+                    values.push("[% option.lib %]");
+                    lib.push("[% option.authorised_value %]");
+                [% END %]
+                patron_attributes_lib["[% pav.attribute_code %]"] = values;
+                patron_attributes_values["[% pav.attribute_code %]"] = lib;
+            [% END %]
+
+            $('select[name="patron_attributes"]').change(function() {
+                updateAttrValues(this);
+            } );
+
+            $('select[name="patron_attributes"]').change();
+
+            $(".clear-date").on("click",function(e){
+                e.preventDefault();
+                var fieldID = this.id.replace("clear-date-","");
+                $("#" + fieldID).val("");
+            });
+            $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
+                e.preventDefault();
+                add_attributes();
+            });
+            $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
+                e.preventDefault();
+                del_attributes(this);
+            });
+        });
+
+        function updateAttrValues (select_attr) {
+            var attr_code = $(select_attr).val();
+            var type = $(select_attr).find("option:selected").attr('data-type');
+            var category = $(select_attr).find("option:selected").attr('data-category');
+            var span = $(select_attr).parent().parent().find('span.patron_attributes_value');
+            var information_category_node = $(select_attr).parent().parent().find('span.information_category');
+            information_category_node.html("");
+            if ( category.length > 0 ) {
+                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
+            }
+            if ( type == 'select' ) {
+                var options = '<option value = ""></option>';
+                for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
+                    options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
+                }
+                span.html('<select name="patron_attributes_value">' + options + '</select>');
+            } else {
+                span.html('<input type="text" name="patron_attributes_value"/>')
+            }
+        }
+
+        function add_attributes() {
+            var li_node = $("li.attributes:last");
+            var li_clone = $(li_node).clone();
+            if ( $(li_clone).find("a.del_attributes").length == 0 ) {
+                $(li_clone).append('<a href="#" title="Delete" class="del_attributes"><i class="fa fa-fw fa-trash"></i> Delete</a>');
+            }
+            $(li_clone).find('select[name="patron_attributes"]').change(function() {
+                updateAttrValues(this);
+            } );
+
+            $(li_clone).find('select[name="patron_attributes"]').change();
+
+            $("#fields_list>ol").append(li_clone);
+            update_attr_values();
+        }
+
+        function del_attributes(a_node) {
+            $(a_node).parent('li').remove();
+            update_attr_values();
+        }
+
+        function update_attr_values() {
+            $("li.attributes").each(function(i) {
+                $(this).find("input:checkbox").val("attr"+i+"_value");
+            });
+        }
+        function clearDate(nodeid) {
+            $("#"+nodeid).val("");
+        }
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index bb6e824..f27a8c2 100644 (file)
@@ -1,27 +1,11 @@
 [% USE Koha %]
 [% USE Branches %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Overdue notice/status triggers</title>
 [% INCLUDE 'doc-head-close.inc' %]
-
-<script type="text/javascript">
-//<![CDATA[
-var tab_map = { "1" : _("First"), "2" : _("Second"), "3" : _("Third")};
-$(document).ready(function() {
-    $('#selectlibrary').find("input:submit").hide();
-    $('#branch').change(function() {
-            $('#selectlibrary').submit();
-    });
-    $("li>a.tab").each( function(){
-        var id = $(this).attr("data-number");
-        $(this).html(tab_map[id]);
-    } );
-    $('#rulestabs').tabs();
-});
-//]]>
-</script>
-
 </head>
+
 <body id="tools_overduerules" class="tools">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
@@ -170,4 +154,23 @@ $(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">
+        var tab_map = { "1" : _("First"), "2" : _("Second"), "3" : _("Third")};
+        $(document).ready(function() {
+            $('#selectlibrary').find("input:submit").hide();
+            $('#branch').change(function() {
+                $('#selectlibrary').submit();
+            });
+            $("li>a.tab").each( function(){
+                var id = $(this).attr("data-number");
+                $(this).html(tab_map[id]);
+            });
+            $('#rulestabs').tabs();
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]