Bug 36640: Fix itemsearch

We use the regular _dt_add_filter and pass the filters_options for
selects \o/
We need to iterate again to make it easier to write (lot of duplicated
code to build the AV list) but that's for later!

Signed-off-by: Jake Deery <jake.deery@ptfs-europe.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2024-10-31 10:11:28 +01:00 committed by Katrin Fischer
parent 4c29369dfc
commit 9bc4d8e40e
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 72 additions and 61 deletions

View File

@ -4,7 +4,8 @@
<!-- columns_settings.inc -->
<script>
function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
// default_filters is not used but keeping the same constructor as kohaTable for consistency
function KohaTable(id_selector, dt_parameters, table_settings, add_filters, default_filters, filters_options) {
var counter = 0;
var hidden_ids = [];
var included_ids = [];
@ -260,6 +261,10 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
);
}
if ( add_filters ) {
dt_parameters['orderCellsTop'] = true;
}
var table = $(selector);
var new_parameters = {}
@ -303,12 +308,12 @@ function KohaTable(id_selector, dt_parameters, table_settings, add_filters) {
}).columns( hidden_ids ).visible( false );
if ( add_filters ) {
_dt_add_filters(table, table_dt);
_dt_add_filters(table, table_dt, filters_options);
}
table_dt.on("column-visibility.dt", function(){
if ( add_filters ) {
_dt_add_filters(table, table_dt);
_dt_add_filters(table, table_dt, filters_options);
}
});

View File

@ -2,6 +2,8 @@
[% USE To %]
[% USE Asset %]
[% USE AuthorisedValues %]
[% USE Branches %]
[% USE ItemTypes %]
[% USE TablesSettings %]
[% PROCESS 'i18n.inc' %]
[%- BLOCK form_label -%]
@ -517,7 +519,7 @@
+ ' </div>'
+ ' </div>'
+ ' <table id="results">'
+ ' <thead>' + tr + tr + '</thead>'
+ ' <thead>' + tr + '</thead>'
+ ' <tbody></tbody>'
+ ' </table>'
+ '</div>';
@ -568,6 +570,63 @@
var params = getParams($form);
const all_libraries = [% To.json(Branches.all) | $raw %];
const libraries_filters = all_libraries.map(e => {
e["_id"] = e["branchcode"];
e["_str"] = e["branchname"];
return e;
});
const libraries_names = new Map(all_libraries.map( l => [l.branchcode, l.branchname] ));
const all_item_types = [% To.json(ItemTypes.Get) | $raw %];
const item_types_filters = all_item_types.map(e => {
e["_id"] = e["itemtype"];
e["_str"] = e["translated_description"];
return e;
});
const item_types_notforloan = new Map(all_item_types.map( it => [it.itemtype, it.notforloan] ));
const all_ccodes = [% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.ccode' })) | $raw %].map( av => {
av._id = av.authorised_value;
av._str = av.lib;
return av;
} );
const all_locations = [% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.location' })) | $raw %].map( av => {
av._id = av.authorised_value;
av._str = av.lib;
return av;
} );
const all_notforloans = [% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.notforloan' })) | $raw %].map( av => {
av._id = av.authorised_value;
av._str = av.lib;
return av;
} );
const all_losts = [% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.itemlost' })) | $raw %].map( av => {
av._id = av.authorised_value;
av._str = av.lib;
return av;
} );
const all_withdrawns = [% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.withdrawn' })) | $raw %].map( av => {
av._id = av.authorised_value;
av._str = av.lib;
return av;
} );
const all_damageds = [% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.damaged' })) | $raw %].map( av => {
av._id = av.authorised_value;
av._str = av.lib;
return av;
} );
let filters_options = {
4: () => all_ccodes,
9: () => all_libraries,
10: () => all_libraries,
11: () => all_locations,
12: () => all_item_types,
14: () => all_notforloans,
15: () => all_losts,
16: () => all_withdrawns,
17: () => all_damageds,
};
var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %];
KohaTable('results' , {
"bKohaColumnsUseNames": true,
@ -592,7 +651,7 @@
'dom': 'C<"top pager"ilpB>tr<"bottom pager"ip>',
'order': [[1, 'asc']],
'columns': [
{ 'name': 'checkbox', 'orderable': false },
{ 'name': 'checkbox', 'orderable': false, searchable: false, },
{ 'name': 'title' },
{ 'name': 'publicationyear' },
{ 'name': 'publishercode' },
@ -613,68 +672,15 @@
{ 'name': 'issues' },
{ 'name': 'datelastborrowed' },
{ 'name': 'date_due' },
{ 'name': 'actions', 'orderable': false }
{ 'name': 'actions', 'orderable': false, searchable: false, }
],
"pagingType": "full_numbers",
"drawCallback": function( settings ) {
prepSelections();
},
fixedHeader: false // There is a bug on this view
}, table_settings ).columnFilter({
'sPlaceHolder': 'head:after',
"aoColumns": [
null,
{ 'type': 'text' },
{ 'type': 'text' },
{ 'type': 'text' },
[% IF ccodes.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => ccodes %] },
[% ELSE %]
null,
[% END %]
{ 'type': 'text' },
{ 'type': 'text' },
{ 'type': 'text' },
{ 'type': 'text' },
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => branches %] },
[% IF locations.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => locations %] },
[% ELSE %]
null,
[% END %]
[% IF itemtypes.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemtypes %] },
[% ELSE %]
null,
[% END %]
{ 'type': 'text' },
[% IF notforloans.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => notforloans %] },
[% ELSE %]
null,
[% END %]
[% IF itemlosts.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => itemlosts %] },
[% ELSE %]
null,
[% END %]
[% IF withdrawns.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => withdrawns %] },
[% ELSE %]
null,
[% END %]
[% IF damageds.size %]
{ 'type': 'select', 'values': [% INCLUDE escape_html_value_label elts => damageds %] },
[% ELSE %]
null,
[% END %]
{ 'type': 'text' },
{ 'type': 'text' },
{ 'type': 'text' },
null
]
});
}, table_settings, true, null, filters_options );
$('#results').on('draw.dt', function (e, settings) {
prepSelections();
$('[data-bs-toggle="tooltip"]').tooltip();