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

(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js (-1 / +2 lines)
Lines 316-321 $(document).ready(function () { Link Here
316
                },
316
                },
317
                {
317
                {
318
                    data: "ill_batch.name", // batch
318
                    data: "ill_batch.name", // batch
319
                    searchable: true,
319
                    orderable: false,
320
                    orderable: false,
320
                    render: function (data, type, row, meta) {
321
                    render: function (data, type, row, meta) {
321
                        return row.ill_batch
322
                        return row.ill_batch
Lines 537-543 $(document).ready(function () { Link Here
537
            ],
538
            ],
538
        },
539
        },
539
        table_settings,
540
        table_settings,
540
        null,
541
        1,
541
        additional_filters,
542
        additional_filters,
542
        undefined,
543
        undefined,
543
        external_filter_nodes
544
        external_filter_nodes
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt (-1 / +4 lines)
Lines 442-447 Link Here
442
                },
442
                },
443
                {
443
                {
444
                    data: 'author',
444
                    data: 'author',
445
                    searchable: false,
445
                    sortable: false,
446
                    sortable: false,
446
                    render: (data, type, row, meta) => {
447
                    render: (data, type, row, meta) => {
447
                        return display_extended_attribute(row, 'author');
448
                        return display_extended_attribute(row, 'author');
Lines 449-454 Link Here
449
                },
450
                },
450
                {
451
                {
451
                    data: 'title',
452
                    data: 'title',
453
                    searchable: false,
452
                    sortable: false,
454
                    sortable: false,
453
                    render: (data, type, row, meta) => {
455
                    render: (data, type, row, meta) => {
454
                        return display_extended_attribute(row, 'title');
456
                        return display_extended_attribute(row, 'title');
Lines 460-465 Link Here
460
                },
462
                },
461
                {
463
                {
462
                    data: 'type',
464
                    data: 'type',
465
                    searchable: false,
463
                    sortable: false,
466
                    sortable: false,
464
                    render: (data, type, row, meta) => {
467
                    render: (data, type, row, meta) => {
465
                        return display_extended_attribute(row, 'type');
468
                        return display_extended_attribute(row, 'type');
Lines 494-500 Link Here
494
                    },
497
                    },
495
                }
498
                }
496
            ]
499
            ]
497
        });
500
        }, undefined, 1, undefined, undefined);
498
        $("#backend-dropdown-options").removeClass("nojs");
501
        $("#backend-dropdown-options").removeClass("nojs");
499
        [% IF services_json.length > 0 %]
502
        [% IF services_json.length > 0 %]
500
            var services = [% services_json | $raw %];
