Bug 26234: Teach our KohaTable constructor the specific th classes

We have different classes we can use to set specific behaviours on
table columns: title-string, string-sort, anti-the and NoSort.
We should not need to pass them to the DataTable constructor, we could
teach it that we always want to apply them.

It will avoid bug like bug 26233

The goal is to define them in a centralised place
(columns_settings.inc) then only use the class on the th

Test plan:
Different behaviour and tables must be tested to confirm it works
correctly. Focus must be put on table when aoColumnsDefs is passed from
the template and confirm that this will add more info to aoColumnsDefs
and not remove the existing ones.

Note that this only work when KohaTable is used.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2020-08-18 09:59:24 +00:00
parent 94a445d413
commit d3f3a55e0b
31 changed files with 28 additions and 132 deletions

View file

@ -127,8 +127,21 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
thead_row.before(clone);
}
table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
var new_parameters = {}
$.extend(true, new_parameters, dataTablesDefaults, dt_parameters);
var default_column_defs = [
{ "aTargets": [ "title-string" ], "sType": "title-string" },
{ "aTargets": [ "string-sort" ], "sType": "string" },
{ "aTargets": [ "anti-the" ], "sType": "anti-the" },
{ "aTargets": [ "NoSort" ], "bSortable": false, "bSearchable": false },
];
if ( new_parameters["aoColumnDefs"] === undefined ) {
new_parameters["aoColumnDefs"] = default_column_defs;
} else {
$.extend(true, new_parameters, default_column_defs);
}
table.dataTable(new_parameters);
table.DataTable().on("column-visibility.dt", function(){
if( typeof columnsInit == 'function' ){
// This function can be created separately and used to trigger

View file

@ -929,12 +929,6 @@
[% SET table_settings = TablesSettings.GetTableSettings( 'acqui', 'basket', 'orders' ) %];
$(document).ready(function() {
KohaTable("orders", {
[% IF ( active ) %]
"aoColumnDefs": [
{ "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
{ "sType": "anti-the", "aTargets": [ "anti-the" ] }
],
[% END %]
"sPaginationType": "full",
"autoWidth": false,
"exportColumns": [0,1,2,3,4,5,6,7,8,9,10,11,12,13],

View file

@ -321,10 +321,6 @@ Basket [% basket.basketno | html %] &rsaquo; Duplicate existing orders
$('span.hint').hide();
var columns_settings;// = [% TablesSettings.GetColumns( 'acqui', 'histsearch', 'histsearcht', 'json' ) | $raw %];
KohaTable("table_orders", {
"aoColumnDefs": [
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
"bPaginate": false
}, columns_settings );

View file

@ -132,10 +132,6 @@
$(document).ready(function() {
var columns_settings = [% TablesSettings.GetColumns( 'acqui', 'histsearch', 'histsearcht', 'json' ) | $raw %];
KohaTable("histsearcht", {
"aoColumnDefs": [
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
"sPaginationType": "full"
}, columns_settings );

View file

@ -289,11 +289,6 @@
var columns_settings = [% TablesSettings.GetColumns( 'acqui', 'lateorders', 'late_orders', 'json' ) | $raw %];
late_orderst = KohaTable("late_orders", {
"aoColumnDefs": [
{ "targets": [ "NoSort" ],"sortable": false,"searchable": false },
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
"sorting": [[ 1, "asc" ]],
"sPaginationType": "full",
"bAutoWidth": false,

View file

@ -218,7 +218,7 @@
<th>Description (OPAC)</th>
<th>Icon</th>
<th>Library limitations</th>
<th class="noExport">Actions</th>
<th class="noExport NoSort">Actions</th>
</tr>
</thead><tbody>
[% FOREACH loo IN loop %]
@ -317,9 +317,6 @@
var columns_settings = []; // Empty because there are no columns we want to be configurable
KohaTable("categoriest", {
"aoColumnDefs": [
{ "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
],
"aaSorting": [[ 0, "asc" ]],
"sPaginationType": "full"
}, columns_settings);

View file

@ -183,7 +183,7 @@
<th class="title-string">Last updated</th>
<th>Active</th>
<th>Archived</th>
<th>Actions</th>
<th class="NoSort">Actions</th>
</tr>
</thead>
<tbody>
@ -249,10 +249,6 @@
columns_settings = [% TablesSettings.GetColumns( 'admin', 'currency', 'currencies-table', 'json' ) | $raw %]
var issuest = KohaTable("currencies-table", {
dom: 'B<"clearfix">t',
"columnDefs": [
{ "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
}, columns_settings );
// prevents users to check active with a currency != 1

View file

@ -404,7 +404,7 @@ Item types administration
<th>Processing fee (when lost)</th>
<th>Checkin message</th>
<th>Library limitations</th>
<th class="noExport">Actions</th>
<th class="noExport NoSort">Actions</th>
</thead>
[% FOREACH itemtype IN itemtypes %]
<tr>
@ -538,9 +538,6 @@ Item types administration
$(document).ready(function() {
KohaTable("table_item_type", {
"aoColumnDefs": [
{ "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
],
"aaSorting": [[ 1, "asc" ]],
"iDisplayLength": 10,
"sPaginationType": "full"

View file

@ -1233,10 +1233,6 @@ Note that permanent location is a code, and location may be an authval.
'sDom': 't',
'bPaginate': false,
'bAutoWidth': false,
"aoColumnDefs": [
{ "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
"bKohaColumnsUseNames": true,
"sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
};
@ -1250,9 +1246,6 @@ Note that permanent location is a code, and location may be an authval.
'bPaginate': false,
'bAutoWidth': false,
"aaSorting": [[ 4, "desc" ]],
"aoColumnDefs": [
{ "aTargets": "title-string", "sType": "title-string" }
]
}, columns_settings);
[% END %]

View file

@ -116,9 +116,6 @@
columns_settings.splice(0,1);
[% END %]
var table = KohaTable("table_issues", {
"aoColumnDefs": [
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
"sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
"aaSorting": [[ 4, "desc" ]],
"sPaginationType": "full_numbers"

View file

@ -51,7 +51,7 @@
<table id="itemst">
<thead>
<tr>
<th>&nbsp;</th>
<th class="NoSort">&nbsp;</th>
[% FOREACH item_header IN item_header_loop %]
[% IF item_header.column_name %]
[% IF date_fields.grep(item_header.column_name).size %]

View file

@ -244,7 +244,6 @@
var columns_settings = [% TablesSettings.GetColumns( 'cataloguing', 'z3950_search', 'resultst', 'json' ) | $raw %];
var thetable = KohaTable("resultst", {
"aoColumnDefs": [
{ "targets": [ "NoSort" ],"sortable": false,"searchable": false },
{ "aTargets": [ 1 ], "sType": "nsb-nse" },
],
"aaSorting": [[ 1, "asc" ]],

View file

@ -282,10 +282,6 @@
KohaTable("overduest", {
"sPaginationType": "full",
"aaSorting": [[0, 'asc']],
"aoColumnDefs": [
{ "sType": "title-string", "aTargets": [ "title-string" ] },
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] }
],
"autoWidth": false,
"stateSave": true
}, columns_settings);

View file

@ -250,11 +250,6 @@
$(document).ready(function() {
var columns_settings = [% TablesSettings.GetColumns('circ', 'holds', 'holds-to-pull', 'json') | $raw %];
var holdst = KohaTable("holdst", {
"aoColumnDefs": [
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] },
{ "sType": "string", "aTargets": [ "string-sort" ] }
],
"sPaginationType": "full_numbers"
}, columns_settings);
holdst.fnAddFilters("filter");

View file

@ -50,7 +50,7 @@
<table id="holdst">
<thead>
<tr>
<th class="hq-title">Title</th>
<th class="hq-title anti-the">Title</th>
<th class="hq-collection">Collection</th>
<th class="hq-itemtype">Item type</th>
<th class="hq-callnumber">Call number</th>
@ -59,7 +59,7 @@
<th class="hq-barcode">Barcode</th>
<th class="hq-patron">Patron</th>
<th class="hq-sendto">Send to</th>
<th class="hq-date">Date</th>
<th class="hq-date title-string">Date</th>
<th class="hq-notes">Notes</th>
</tr>
<tr>
@ -232,9 +232,6 @@
var columns_settings = [% TablesSettings.GetColumns('circ', 'view_holdsqueue', 'holds-table', 'json') | $raw %];
var holdst = KohaTable("holdst", {
"aaSorting": [[ 3, "asc" ]],
"aoColumns": [
{ "sType": "anti-the" },null,null,null,null,null,null,null,null,{ "sType": "title-string" },null
],
"sDom": 'B<"clearfix">t',
"bSortCellsTop": true,
"bPaginate": false

View file

@ -129,20 +129,10 @@
$(document).ready(function() {
KohaTable("holdst", {
"aoColumnDefs": [
{ "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
{ "type": "anti-the", "targets" : [ "anti-the" ] },
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"sPaginationType": "full"
}, holdst_columns_settings);
KohaTable("holdso", {
"aoColumnDefs": [
{ "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
{ "type": "anti-the", "targets" : [ "anti-the" ] },
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"sPaginationType": "full"
}, holdso_columns_settings);

View file

@ -77,7 +77,7 @@
<table id="course_reserves_table">
<thead>
<tr>
<th class="antithe">Title</th>
<th class="anti-the">Title</th>
<th>Author</th>
<th>Barcode</th>
<th>Call number</th>
@ -277,10 +277,6 @@
var rtable = KohaTable("course_reserves_table", {
"sPaginationType": "full",
"bAutoWidth": false,
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 'NoSort' ] },
{ 'sType': "anti-the", 'aTargets' : [ 'antithe'] }
]
}, columns_settings );
$(".delete_item").click(function(){

View file

@ -55,7 +55,7 @@
<th>Note</th>
<th>Amount</th>
<th>Outstanding</th>
<th>Actions</th>
<th class="NoSort">Actions</th>
</tr>
</thead>
@ -318,10 +318,6 @@
"sPaginationType": "full",
'aaSorting': [[0, 'desc']],
"sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
"aoColumnDefs": [
{ "sType": "title-string", "aTargets" : [ "title-string" ] },
{ "bSortable": false, "bSearchable": false, "aTargets": [-1] }
]
}, columns_settings);
$("#filter_c").html('<p><a href="#" id="filter_transacs"><i class="fa fa-filter"></i> '+txtActivefilter+'</a>');
$('#filter_transacs').click(function(e) {

View file

@ -139,10 +139,6 @@
"sPaginationType": "full",
"aaSorting": [[4, 'desc']],
"sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
"aoColumnDefs": [
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
]
}, columns_settings);
});
</script>

View file

@ -222,11 +222,6 @@
var columns_settings = [% TablesSettings.GetColumns('members', 'pay', 'pay-fines-table', 'json') | $raw %];
KohaTable("finest", {
"columnDefs": [
{ "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
],
"paging": false,
'sorting': [[ 3, "asc" ]],
"autoWidth": false

View file

@ -136,10 +136,6 @@
"sPaginationType": "full",
"aaSorting": [[10, 'desc']],
"sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
"aoColumnDefs": [
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
]
}, columns_settings);
var tabs = $("#tabs").tabs({

View file

@ -119,14 +119,14 @@
<table id="patron-list-table">
<thead>
<tr>
<th>&nbsp;</th>
<th class="NoSort">&nbsp;</th>
<th>Card</th>
<th>First name</th>
<th>Surname</th>
<th>Address</th>
<th>Category</th>
<th>Library</th>
<th>Expires on</th>
<th class="title-string">Expires on</th>
<th>Circ notes</th>
</tr>
</thead>
@ -189,12 +189,6 @@
var columns_settings_table = [% TablesSettings.GetColumns('members', 'patron-lists', 'patron-list-table', 'json') | $raw %]
KohaTable('patron-list-table', {
"order": [[ 3, "asc" ]],
"aoColumns": [
null,null,null,null,null,null,null,{ "sType": "title-string" },null
],
"aoColumnDefs": [
{ "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
],
"sPaginationType": "full"
}, columns_settings_table);

View file

@ -53,8 +53,8 @@
<tr>
<th>Code</th>
<th>Description</th>
<th>Cost</th>
<th>Action</th>
<th class="NoSort">Cost</th>
<th class="NoSort">Action</th>
</tr>
</thead>
<tbody>
@ -343,9 +343,6 @@
var items_table = KohaTable("invoices", {
"sPaginationType": "full",
"aaSorting": [[ 0, "asc" ]],
"aoColumnDefs": [
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable":false },
],
}, items_columns_settings);
$(".add_button").on("click", function(e) {

View file

@ -217,7 +217,7 @@
<table id="table_reports">
<thead>
<tr>
<th>&nbsp;</th>
<th class="NoSort">&nbsp;</th>
<th>ID</th>
<th>Report name</th>
<th>Type</th>
@ -241,7 +241,7 @@
[% ELSE %]
<th class="hidden">&nbsp;</th>
[% END %]
<th>Actions</th>
<th class="NoSort">Actions</th>
</tr>
</thead>
<tbody>
@ -1550,10 +1550,8 @@
'sPaginationType': 'full',
'aaSorting': [[ 1, "asc" ]],
'aoColumnDefs': [
{ 'bSortable': false, 'bSearchable':false, 'aTargets': [0, -1] },
{ 'bSearchable': false, 'aTargets': [3] },
{ "aTargets": [ 1, 2 ], "sType": "natural" },
{ "sType": "title-string", "aTargets" : [ "title-string" ] },
{ "visible": false, "aTargets" : [ "hidden" ] }
],
'oLanguage': {

View file

@ -150,10 +150,6 @@
[% SET table_settings = TablesSettings.GetTableSettings( 'reports', 'orders_by_fund', 'funds-table' ) %];
$(document).ready( function () {
var funds_table = KohaTable("funds", {
"columnDefs": [
{ "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"pageLength": [% table_settings.default_display_length | html %],
"order": [[ [% table_settings.default_sort_order | html %], 'asc']],
'autoWidth': false,

View file

@ -518,7 +518,6 @@
"aoColumnDefs": [
{ "bVisible": false, "aTargets": [ 'NoVisible' ] },
{ "bSortable": false, "aTargets": ["_all"] },
{ "aTargets": "title-string", "sType": "title-string" }
],
'bPaginate': false,

View file

@ -1028,10 +1028,6 @@
KohaTable("table_[% loop.count| html %]", {
"sorting": [[ 1, "asc" ]],
"autoWidth": false,
"columnDefs": [
{ "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
]
}, columns_settings );
[% END %]
[% END %]

View file

@ -45,9 +45,6 @@ $(document).ready(function(){
columns_settings.unshift( { cannot_be_toggled: "1" } );
var itemst = KohaTable("itemst", {
"aoColumnDefs": [
{ "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
],
'bPaginate': false,
'bInfo': false,
"bAutoWidth": false,

View file

@ -116,10 +116,6 @@
"dom": '<"top"flp>rt<"clear">',
"sorting": [[ 1, "asc" ]],
"autoWidth": false,
"asColumnDefs": [
{ "type": "anti-the", "targets" : [ "anti-the" ] },
{ "type": "title-string", "targets" : [ "title-string" ] },
]
}, columns_settings );
});
</script>

View file

@ -76,8 +76,6 @@
"sorting": [[ 1, "asc" ]],
"autoWidth": false,
"asColumnDefs": [
{ "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
{ "aTargets": [ 1 ], "sType": "nsb-nse" },
]
}, columns_settings );

View file

@ -1476,7 +1476,6 @@
dom: '<"clearfix">t',
"columnDefs": [
{ "targets": [ -1 ], "sortable": false, "searchable": false },
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"bKohaColumnsUseNames": true,
"autoWidth": false
@ -1486,7 +1485,6 @@
dom: '<"clearfix">t',
"columnDefs": [
{ "targets": [ -1 ], "sortable": false, "searchable": false },
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"bKohaColumnsUseNames": true,
"autoWidth": false
@ -1497,9 +1495,6 @@
KohaTable("#subscriptionst", {
dom: '<"clearfix">t',
"sorting": [[ 1, "desc" ]],
"columnDefs": [
{ "type": "title-string", "targets" : [ "title-string" ] }
],
"autoWidth": false,
"bKohaColumnsUseNames": true
}, serial_column_settings);