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 241-246 Link Here
241
            collection_code: new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.ccode' })) | $raw %].map( av => [av.lib, av.authorised_value])),
239
            collection_code: new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.ccode' })) | $raw %].map( av => [av.lib, av.authorised_value])),
242
        };
240
        };
243
241
242
        let filters_options = {
243
            item_types: all_item_types,
244
            libraries: all_libraries,
245
            libraries: all_libraries,
246
            statuses: all_statuses,
247
        };
248
244
        [% IF Koha.Preference('URLLinkText') %]
249
        [% IF Koha.Preference('URLLinkText') %]
245
            const url_link_text = "[% Koha.Preference('URLLinkText') | html %]";
250
            const url_link_text = "[% Koha.Preference('URLLinkText') | html %]";
246
        [% ELSE %]
251
        [% ELSE %]
Lines 326-343 Link Here
326
                return $("#" + tab_id + "_status select").val();
331
                return $("#" + tab_id + "_status select").val();
327
            };
332
            };
328
333
329
            let filters_options = {};
330
331
            let itype_col = $("#" + tab_id + "_table thead th[data-colname='itype']").index();
332
            let holdingbranch_col = $("#" + tab_id + "_table thead th[data-colname='holdingbranch']").index();
333
            let homebranch_col = $("#" + tab_id + "_table thead th[data-colname='homebranch']").index();
334
            let status_col = $("#" + tab_id + "_table thead th[data-colname='status']").index();
335
336
            if ( itype_col >= 0 ) filters_options[itype_col] = () => all_item_types;
337
            if ( holdingbranch_col >= 0 ) filters_options[holdingbranch_col] = () => all_libraries;
338
            if ( homebranch_col >= 0 ) filters_options[homebranch_col] = () => all_libraries;
339
            if ( status_col >= 0 ) filters_options[status_col] = () => all_statuses;
