View | Details | Raw Unified | Return to bug 38311
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc (-16 / +13 lines)
Lines 205-219 Link Here
205
            });
205
            });
206
        });
206
        });
207
207
208
        const all_libraries = [% To.json(Branches.all) | $raw %];
208
        const all_libraries = [% To.json(Branches.all) | $raw %].map(e => {
209
        const libraries_filters = all_libraries.map(e => {
210
                    e["_id"] = e["branchcode"];
209
                    e["_id"] = e["branchcode"];
211
                    e["_str"] = e["branchname"];
210
                    e["_str"] = e["branchname"];
212
                    return e;
211
                    return e;
213
                });
212
                });
214
        const libraries_names = new Map(all_libraries.map( l => [l.branchcode, l.branchname] ));
213
        const libraries_names = new Map(all_libraries.map( l => [l.branchcode, l.branchname] ));
215
        const all_item_types = [% To.json(ItemTypes.Get) | $raw %];
214
        const all_item_types = [% To.json(ItemTypes.Get) | $raw %].map(e => {
216
        const item_types_filters = all_item_types.map(e => {
217
                    e["_id"] = e["itemtype"];
215
                    e["_id"] = e["itemtype"];
218
                    e["_str"] = e["translated_description"];
216
                    e["_str"] = e["translated_description"];
219
                    return e;
217
                    return e;
Lines 242-247 Link Here
242
            location: new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.location' })) | $raw %].map( av => [av.lib, av.authorised_value])),
240
            location: new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.location' })) | $raw %].map( av => [av.lib, av.authorised_value])),
243
        };
241
        };
244
242
243
        let filters_options = {
244
            item_types: all_item_types,
245
            libraries: all_libraries,
246
            libraries: all_libraries,
247
            statuses: all_statuses,
248
        };
249
245
        [% IF Koha.Preference('URLLinkText') %]
250
        [% IF Koha.Preference('URLLinkText') %]
246
            const url_link_text = "[% Koha.Preference('URLLinkText') | html %]";
251
            const url_link_text = "[% Koha.Preference('URLLinkText') | html %]";
247
        [% ELSE %]
252
        [% ELSE %]
Lines 327-344 Link Here
327
                return $("#" + tab_id + "_status select").val();
332
                return $("#" + tab_id + "_status select").val();
328
            };
333
            };
329
334
330
            let filters_options = {};
331
332
            let itype_col = $("#" + tab_id + "_table thead th[data-colname='itype']").index();
333
            let holdingbranch_col = $("#" + tab_id + "_table thead th[data-colname='holdingbranch']").index();
334
            let homebranch_col = $("#" + tab_id + "_table thead th[data-colname='homebranch']").index();
335
            let status_col = $("#" + tab_id + "_table thead th[data-colname='status']").index();
336
337
            if ( itype_col >= 0 ) filters_options[itype_col] = () => all_item_types;
338
            if ( holdingbranch_col >= 0 ) filters_options[holdingbranch_col] = () => all_libraries;
339
            if ( homebranch_col >= 0 ) filters_options[homebranch_col] = () => all_libraries;
340
            if ( status_col >= 0 ) filters_options[status_col] = () => all_statuses;
