From 60f41d624b3790210e176a9f23f57ac849e30f49 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Dec 2021 12:24:20 +0100 Subject: [PATCH] Bug 29648: Cities administration view - REST API Here we need to deal with the other DT config (in datatables.js, not columns_settings.inc). Test plan: Same as "normal" Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- admin/columns_settings.yml | 2 + .../prog/en/modules/admin/cities.tt | 4 +- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 41 ++++++++++++------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index f8f518938e..a392306fab 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -197,6 +197,8 @@ modules: admin: cities: table_cities: + default_display_length: 20 + default_sort_order: 0 columns: - columnname: city_id diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt index 0df7eb3bb5..feea946e9e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt @@ -214,7 +214,7 @@ [% INCLUDE 'columns_settings.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index c33943df1e..97c017267f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -496,13 +496,13 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { * We extend the options set with the `criteria` key which allows * the developer to select the match type to be applied during searches * Valid keys are: `contains`, `starts_with`, `ends_with` and `exact` - * @param {Object} column_settings The arrayref as returned by TableSettings.GetColums function available + * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function available * from the columns_settings template toolkit include * @param {Boolean} add_filters Add a filters row as the top row of the table * @param {Object} default_filters Add a set of default search filters to apply at table initialisation * @return {Object} The dataTables instance */ - $.fn.kohaTable = function(options, columns_settings, add_filters, default_filters) { + $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) { var settings = null; if ( add_filters ) { @@ -683,19 +683,23 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { var hidden_ids = []; var included_ids = []; - $(columns_settings).each( function() { - var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' ); - var used_id = settings.bKohaColumnsUseNames ? named_id : counter; - if ( used_id == -1 ) return; - if ( this['is_hidden'] == "1" ) { - hidden_ids.push( used_id ); - } - if ( this['cannot_be_toggled'] == "0" ) { - included_ids.push( used_id ); - } - counter++; - }); + if ( table_settings ) { + var columns_settings = table_settings['columns']; + $(columns_settings).each( function() { + var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' ); + var used_id = settings.bKohaColumnsUseNames ? named_id : counter; + if ( used_id == -1 ) return; + + if ( this['is_hidden'] == "1" ) { + hidden_ids.push( used_id ); + } + if ( this['cannot_be_toggled'] == "0" ) { + included_ids.push( used_id ); + } + counter++; + }); + } var exportColumns = ":visible:not(.noExport)"; if( settings.hasOwnProperty("exportColumns") ){ @@ -799,6 +803,15 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { settings['orderCellsTop'] = true; } + if ( table_settings ) { + if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) { + settings["pageLength"] = table_settings['default_display_length']; + } + if ( table_settings.hasOwnProperty('default_sort_order') && table_settings['default_sort_order'] != null ) { + settings["order"] = [[ table_settings['default_sort_order'], 'asc' ]]; + } + } + var table = $(this).dataTable(settings); -- 2.39.5