340
341
            var items_table = $("#" + tab_id + '_table').kohaTable({
334
            var items_table = $("#" + tab_id + '_table').kohaTable({
342
                ajax: { url: item_table_url },
335
                ajax: { url: item_table_url },
343
                order: [],
336
                order: [],
Lines 390-395 Link Here
390
                {
383
                {
391
                    data: "me.item_type_id", // FIXME Cannot filter by biblioitem.itemtype
384
                    data: "me.item_type_id", // FIXME Cannot filter by biblioitem.itemtype
392
                    datatype: "coded_value:item_type",
385
                    datatype: "coded_value:item_type",
386
                    dataFilter: "item_types",
393
                    className: "itype",
387
                    className: "itype",
394
                    searchable: true,
388
                    searchable: true,
395
                    orderable: true,
389
                    orderable: true,
Lines 410-415 Link Here
410
                {
404
                {
411
                    data: "me.holding_library_id",
405
                    data: "me.holding_library_id",
412
                    datatype: "coded_value:library",
406
                    datatype: "coded_value:library",
407
                    dataFilter: "libraries",
413
                    className: "location",
408
                    className: "location",
414
                    searchable: true,
409
                    searchable: true,
415
                    orderable: true,
410
                    orderable: true,
Lines 420-425 Link Here
420
                {
415
                {
421
                    data: "me.home_library_id",
416
                    data: "me.home_library_id",
422
                    datatype: "coded_value:library",
417
                    datatype: "coded_value:library",
418
                    dataFilter: "libraries",
423
                    className: "homebranch",
419
                    className: "homebranch",
424
                    searchable: true,
420
                    searchable: true,
425
                    orderable: true,
421
                    orderable: true,
Lines 510-515 Link Here
510
                {
506
                {
511
                    data: "",
507
                    data: "",
512
                    className: "status",
508
                    className: "status",
509
                    dataFilter: "statuses",
513
                    searchable: false,
510
                    searchable: false,
514
                    orderable: false,
511
                    orderable: false,
515
                    render: function (data, type, row, meta) {
512
                    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 652-666 Link Here
652
            } );
652
            } );
653
653
654
            let filters_options = {
654
            let filters_options = {
655
                4: () => all_ccodes,
655
                collection_codes: all_ccodes,
656
                9: () => all_libraries,
656
                libraries: all_libraries,
657
                10: () => all_libraries,
657
                locations: all_locations,
658
                11: () => all_locations,
658
                item_types: all_item_types,
659
                12: () => all_item_types,
659
                av_notforloan: all_notforloans,
660
                14: () => all_notforloans,
660
                av_lost: all_losts,
661
                15: () => all_losts,
661
                av_withdrawn: all_withdrawns,
662
                16: () => all_withdrawns,
662
                av_damaged: all_damageds,
663
                17: () => all_damageds,
664
            };
663
            };
665
664
666
            var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %];
665
            var table_settings = [% TablesSettings.GetTableSettings( 'catalogue', 'itemsearch', 'results', 'json' ) | $raw %];
Lines 692-711 Link Here
692
                    { 'name': 'title' },
691
                    { 'name': 'title' },
693
                    { 'name': 'publicationyear' },
692
                    { 'name': 'publicationyear' },
694
                    { 'name': 'publishercode' },
693
                    { 'name': 'publishercode' },
695
                    { 'name': 'ccode' },
694
                    { 'name': 'ccode', dataFilter: 'collection_codes' },
696
                    { 'name': 'barcode' },
695
                    { 'name': 'barcode' },
697
                    { 'name': 'itemnumber' },
696
                    { 'name': 'itemnumber' },
698
                    { 'name': 'enumchron' },
697
                    { 'name': 'enumchron' },
699
                    { 'name': 'itemcallnumber' },
698
                    { 'name': 'itemcallnumber' },
700
                    { 'name': 'homebranch' },
699
                    { 'name': 'homebranch', dataFilter: 'libraries' },
701
                    { 'name': 'holdingbranch' },
700
                    { 'name': 'holdingbranch', dataFilter: 'libraries' },
702
                    { 'name': 'location' },
701
                    { 'name': 'location', dataFilter: 'locations' },
703
                    { 'name': 'itype'},
702
                    { 'name': 'itype', dataFilter: 'item_types' },
704
                    { 'name': 'stocknumber' },
703
                    { 'name': 'stocknumber' },
705
                    { 'name': 'notforloan' },
704
                    { 'name': 'notforloan', dataFilter: 'av_notforloan' },
706
                    { 'name': 'itemlost' },
705
                    { 'name': 'itemlost', dataFilter: 'av_lost' },
707
                    { 'name': 'withdrawn' },
706
                    { 'name': 'withdrawn', dataFilter: 'av_widthdrawn' },
708
                    { 'name': 'damaged' },
707
                    { 'name': 'damaged', dataFilter: 'av_damaged' },
709
                    { 'name': 'dateaccessioned' },
708
                    { 'name': 'dateaccessioned' },
710
                    { 'name': 'issues' },
709
                    { 'name': 'issues' },
711
                    { 'name': 'datelastborrowed' },
710
                    { '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 1009-1037 function _dt_add_filters(table_node, table_dt, filters_options = {}) { Link Here
1009
        let th = $(table_node).find(
1009
        let th = $(table_node).find(
1010
            "thead tr:eq(1) th:eq(%s)".format(visible_i)
1010
            "thead tr:eq(1) th:eq(%s)".format(visible_i)
1011
        );
1011
        );
1012
        var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable;
1012
        let col = table_dt.settings()[0].aoColumns[i];
1013
        var is_searchable = col.bSearchable;
1013
        $(this)
1014
        $(this)
1014
            .removeClass("sorting")
1015
            .removeClass("sorting")
1015
            .removeClass("sorting_asc")
1016
            .removeClass("sorting_asc")
1016
            .removeClass("sorting_desc");
1017
            .removeClass("sorting_desc");
1017
        $(this).data("th-id", i);
1018
        $(this).data("th-id", i);
1018
        if (is_searchable || $(this).data("filter") || filters_options[i]) {
1019
        if (is_searchable || col.dataFilter) {
1019
            let input_type = "input";
1020
            let input_type = "input";
1020
            let existing_search = column.search();
1021
            let existing_search = column.search();
1021
            if ($(th).data("filter") || filters_options.hasOwnProperty(i)) {
1022
            if (col.dataFilter) {
1022
                input_type = "select";
1023
                input_type = "select";
1023
                let filter_type = $(th).data("filter");
1024
                let filter_type = $(th).data("filter");
1024
                let select = $(
1025
                let select = $(
1025
                    '<select class="dt-select-filter"><option value=""></option></select'
1026
                    '<select class="dt-select-filter"><option value=""></option></select'
1026
                );
1027
                );
1027
1028
1028
                // FIXME eval here is bad and dangerous, how do we workaround that?
1029
                if (typeof filters_options[col.dataFilter] === "function") {
1029
                if (!filters_options.hasOwnProperty(i)) {
1030
                    filters_options[col.dataFilter] =
1030
                    filters_options[i] = eval(filter_type);
1031
                        filters_options[col.dataFilter](table_dt);
1031
                } else if (typeof filters_options[i] === "function") {
1032
                    filters_options[i] = filters_options[i](table_dt);
1033
                }
1032
                }
1034
                $(filters_options[i])
1033
                $(filters_options[col.dataFilter])
1035
                    .filter(function () {
1034
                    .filter(function () {
1036
                        return this._id !== "" && this._str !== "";
1035
                        return this._id !== "" && this._str !== "";
1037
                    })
1036
                    })
1038
- 

Return to bug 38311