503
            var services = [% services_json | $raw %];
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js (-2 / +131 lines)
Lines 587-593 function _dt_visibility(table_settings, table_dt) { Link Here
587
        options = {},
587
        options = {},
588
        table_settings = undefined,
588
        table_settings = undefined,
589
        add_filters,
589
        add_filters,
590
        default_filters
590
        default_filters,
591
        filters_options
591
    ) {
592
    ) {
592
        // Early return if the node does not exist
593
        // Early return if the node does not exist
593
        if (!this.length) return;
594
        if (!this.length) return;
Lines 666-671 function _dt_visibility(table_settings, table_dt) { Link Here
666
667
667
        var table_dt = table.DataTable();
668
        var table_dt = table.DataTable();
668
669
670
        if (add_filters) {
671
            _dt_add_filters(this, table_dt, filters_options);
672
        }
673
674
        table_dt.on("column-visibility.dt", function () {
675
            if (add_filters) {
676
                _dt_add_filters(this, table_dt, filters_options);
677
            }
678
        });
679
669
        table_dt.on("search.dt", function (e, settings) {
680
        table_dt.on("search.dt", function (e, settings) {
670
            // When the DataTables search function is triggered,
681
            // When the DataTables search function is triggered,
671
            // enable or disable the "Clear filter" button based on
682
            // enable or disable the "Clear filter" button based on
Lines 688-691 function _dt_visibility(table_settings, table_dt) { Link Here
688
699
689
        return table;
700
        return table;
690
    };
701
    };
702
703
    function _dt_add_filters(table_node, table_dt, filters_options = {}) {
704
        if (!$(table_node).length) return;
705
706
        $(table_node).find("thead tr:eq(1)").remove(); // Remove if one exists already
707
        $(table_node)
708
            .find("thead tr")
709
            .clone()
710
            .appendTo($(table_node).find("thead"));
711
712
        let visibility = table_dt.columns().visible();
713
        let columns = table_dt.settings()[0].aoColumns;
714
        table_dt.columns().every(function () {
715
            var column = this;
716
            let i = column.index();
717
            var visible_i = table_dt.column.index("fromData", i);
718
            let th = $(table_node).find(
719
                "thead tr:eq(1) th:eq(%s)".format(visible_i)
720
            );
721
            var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable;
722
            $(this)
723
                .removeClass("sorting")
724
                .removeClass("sorting_asc")
725
                .removeClass("sorting_desc");
726
            $(this).data("th-id", i);
727
            if (is_searchable || $(this).data("filter") || filters_options[i]) {
728
                let input_type = "input";
729
                let existing_search = column.search();
730
                if ($(th).data("filter") || filters_options.hasOwnProperty(i)) {
731
                    input_type = "select";
732
                    let filter_type = $(th).data("filter");
733
                    let select = $(
734
                        '<select class="dt-select-filter"><option value=""></option></select'
735
                    );
736
737
                    // FIXME eval here is bad and dangerous, how do we workaround that?
738
                    if (!filters_options.hasOwnProperty(i)) {
739
                        filters_options[i] = eval(filter_type);
740
                    } else if (typeof filters_options[i] === "function") {
741
                        filters_options[i] = filters_options[i](table_dt);
742
                    }
743
                    $(filters_options[i]).each(function () {
744
                        let o = $(
745
                            '<option value="^%s$">%s</option>'.format(
746
                                this._id,
747
                                this._str
748
                            )
749
                        );
750
                        // Compare with lc, or selfreg won't match ^SELFREG$ for instance, see bug 32517
751
                        // This is only for category, we might want to apply it only in this case.
752
                        existing_search = existing_search.toLowerCase();
753
                        if (
754
                            existing_search === this._id ||
755
                            (existing_search &&
756
                                this._id.toLowerCase().match(existing_search))
757
                        ) {
758
                            o.prop("selected", "selected");
759
                        }
760
                        o.appendTo(select);
761
                    });
762
                    $(th).html(select);
763
                } else {
764
                    var title = $(th).text();
765
                    if (existing_search) {
766
                        $(th).html(
767
                            '<input type="text" value="%s" style="width: 100%" />'.format(
768
                                existing_search
769
                            )
770
                        );
771
                    } else {
772
                        var search_title = __("%s search").format(title);
773
                        $(th).html(
774
                            '<input type="text" placeholder="%s" style="width: 100%" />'.format(
775
                                search_title
776
                            )
777
                        );
778
                    }
779
                }
780
            } else {
781
                $(th).html("");
782
            }
783
        });
784
        _dt_add_delay_filters(table_dt, table_node);
785
        table_dt.fixedHeader?.adjust();
786
    }
787
788
    function _dt_add_delay_filters(table_dt, table_node) {
789
        let delay_ms = 500;
790
791
        let col_input_search = DataTable.util.debounce(function (i, val) {
792
            table_dt.column(i).search(val).draw();
793
        }, delay_ms);
794
        let col_select_search = DataTable.util.debounce(function (i, val) {
795
            table_dt.column(i).search(val, true, false).draw();
796
        }, delay_ms);
797
798
        $(table_node)
799
            .find("thead tr:eq(1) th")
800
            .each(function (visible_i) {
801
                var i = table_dt.column.index("fromVisible", visible_i);
802
                $(this)
803
                    .find("input")
804
                    .unbind()
805
                    .bind("keyup change", function (e) {
806
                        if (e.keyCode === undefined) return;
807
                        col_input_search(i, this.value);
808
                    });
809
810
                $(this)
811
                    .find("select")
812
                    .unbind()
813
                    .bind("keyup change", function () {
814
                        let value = this.value.length
815
                            ? "^" + this.value + "$"
816
                            : "";
817
                        col_select_search(i, this.value);
818
                    });
819
            });
820
    }
691
})(jQuery);
821
})(jQuery);
692
- 

Return to bug 40013