Bug 19656: Move rotating collections templates JS to the footer
authorOwen Leonard <oleonard@myacpl.org>
Mon, 20 Nov 2017 16:41:33 +0000 (16:41 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Dec 2017 14:34:22 +0000 (11:34 -0300)
This patch modifies the staff client's rotating collections templates so
that JavaScript is included in the footer instead of the header.

The patch moves JavaScript from each template and the rotating
collections toolbar into a single external JavaScript file.

To test, apply the patch and test the JavaScript-driven features of
each page: 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/includes/rotating-collections-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt
koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tt
koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tt
koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt
koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js [new file with mode: 0644]

index 9dd3e7a..f46f9f2 100644 (file)
@@ -1,31 +1,17 @@
-<script type="text/javascript">
-    $(document).ready(function(){
-        $(".confirmdelete").click(function(){
-            $(this).parents('tr').addClass("warn");
-            if(confirm(_("Are you sure you want to delete this rotating collection?"))){
-                return true;
-            } else {
-                $(this).parents('tr').removeClass("warn");
-                return false;
-            }
-        });
-});
-</script>
+<div id="toolbar" class="btn-toolbar">
+    <div class="btn-group">
+        <a class="btn btn-default btn-sm" href="/cgi-bin/koha/rotating_collections/editCollections.pl?action=new"><i class="fa fa-plus"></i> New collection</a>
+    </div>
 
-            <div id="toolbar" class="btn-toolbar">
-                <div class="btn-group">
-                    <a class="btn btn-default btn-sm" href="/cgi-bin/koha/rotating_collections/editCollections.pl?action=new"><i class="fa fa-plus"></i> New collection</a>
-                </div>
-
-                [% IF ( colId ) %]
-                    <div class="btn-group">
-                        <a class="btn btn-default btn-sm" href="/cgi-bin/koha/rotating_collections/transferCollection.pl?colId=[% colId %]"><i class="fa fa-exchange"></i> Transfer</a>
-                    </div>
-                    <div class="btn-group">
-                        <a class="btn btn-default btn-sm" href="/cgi-bin/koha/rotating_collections/editCollections.pl?action=edit&amp;colId=[% colId %]"><i class="fa fa-pencil"></i> Edit</a>
-                    </div>
-                    <div class="btn-group">
-                        <a class="btn btn-default btn-sm confirmdelete" href="/cgi-bin/koha/rotating_collections/editCollections.pl?action=delete&amp;colId=[% colId %]"><i class="fa fa-trash"></i> Delete</a>
-                    </div>
-                [% END %]
-            </div>
+    [% IF ( colId ) %]
+        <div class="btn-group">
+            <a class="btn btn-default btn-sm" href="/cgi-bin/koha/rotating_collections/transferCollection.pl?colId=[% colId %]"><i class="fa fa-exchange"></i> Transfer</a>
+        </div>
+        <div class="btn-group">
+            <a class="btn btn-default btn-sm" href="/cgi-bin/koha/rotating_collections/editCollections.pl?action=edit&amp;colId=[% colId %]"><i class="fa fa-pencil"></i> Edit</a>
+        </div>
+        <div class="btn-group">
+            <a class="btn btn-default btn-sm confirmdelete" href="/cgi-bin/koha/rotating_collections/editCollections.pl?action=delete&amp;colId=[% colId %]"><i class="fa fa-trash"></i> Delete</a>
+        </div>
+    [% END %]
+</div>
index 43d4a8b..c7bf918 100644 (file)
@@ -1,14 +1,9 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo; Collection [% colTitle %] &rsquo; Add or remove items</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript">
-    //<![CDATA[
-        $( document ).ready(function() {
-            $("#barcode").focus();
-        });
-    //]]>
-</script>
 </head>
+
 <body id="rcoll_addItems" class="tools rcoll">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
             [% INCLUDE 'tools-menu.inc' %]
         </div>
     </div> <!-- /#bd -->
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/rotating-collections.js"></script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 9504b61..cb0e729 100644 (file)
@@ -1,3 +1,4 @@
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo;
     [%- IF ( action == "new" ) %]
             [% INCLUDE 'tools-menu.inc' %]
         </div>
     </div> <!-- /#bd -->
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/rotating-collections.js"></script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 7cf35f7..3564235 100644 (file)
@@ -1,30 +1,11 @@
 [% USE Branches %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Rotating collections</title>
 [% INCLUDE 'doc-head-close.inc' %]
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-    $(document).ready(function(){
-        $(".confirmdelete").click(function(){
-            $(this).parents('tr').addClass("warn");
-            if(confirm(_("Are you sure you want to delete this collection?"))){
-                return true;
-            } else {
-                $(this).parents('tr').removeClass("warn");
-                return false;
-            }
-        });
-        $('#rotating-collections-table').dataTable($.extend(true, {}, dataTablesDefaults, {
-            "autoWidth": false,
-            "aoColumnDefs": [
-                { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
-            ],
-            "sPaginationType": "four_button"
-        } ));
-    });
-</script>
 </head>
+
 <body id="rcoll_rotatingCollections" class="tools rcoll">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
             [% INCLUDE 'tools-menu.inc' %]
         </div>
     </div> <!-- /#bd -->
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/rotating-collections.js"></script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
index 43f76a4..7d457b8 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Branches %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Rotating collections &rsaquo; Transfer collection</title>
 [% INCLUDE 'doc-head-close.inc' %]
             [% INCLUDE 'tools-menu.inc' %]
         </div>
     </div> <!-- /#bd -->
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/rotating-collections.js"></script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js b/koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js
new file mode 100644 (file)
index 0000000..bed5e9a
--- /dev/null
@@ -0,0 +1,27 @@
+/* global _ dataTablesDefaults */
+
+$(document).ready(function(){
+    $("#barcode").focus();
+
+    $(".confirmdelete").click(function(){
+        $(this).parents('tr').addClass("warn");
+        if(confirm(_("Are you sure you want to delete this rotating collection?"))){
+            return true;
+        } else {
+            $(this).parents('tr').removeClass("warn");
+            return false;
+        }
+    });
+
+    if( $('#rotating-collections-table').length > 0 ){
+        $('#rotating-collections-table').dataTable($.extend(true, {}, dataTablesDefaults, {
+            "autoWidth": false,
+            "aoColumnDefs": [
+                { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
+            ],
+            "sPaginationType": "four_button"
+        } ));
+    }
+
+
+});