341
342
            var items_table = $("#" + tab_id + '_table').kohaTable({
335
            var items_table = $("#" + tab_id + '_table').kohaTable({
343
                ajax: { url: item_table_url },
336
                ajax: { url: item_table_url },
344
                order: [],
337
                order: [],
Lines 391-396 Link Here
391
                {
384
                {
392
                    data: "me.item_type_id", // FIXME Cannot filter by biblioitem.itemtype
385
                    data: "me.item_type_id", // FIXME Cannot filter by biblioitem.itemtype
393
                    datatype: "coded_value:item_type",
386
                    datatype: "coded_value:item_type",
387
                    dataFilter: "item_types",
394
                    className: "itype",
388
                    className: "itype",
395
                    searchable: true,
389
                    searchable: true,
396
                    orderable: true,
390
                    orderable: true,
Lines 411-416 Link Here
411
                {
405
                {
412
                    data: "me.holding_library_id",
406
                    data: "me.holding_library_id",
413
                    datatype: "coded_value:library",
407
                    datatype: "coded_value:library",
408
                    dataFilter: "libraries",
414
                    className: "location",
409
                    className: "location",
415
                    searchable: true,
410
                    searchable: true,
416
                    orderable: true,
411
                    orderable: true,
Lines 421-426 Link Here
421
                {
416
                {
422
                    data: "me.home_library_id",
417
                    data: "me.home_library_id",
423
                    datatype: "coded_value:library",
418
                    datatype: "coded_value:library",
419
                    dataFilter: "libraries",
424
                    className: "homebranch",
420
                    className: "homebranch",
425
                    searchable: true,
421
                    searchable: true,
426
                    orderable: true,
422
                    orderable: true,
Lines 514-519 Link Here
514
                {
510
                {
515
                    data: "",
511
                    data: "",
516
                    className: "status",
512
                    className: "status",
513
                    dataFilter: "statuses",
517
                    searchable: false,
514
                    searchable: false,
518
                    orderable: false,
515
                    orderable: false,
519
                    render: function (data, type, row, meta) {
516
                    render: function (data, type, row, meta) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-33 / +38 lines)
Lines 175-183 Link Here
175
                        [% CASE 'address-library' %]
175
                        [% CASE 'address-library' %]
176
                            <th>Address</th>
176
                            <th>Address</th>
177
                        [% CASE 'branch' %]
177
                        [% CASE 'branch' %]
178
                            <th data-filter="libraries">Library</th>
178
                            <th>Library</th>
179
                        [% CASE 'category' %]
179
                        [% CASE 'category' %]
180
                            <th data-filter="categories">Category</th>
180
                            <th>Category</th>
181
                        [% CASE 'dateexpiry' %]
181
                        [% CASE 'dateexpiry' %]
182
                            <th>Expires on</th>
182
                            <th>Expires on</th>
183
                        [% CASE 'borrowernotes' %]
183
                        [% CASE 'borrowernotes' %]
Lines 189-205 Link Here
189
                        [% CASE 'account_balance' %]
189
                        [% CASE 'account_balance' %]
190
                            <th>Fines</th>
190
                            <th>Fines</th>
191
                        [% CASE 'sort1' %]
191
                        [% CASE 'sort1' %]
192
                            [% IF av_bsort1.size %]
192
                            <th>Sort 1</th>
193
                                <th data-filter="av_bsort1">Sort 1</th>
194
                            [% ELSE %]
195
                                <th>Sort 1</th>
196
                            [% END %]
197
                        [% CASE 'sort2' %]
193
                        [% CASE 'sort2' %]
198
                            [% IF av_bsort2.size %]
194
                            <th>Sort 2</th>
199
                                <th data-filter="av_bsort2">Sort 2</th>
200
                            [% ELSE %]
201
                                <th>Sort 2</th>
202
                            [% END %]
203
                        [% CASE 'action' %]
195
                        [% CASE 'action' %]
204
                            <th class="no-export">&nbsp;</th>
196
                            <th class="no-export">&nbsp;</th>
205
                        [% END %]
197
                        [% END %]
Lines 244-252 Link Here
244
        </script>
236
        </script>
245
    [% END %]
237
    [% END %]
246
    <script>
238
    <script>
247
        [% SET libraries = Branches.all %]
239
        var categories = [% To.json(Categories.all.unblessed) | $raw %].map(e => {
248
        [% SET categories = Categories.all.unblessed %]
249
        var categories = [% To.json(categories) | $raw %].map(e => {
250
            e['_id'] = e.categorycode.toLowerCase();
240
            e['_id'] = e.categorycode.toLowerCase();
251
            e['_str'] = e.description;
241
            e['_str'] = e.description;
252
            return e;
242
            return e;
Lines 255-261 Link Here
255
            map[e._id] = e;
245
            map[e._id] = e;
256
            return map;
246
            return map;
257
        }, {});
247
        }, {});
258
        var libraries  = [% To.json(libraries) | $raw %].map(e => {
248
        var libraries = [% To.json(Branches.all) | $raw %].map(e => {
259
            e['_id'] = e.branchcode;
249
            e['_id'] = e.branchcode;
260
            e['_str'] = e.branchname;
250
            e['_str'] = e.branchname;
261
            return e;
251
            return e;
Lines 285-290 Link Here
285
            return map;
275
            return map;
286
        }, {});
276
        }, {});
287
277
278
        let filters_options = {
279
            libraries,
280
            categories,
281
            av_bsort1,
282
            av_bsort2,
283
        };
284
288
        [% IF Koha.Preference('ExtendedPatronAttributes') %]
285
        [% IF Koha.Preference('ExtendedPatronAttributes') %]
289
            [% SET extended_attribute_types = ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) %]
286
            [% SET extended_attribute_types = ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) %]
290
            [% IF ( extended_attribute_types ) %][% extended_attribute_types = [ extended_attribute_types ]  %][% END %]
287
            [% IF ( extended_attribute_types ) %][% extended_attribute_types = [ extended_attribute_types ]  %][% END %]
Lines 627-636 Link Here
627
                                }
624
                                }
628
                                [% CASE 'branch' %]
625
                                [% CASE 'branch' %]
629
                                {
626
                                {
630
                                    "data": "library.name:me.library_id",
627
                                    data: "library.name:me.library_id",
631
                                    "searchable": true,
628
                                    dataFilter: "libraries",
632
                                    "orderable": true,
629
                                    searchable: true,
633
                                    "render": function( data, type, row, meta ) {
630
                                    orderable: true,
631
                                    render: function( data, type, row, meta ) {
634
                                        if( !singleBranchMode && row.library.library_id == logged_in_library_id ) {
632
                                        if( !singleBranchMode && row.library.library_id == logged_in_library_id ) {
635
                                            return "<span class=\"currentlibrary\">" + escape_str(row.library.name) + "</span>";
633
                                            return "<span class=\"currentlibrary\">" + escape_str(row.library.name) + "</span>";
636
                                        } else {
634
                                        } else {
Lines 640-649 Link Here
640
                                }
638
                                }
641
                                [% CASE 'category' %]
639
                                [% CASE 'category' %]
642
                                {
640
                                {
643
                                    "data": "category_id",
641
                                    data: "category_id",
644
                                    "searchable": true,
642
                                    dataFilter: "categories",
645
                                    "orderable": true,
643
                                    searchable: true,
646
                                    "render": function( data, type, row, meta ) {
644
                                    orderable: true,
645
                                    render: function( data, type, row, meta ) {
647
                                        return escape_str(categories_map[data.toLowerCase()].description);
646
                                        return escape_str(categories_map[data.toLowerCase()].description);
648
                                    }
647
                                    }
649
                                }
648
                                }
Lines 711-720 Link Here
711
710
712
                                [% CASE 'sort1' %]
711
                                [% CASE 'sort1' %]
713
                                {
712
                                {
714
                                    "data": "statistics_1",
713
                                    data: "statistics_1",
715
                                    "searchable": true,
714
                                    [% IF av_bsort1.size %]
716
                                    "orderable": true,
715
                                        dataFilter: "av_bsort1",
717
                                    "render": function( data, type, row, meta ) {
716
                                    [% END %]
717
                                    searchable: true,
718
                                    orderable: true,
719
                                    render: function( data, type, row, meta ) {
718
                                        if (data === null) return '';
720
                                        if (data === null) return '';
719
                                        let bsort1 = av_bsort1_map[data.toString()];
721
                                        let bsort1 = av_bsort1_map[data.toString()];
720
                                        return escape_str(bsort1 ? bsort1.lib : data);
722
                                        return escape_str(bsort1 ? bsort1.lib : data);
Lines 723-732 Link Here
723
725
724
                                [% CASE 'sort2' %]
726
                                [% CASE 'sort2' %]
725
                                {
727
                                {
726
                                    "data": "statistics_2",
728
                                    data: "statistics_2",
727
                                    "searchable": true,
729
                                    [% IF av_bsort2.size %]
728
                                    "orderable": true,
730
                                        dataFilter: "av_bsort2",
729
                                    "render": function( data, type, row, meta ) {
731
                                    [% END %]
732
                                    searchable: true,
733
                                    orderable: true,
734
                                    render: function( data, type, row, meta ) {
730
                                        if (data === null) return '';
735
                                        if (data === null) return '';
731
                                        let bsort2 = av_bsort2_map[data.toString()];
736
                                        let bsort2 = av_bsort2_map[data.toString()];
732
                                        return escape_str(bsort2 ? bsort2.lib : data);
737
                                        return escape_str(bsort2 ? bsort2.lib : data);
Lines 783-789 Link Here
783
                        },
788
                        },
784
                    [% END %]
789
                    [% END %]
785
                    fixedHeader: false,
790
                    fixedHeader: false,
786
                }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters, undefined, external_filter_nodes, parent_block.find(".search_description"), additional_search_descriptions );
791
                }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters, filters_options, external_filter_nodes, parent_block.find(".search_description"), additional_search_descriptions );
787
792
788
                patron_search_form.on('submit', filter);
793
                patron_search_form.on('submit', filter);
789
                patron_search_form.on('submit', update_search_type);
794
                patron_search_form.on('submit', update_search_type);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt (-18 / +17 lines)
Lines 656-670 Link Here
656
            } );
656
            } );
657
657
658
            let filters_options = {
658
            let filters_options = {
659
                4: () => all_ccodes,
659
                collection_codes: all_ccodes,
660
                9: () => all_libraries,
660
                libraries: all_libraries,
661
                10: () => all_libraries,
661
                locations: all_locations,
662
                11: () => all_locations,
662
                item_types: all_item_types,
663
                12: () => all_item_types,
663
                av_notforloan: all_notforloans,
664
                14: () => all_notforloans,
664
                av_lost: all_losts,
665
                15: () => all_losts,
665
                av_withdrawn: all_withdrawns,
666
                16: () => all_withdrawns,
666
                av_damaged: all_damageds,
667
                17: () => all_damageds,
668
            };
667
            };
669
668
670
            var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %];
669
            var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %];
Lines 696-715 Link Here
696
                    { 'name': 'title' },
695
                    { 'name': 'title' },
697
                    { 'name': 'publicationyear' },
696
                    { 'name': 'publicationyear' },
698
                    { 'name': 'publishercode' },
697
                    { 'name': 'publishercode' },
699
                    { 'name': 'ccode' },
698
                    { 'name': 'ccode', dataFilter: 'collection_codes' },
700
                    { 'name': 'barcode' },
699
                    { 'name': 'barcode' },
701
                    { 'name': 'itemnumber' },
700
                    { 'name': 'itemnumber' },
702
                    { 'name': 'enumchron' },
701
                    { 'name': 'enumchron' },
703
                    { 'name': 'itemcallnumber' },
702
                    { 'name': 'itemcallnumber' },
704
                    { 'name': 'homebranch' },
703
                    { 'name': 'homebranch', dataFilter: 'libraries' },
705
                    { 'name': 'holdingbranch' },
704
                    { 'name': 'holdingbranch', dataFilter: 'libraries' },
706
                    { 'name': 'location' },
705
                    { 'name': 'location', dataFilter: 'locations' },
707
                    { 'name': 'itype'},
706
                    { 'name': 'itype', dataFilter: 'item_types' },
708
                    { 'name': 'stocknumber' },
707
                    { 'name': 'stocknumber' },
709
                    { 'name': 'notforloan' },
708
                    { 'name': 'notforloan', dataFilter: 'av_notforloan' },
710
                    { 'name': 'itemlost' },
709
                    { 'name': 'itemlost', dataFilter: 'av_lost' },
711
                    { 'name': 'withdrawn' },
710
                    { 'name': 'withdrawn', dataFilter: 'av_widthdrawn' },
712
                    { 'name': 'damaged' },
711
                    { 'name': 'damaged', dataFilter: 'av_damaged' },
713
                    { 'name': 'dateaccessioned' },
712
                    { 'name': 'dateaccessioned' },
714
                    { 'name': 'issues' },
713
                    { 'name': 'issues' },
715
                    { 'name': 'datelastborrowed' },
714
                    { 'name': 'datelastborrowed' },
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingbookings.tt (-3 / +2 lines)
Lines 154-167 Link Here
154
                }
154
                }
155
            };
155
            };
156
156
157
            [% SET libraries = Branches.all %]
157
            let all_libraries  = [% To.json(Branches.all) | $raw %].map(e => {
158
            let all_libraries  = [% To.json(libraries) | $raw %].map(e => {
159
                e['_id'] = e.branchcode;
158
                e['_id'] = e.branchcode;
160
                e['_str'] = e.branchname;
159
                e['_str'] = e.branchname;
161
                return e;
160
                return e;
162
            });
161
            });
163
            let filters_options = {
162
            let filters_options = {
164
                [1] : () => all_libraries,
163
                libraries: all_libraries,
165
            };
164
            };
166
165
167
            var bookings_table_url = '/api/v1/bookings?';
166
            var bookings_table_url = '/api/v1/bookings?';
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt (-4 / +23 lines)
Lines 316-325 Link Here
316
316
317
        $(document).ready(function() {
317
        $(document).ready(function() {
318
            let filters_options = {
318
            let filters_options = {
319
                [5] : (table_dt) => get_options(table_dt.column(5)),
319
                libraries: (table_dt) => get_options(table_dt.column(5)),
320
                [10] : (table_dt) => get_options(table_dt.column(10)),
320
                item_types: (table_dt) => get_options(table_dt.column(10)),
321
                [11] : (table_dt) => get_options(table_dt.column(11)),
321
                locations: (table_dt) => get_options(table_dt.column(11)),
322
                [15] : (table_dt) => get_options(table_dt.column(15)),
322
                pickup_locations : (table_dt) => get_options(table_dt.column(15)),
323
            };
323
            };
324
324
325
325
Lines 327-332 Link Here
327
            var holdst = $("#holdst").kohaTable(
327
            var holdst = $("#holdst").kohaTable(
328
                {
328
                {
329
                    pagingType: "full_numbers",
329
                    pagingType: "full_numbers",
330
                    columns: [
331
                        {name: "pull_items" },
332
                        {name: "available_items" },
333
                        {name: "patrons" },
334
                        {name: "patron" },
335
                        {name: "title" },
336
                        {name: "libraries", dataFilter: "libraries" },
337
                        {name: "barcodes" },
338
                        {name: "call_numbers" },
339
                        {name: "copy_numbers" },
340
                        {name: "enumeration" },
341
                        {name: "itemtypes", dataFilter: "item_types" },
342
                        {name: "locations", dataFilter: "locations" },
343
                        {name: "collection" },
344
                        {name: "hold_date" },
345
                        {name: "reserve_nodes" },
346
                        {name: "pickup_location", dataFilter: "pickup_locations" },
347
                        {name: "action" },
348
                    ],
330
                },
349
                },
331
                table_settings,
350
                table_settings,
332
                true,
351
                true,
(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-10 / +8 lines)
Lines 1049-1077 function _dt_add_filters(table_node, table_dt, filters_options = {}) { Link Here
1049
        let th = $(table_node).find(
1049
        let th = $(table_node).find(
1050
            "thead tr:eq(1) th:eq(%s)".format(visible_i)
1050
            "thead tr:eq(1) th:eq(%s)".format(visible_i)
1051
        );
1051
        );
1052
        var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable;
1052
        let col = table_dt.settings()[0].aoColumns[i];
1053
        var is_searchable = col.bSearchable;
1053
        $(this)
1054
        $(this)
1054
            .removeClass("sorting")
1055
            .removeClass("sorting")
1055
            .removeClass("sorting_asc")
1056
            .removeClass("sorting_asc")
1056
            .removeClass("sorting_desc");
1057
            .removeClass("sorting_desc");
1057
        $(this).data("th-id", i);
1058
        $(this).data("th-id", i);
1058
        if (is_searchable || $(this).data("filter") || filters_options[i]) {
1059
        if (is_searchable || col.dataFilter) {
1059
            let input_type = "input";
1060
            let input_type = "input";
1060
            let existing_search = column.search();
1061
            let existing_search = column.search();
1061
            if ($(th).data("filter") || filters_options.hasOwnProperty(i)) {
1062
            if (col.dataFilter) {
1062
                input_type = "select";
1063
                input_type = "select";
1063
                let filter_type = $(th).data("filter");
1064
                let filter_type = $(th).data("filter");
1064
                let select = $(
1065
                let select = $(
1065
                    '<select class="dt-select-filter"><option value=""></option></select'
1066
                    '<select class="dt-select-filter"><option value=""></option></select'
1066
                );
1067
                );
1067
1068
1068
                // FIXME eval here is bad and dangerous, how do we workaround that?
1069
                if (typeof filters_options[col.dataFilter] === "function") {
1069
                if (!filters_options.hasOwnProperty(i)) {
1070
                    filters_options[col.dataFilter] =
1070
                    filters_options[i] = eval(filter_type);
1071
                        filters_options[col.dataFilter](table_dt);
1071
                } else if (typeof filters_options[i] === "function") {
1072
                    filters_options[i] = filters_options[i](table_dt);
1073
                }
1072
                }
1074
                $(filters_options[i])
1073
                $(filters_options[col.dataFilter])
1075
                    .filter(function () {
1074
                    .filter(function () {
1076
                        return this._id !== "" && this._str !== "";
1075
                        return this._id !== "" && this._str !== "";
1077
                    })
1076
                    })
1078
- 

Return to bug 38311