Bug 26098: Fix JS error on the fund list view when no fund displayed
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 30 Jul 2020 08:51:26 +0000 (10:51 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 6 Aug 2020 09:37:06 +0000 (11:37 +0200)
TypeError: this.data(...) is undefined
in jquery.treetable.js

Test plan:
Go to the fund list view
Select a filter that will return no result
=> With this patch applied there is no JS error in the console

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt

index 4a6d561..ce88e28 100644 (file)
         //<![CDATA[
             //
             $(document).ready(function() {
-                var oTable = $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
-                    "fnDrawCallback": function ( oSettings ) {
-                        if ( oSettings.aiDisplay.length == 0 )
-                        {
-                            return;
-                        }
+                [% IF budgets %]
+                    var oTable = $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
+                        "fnDrawCallback": function ( oSettings ) {
+                            if ( oSettings.aiDisplay.length == 0 )
+                            {
+                                return;
+                            }
 
-                        var nTrs = $('#budgeth tbody tr');
-                        var iColspan = nTrs[0].getElementsByTagName('td').length;
-                        var sLastGroup = "";
-                        for ( var i=0 ; i<nTrs.length ; i++ )
-                        {
-                            var iDisplayIndex = oSettings._iDisplayStart + i;
-                            var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
-                            if ( sGroup != sLastGroup )
+                            var nTrs = $('#budgeth tbody tr');
+                            var iColspan = nTrs[0].getElementsByTagName('td').length;
+                            var sLastGroup = "";
+                            for ( var i=0 ; i<nTrs.length ; i++ )
                             {
-                                var nGroup = document.createElement( 'tr' );
-                                var nCell = document.createElement( 'td' );
-                                nCell.colSpan = iColspan;
-                                nCell.className = "group";
-                                nCell.innerHTML = sGroup;
-                                nGroup.appendChild( nCell );
-                                nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
-                                sLastGroup = sGroup;
+                                var iDisplayIndex = oSettings._iDisplayStart + i;
+                                var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
+                                if ( sGroup != sLastGroup )
+                                {
+                                    var nGroup = document.createElement( 'tr' );
+                                    var nCell = document.createElement( 'td' );
+                                    nCell.colSpan = iColspan;
+                                    nCell.className = "group";
+                                    nCell.innerHTML = sGroup;
+                                    nGroup.appendChild( nCell );
+                                    nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
+                                    sLastGroup = sGroup;
+                                }
                             }
-                        }
-                    },
-                    "footerCallback": function ( row, data, start, end, display ) {
-                        var api = this.api(), data;
-                        footer_column_sum( api, [ 4, 6, 8, 10 ], 2 );
-                    },
-                    "aoColumnDefs": [
-                        { "bVisible": false, "aTargets": [ 0, 1 ] },
-                        { "bSortable": false, "aTargets": ["_all"] }
-                    ],
-                    'dom': '<"top pager"ilpf>tr<"bottom pager"ip>',
-                    'bSort': true,
-                    'aaSortingFixed': [[ 1, 'asc' ]],
-                    'bPaginate': false,
-                    "bAutoWidth": false
-                }));
-
-                $(oTable).treetable({
-                    expandable: true
-                });
-                $(oTable).treetable('expandAll');
-                $("#expand_all").click(function(e){
-                    e.preventDefault();
+                        },
+                        "footerCallback": function ( row, data, start, end, display ) {
+                            var api = this.api(), data;
+                            footer_column_sum( api, [ 4, 6, 8, 10 ], 2 );
+                        },
+                        "aoColumnDefs": [
+                            { "bVisible": false, "aTargets": [ 0, 1 ] },
+                            { "bSortable": false, "aTargets": ["_all"] }
+                        ],
+                        'dom': '<"top pager"ilpf>tr<"bottom pager"ip>',
+                        'bSort': true,
+                        'aaSortingFixed': [[ 1, 'asc' ]],
+                        'bPaginate': false,
+                        "bAutoWidth": false
+                    }));
+
+                    $(oTable).treetable({
+                        expandable: true
+                    });
                     $(oTable).treetable('expandAll');
-                });
-                $("#collapse_all").click(function(e){
-                    e.preventDefault();
-                    $(oTable).treetable('collapseAll');
-                });
-
-                [% UNLESS budget_period_id %]
-                  $("#hide_inactive").click(function(e){
-                    e.preventDefault();
-                    oTable.fnFilter( 1, 0 ); // Show only active=1
-                  });
-                  $("#show_inactive").click(function(e){
-                    e.preventDefault();
-                    oTable.fnFilter( '', 0 );
-                  });
-                  $("#hide_inactive").click();
+                    $("#expand_all").click(function(e){
+                        e.preventDefault();
+                        $(oTable).treetable('expandAll');
+                    });
+                    $("#collapse_all").click(function(e){
+                        e.preventDefault();
+                        $(oTable).treetable('collapseAll');
+                    });
+
+                    [% UNLESS budget_period_id %]
+                      $("#hide_inactive").click(function(e){
+                        e.preventDefault();
+                        oTable.fnFilter( 1, 0 ); // Show only active=1
+                      });
+                      $("#show_inactive").click(function(e){
+                        e.preventDefault();
+                        oTable.fnFilter( '', 0 );
+                      });
+                      $("#hide_inactive").click();
+                    [% END %]
+                    oTable.fnAddFilters("filter", 750);
                 [% END %]
-                oTable.fnAddFilters("filter", 750);
 
                 $("#filterbutton").click(function() {
                     $("#fundfilters").slideToggle(0);