Bug 19601: Move admin templates JavaScript to the footer: Additional parameters
authorOwen Leonard <oleonard@myacpl.org>
Thu, 9 Nov 2017 13:53:19 +0000 (13:53 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Dec 2017 14:34:21 +0000 (11:34 -0300)
This patch modifies the staff client "additional parameters"
administration 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 page: All button controls, DataTables functionality, tabs, etc.

Signed-off-by: Simon Pouchol <simon.pouchol@biblibre.com>
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/admin/audio_alerts.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/didyoumean.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/sms_providers.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt

index a1d3309..0ebf15f 100644 (file)
@@ -1,13 +1,8 @@
 [% USE Koha %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Audio alerts</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-    var MSG_AUDIO_EMPTY_SOUND = _("Please select or enter a sound.");
-    var MSG_AUDIO_CONFIRM_DELETE = _("Are you sure you want to delete the selected audio alerts?");
-    var MSG_AUDIO_CHECK_CHECKBOXES = _("Check the box next to the alert you want to delete.")
-</script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/audio_alerts.js"></script>
 </head>
 
 <body id="admin_audio_alerts" class="admin">
 [% INCLUDE 'admin-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
+    <script type="text/javascript">
+        var MSG_AUDIO_EMPTY_SOUND = _("Please select or enter a sound.");
+        var MSG_AUDIO_CONFIRM_DELETE = _("Are you sure you want to delete the selected audio alerts?");
+        var MSG_AUDIO_CHECK_CHECKBOXES = _("Check the box next to the alert you want to delete.")
+    </script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/audio_alerts.js"></script>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]
index 884cc77..d7faa30 100644 (file)
@@ -1,3 +1,4 @@
+[% SET footerjs = 1 %]
 [% SET panel_id = 0 %]
 [% BLOCK pagelist %]
 <div class="pagelist">
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Columns settings</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-    $(document).ready( function() {
-        var accordion = $( "#modules" ).accordion({
-            collapsible: true,
-            autoHeight: false,
-            header: "h3",
-          [%- IF panel -%]
-            [%# we were asked to show a specific panel, usually on update %]
-            active: [%- panel -%]
-          [%- ELSE -%]
-            active: false
-          [%- END -%]
-        });
-    });
-</script>
 </head>
+
 <body id="admin_tables" class="admin">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'prefs-admin-search.inc' %]
       [% INCLUDE 'admin-menu.inc' %]
     </div>
   </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
+    <script type="text/javascript">
+        $(document).ready( function() {
+            var accordion = $( "#modules" ).accordion({
+                collapsible: true,
+                autoHeight: false,
+                header: "h3",
+              [%- IF panel -%]
+                [%# we were asked to show a specific panel, usually on update %]
+                active: [%- panel -%]
+              [%- ELSE -%]
+                active: false
+              [%- END -%]
+            });
+        });
+    </script>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]
index fa4e52b..9604316 100644 (file)
@@ -1,3 +1,4 @@
+[% SET footerjs = 1 %]
 [% BLOCK pluginlist %]
 <div class="pluginlist">
 [% FOREACH plugin IN plugins %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Did you mean?</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script>
-    $(document).ready(function() {
-        $( ".pluginlist" ).sortable();
-        $( ".plugin" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
-            .find( ".pluginname" )
-                    .addClass( "ui-widget-header ui-corner-all" )
-                    .end()
-            .find( ".plugindesc" );
-        $(".save-all").on("click",function(e){
-            e.preventDefault();
-            yesimeant();
-        });
-        $(".force_reload").on("click",function(e){
-            e.preventDefault();
-            window.location.reload(true);
-        });
-    });
-
-    function yesimeant() {
-        var OPACdidyoumean = serialize_plugins('opac');
-        var INTRAdidyoumean = serialize_plugins('intranet');
-
-        var data = "pref_OPACdidyoumean=" + encodeURIComponent(OPACdidyoumean) + "&pref_INTRAdidyoumean=" + encodeURIComponent(INTRAdidyoumean);
-
-        $.ajax({
-            data: data,
-            type: 'POST',
-            url: '/cgi-bin/koha/svc/config/systempreferences/',
-            success: function () { alert("Successfully saved configuration"); },
-        });
-        return false;
-    }
-
-    function serialize_plugins(interface) {
-        var serializedconfig = '[';
-        $('#didyoumean' + interface + ' .pluginlist .plugin').each(function(index) {
-            var name = $(this).find('.pluginlabel').text();
-            var enabled = $(this).find('input:checkbox:checked').length ?
-                          ', "enabled": 1' : '';
-            serializedconfig += '{ "name": "' + name + '"' + enabled + '}, ';
-            });
-            serializedconfig = serializedconfig.substring(0, serializedconfig.length - 2);
-            serializedconfig += ']';
-            return serializedconfig;
-    }
-</script>
 </head>
+
 <body id="admin_didyoumean" class="admin">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'prefs-admin-search.inc' %]
 [% INCLUDE 'admin-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
+    <script type="text/javascript">
+        $(document).ready(function() {
+            $( ".pluginlist" ).sortable();
+            $( ".plugin" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
+                .find( ".pluginname" )
+                        .addClass( "ui-widget-header ui-corner-all" )
+                        .end()
+                .find( ".plugindesc" );
+            $(".save-all").on("click",function(e){
+                e.preventDefault();
+                yesimeant();
+            });
+            $(".force_reload").on("click",function(e){
+                e.preventDefault();
+                window.location.reload(true);
+            });
+        });
+
+        function yesimeant() {
+            var OPACdidyoumean = serialize_plugins('opac');
+            var INTRAdidyoumean = serialize_plugins('intranet');
+
+            var data = "pref_OPACdidyoumean=" + encodeURIComponent(OPACdidyoumean) + "&pref_INTRAdidyoumean=" + encodeURIComponent(INTRAdidyoumean);
+
+            $.ajax({
+                data: data,
+                type: 'POST',
+                url: '/cgi-bin/koha/svc/config/systempreferences/',
+                success: function () { alert("Successfully saved configuration"); },
+            });
+            return false;
+        }
+
+        function serialize_plugins(interface) {
+            var serializedconfig = '[';
+            $('#didyoumean' + interface + ' .pluginlist .plugin').each(function(index) {
+                var name = $(this).find('.pluginlabel').text();
+                var enabled = $(this).find('input:checkbox:checked').length ?
+                              ', "enabled": 1' : '';
+                serializedconfig += '{ "name": "' + name + '"' + enabled + '}, ';
+                });
+                serializedconfig = serializedconfig.substring(0, serializedconfig.length - 2);
+                serializedconfig += ']';
+                return serializedconfig;
+        }
+    </script>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]
index c974417..15c4de2 100644 (file)
@@ -1,15 +1,7 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; SMS cellular providers</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-    //<![CDATA[
-        var MSG_SMS_PATRONS_USING = _("Are you sure you want to delete %s? %s patron(s) are using it!");
-        var MSG_SMS_DELETE_CONFIRM = _("Are you sure you want to delete %s?");
-        var LABEL_SMS_ADD_PROVIDER = _("Add an SMS cellular provider");
-        var LABEL_SMS_EDIT_PROVIDER = _("Edit provider %s");
-    //]]>
-</script>
-<script type="text/javascript" src="[% interface %]/[% theme %]/js/sms_providers.js"></script>
 </head>
 
 <body id="admin_sms_providers" class="admin">
         </div>
     </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
+    <script type="text/javascript">
+        var MSG_SMS_PATRONS_USING = _("Are you sure you want to delete %s? %s patron(s) are using it!");
+        var MSG_SMS_DELETE_CONFIRM = _("Are you sure you want to delete %s?");
+        var LABEL_SMS_ADD_PROVIDER = _("Add an SMS cellular provider");
+        var LABEL_SMS_EDIT_PROVIDER = _("Edit provider %s");
+    </script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/sms_providers.js"></script>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]
index f210049..6ae0314 100644 (file)
@@ -1,44 +1,11 @@
+[% SET footerjs = 1 %]
 [% USE Koha %]
 [% USE KohaDates %]
 [% USE Price %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Koha usage statistics</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <link rel="stylesheet" href="[% interface %]/lib/leaflet/leaflet.css" />
-<script src="[% interface %]/lib/leaflet/leaflet.js"></script>
-
-<script type="text/javascript">
-//<![CDATA[
-    function positionMap() {
-        var tbh = $("#mapid");
-        var mapContainer = tbh.parent();
-        mapContainer.css('position', 'relative');
-        mapContainer.css('min-height', tbh.outerHeight(true));
-        tbh.css('position', 'absolute');
-        tbh.css('right', 0);
-
-        var offsetTop = mapContainer.offset().top;
-        var s = parseInt($(window).scrollTop(), 10);
-        tbh.css('top', '').css('bottom', '');
-        if (s > offsetTop) {
-            var mapContainerOffsetBottom = offsetTop + mapContainer.innerHeight();
-            if (s + tbh.outerHeight(true) > mapContainerOffsetBottom) {
-                tbh.css('bottom', 0);
-            } else {
-                tbh.css('top', s - offsetTop);
-            }
-        } else {
-            tbh.css('top', 0);
-        }
-    }
-
-    $(document).ready(function() {
-        $(window).scroll(positionMap);
-        positionMap();
-    });
-//]]>
-</script>
 </head>
 
 <body id="admin_usage_statistics" class="admin">
             <a class="cancel" href="/cgi-bin/koha/admin/usage_statistics.pl">Cancel</a>
         </fieldset>
     </form>
+</div>
+</div>
+<div class="yui-b">
+[% INCLUDE 'admin-menu.inc' %]
+</div>
+</div>
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
+    <script src="[% interface %]/lib/leaflet/leaflet.js"></script>
+    <script type="text/javascript">
+        function positionMap() {
+            var tbh = $("#mapid");
+            var mapContainer = tbh.parent();
+            mapContainer.css('position', 'relative');
+            mapContainer.css('min-height', tbh.outerHeight(true));
+            tbh.css('position', 'absolute');
+            tbh.css('right', 0);
+
+            var offsetTop = mapContainer.offset().top;
+            var s = parseInt($(window).scrollTop(), 10);
+            tbh.css('top', '').css('bottom', '');
+            if (s > offsetTop) {
+                var mapContainerOffsetBottom = offsetTop + mapContainer.innerHeight();
+                if (s + tbh.outerHeight(true) > mapContainerOffsetBottom) {
+                    tbh.css('bottom', 0);
+                } else {
+                    tbh.css('top', s - offsetTop);
+                }
+            } else {
+                tbh.css('top', 0);
+            }
+        }
+
+        $(document).ready(function() {
+            $(window).scroll(positionMap);
+            positionMap();
+        });
 
-    <script>
         var map = L.map('mapid').setView([0,0], 1);
 
         L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png', {
         });
 
     </script>
-
-</div>
-</div>
-<div class="yui-b">
-[% INCLUDE 'admin-menu.inc' %]
-</div>
-</div>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]
index d25cc36..f610cd4 100644 (file)
@@ -1,3 +1,4 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 
 [% BLOCK ServerType %]
 
 [% IF op == 'list' %]
     <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
-    [% INCLUDE 'datatables.inc' %]
 [% END %]
-
-<script type="text/javascript">
-//<![CDATA[
-[% IF ( add_form ) %]
-    $(document).ready(function(){
-        // Update selects for syntax, encoding and recordtype
-        [% IF server %]
-            $("#syntax").val('[% server.syntax %]');
-            $("#encoding").val('[% server.encoding %]');
-            $("#recordtype").val('[% server.recordtype %]');
-        [% END %]
-        // Disable recordtype (and default to bib) for non-Z3950 servers until auth is supported
-        [% UNLESS (server.servertype||type) == 'zed' %]
-            $("#recordtype").prop('disabled',true);
-        [% END %]
-        $( "#serverentry" ).validate({
-            rules: {
-                servername: { required: true },
-                host: { required: true },
-                port: {
-                    required: true,
-                    number: true
-                },
-                db: { required: true },
-                rank: { number: true },
-                timeout: { number: true }
-            }
-        });
-        $("#serverentry").submit(function( event ) {
-            // first test if show_sru_fields exists
-            if( $('#show_sru_fields').length && $('#show_sru_fields').val()=='' && !confirm( _("No SRU search field mappings have been defined. This means that all field searches will go through the whole record. Continue?"))) {
-                return false;
-            }
-            // copy show_sru_fields to hidden counterpart
-            $('#sru_fields').val( $('#show_sru_fields').val() );
-            // enable recordtype to include field in post
-            $('#recordtype').prop('disabled',false);
-        });
-        $("#servername").on("blur",function(){
-            toUC(this);
-        });
-        $("#modify_sru_fields").on("click",function(){
-            ModMapping();
-        });
-    });
-    function ModMapping () {
-        var map= $('#show_sru_fields').val();
-        window.open('/cgi-bin/koha/admin/sru_modmapping.pl?mapping='+map,'popup','width=800,height=400,resizable=yes,toolbar=false,scrollbars=yes,top');
-    }
-[% ELSE %]
-    $(document).ready(function() {
-        $("#serverst").dataTable($.extend(true, {}, dataTablesDefaults, {
-            "aoColumnDefs": [
-                { "aTargets": [2,3,4,7,8,9,10,11], "bSortable": false, "bSearchable": false },
-            ],
-            "sPaginationType": "four_button"
-        }));
-        $(".delete").on("click",function(e){
-            var servername = $(this).data("servername");
-            if( confirm( _("Are you sure you want to delete server %s?").format(servername) ) ) {
-                return true;
-            } else {
-                e.preventDefault();
-            }
-        });
-    });
-[% END %]
-//]]>
-</script>
-
 </head>
+
 <body id="admin_z3950servers" class="admin">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'z3950-admin-search.inc' %]
 [% INCLUDE 'admin-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu.js"></script>
+    [% IF op == 'list' %]
+        [% INCLUDE 'datatables.inc' %]
+    [% END %]
+
+    <script type="text/javascript">
+        [% IF ( add_form ) %]
+            $(document).ready(function(){
+                // Update selects for syntax, encoding and recordtype
+                [% IF server %]
+                    $("#syntax").val('[% server.syntax %]');
+                    $("#encoding").val('[% server.encoding %]');
+                    $("#recordtype").val('[% server.recordtype %]');
+                [% END %]
+                // Disable recordtype (and default to bib) for non-Z3950 servers until auth is supported
+                [% UNLESS (server.servertype||type) == 'zed' %]
+                    $("#recordtype").prop('disabled',true);
+                [% END %]
+                $( "#serverentry" ).validate({
+                    rules: {
+                        servername: { required: true },
+                        host: { required: true },
+                        port: {
+                            required: true,
+                            number: true
+                        },
+                        db: { required: true },
+                        rank: { number: true },
+                        timeout: { number: true }
+                    }
+                });
+                $("#serverentry").submit(function( event ) {
+                    // first test if show_sru_fields exists
+                    if( $('#show_sru_fields').length && $('#show_sru_fields').val()=='' && !confirm( _("No SRU search field mappings have been defined. This means that all field searches will go through the whole record. Continue?"))) {
+                        return false;
+                    }
+                    // copy show_sru_fields to hidden counterpart
+                    $('#sru_fields').val( $('#show_sru_fields').val() );
+                    // enable recordtype to include field in post
+                    $('#recordtype').prop('disabled',false);
+                });
+                $("#servername").on("blur",function(){
+                    toUC(this);
+                });
+                $("#modify_sru_fields").on("click",function(){
+                    ModMapping();
+                });
+            });
+            function ModMapping () {
+                var map= $('#show_sru_fields').val();
+                window.open('/cgi-bin/koha/admin/sru_modmapping.pl?mapping='+map,'popup','width=800,height=400,resizable=yes,toolbar=false,scrollbars=yes,top');
+            }
+        [% ELSE %]
+            $(document).ready(function() {
+                $("#serverst").dataTable($.extend(true, {}, dataTablesDefaults, {
+                    "aoColumnDefs": [
+                        { "aTargets": [2,3,4,7,8,9,10,11], "bSortable": false, "bSearchable": false },
+                    ],
+                    "sPaginationType": "four_button"
+                }));
+                $(".delete").on("click",function(e){
+                    var servername = $(this).data("servername");
+                    if( confirm( _("Are you sure you want to delete server %s?").format(servername) ) ) {
+                        return true;
+                    } else {
+                        e.preventDefault();
+                    }
+                });
+            });
+        [% END %]
+    </script>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]