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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-57 / +48 lines)
Lines 150-156 Link Here
150
        [% END %]
150
        [% END %]
151
    </div>
151
    </div>
152
152
153
    <h3 style="display: none;">Patrons found for: <span class="searchpattern"></span></h3>
153
    <h3 style="display: none;" class="search_description" data-prefix="[% I18N.t("Patrons found for: %s") %]"></h3>
154
154
155
    <div id="[% table_id | html %]_search_results" style="display:none;">
155
    <div id="[% table_id | html %]_search_results" style="display:none;">
156
156
Lines 418-423 Link Here
418
                };
418
                };
419
            [% END %]
419
            [% END %]
420
420
421
            let additional_search_descriptions = {};
422
            [% IF display_search_description %]
423
                additional_search_descriptions = {
424
                    main: function(){
425
                        let parent_block = $("#[% search_results_block_id | html %]");
426
                        let patron_search_form = get_patron_search_form();
427
                        let searched = "";
428
                        let pattern = patron_search_form.find(".search_patron_filter").val();
429
                        if ( pattern ) {
430
                            let field = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
431
                            if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
432
                                searched += _("%s starting with '%s'".format(field, pattern));
433
                            } else {
434
                                searched += _("%s containing '%s'".format(field, pattern));
435
                            }
436
                        }
437
438
                        if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
439
                            searched += _(" with sort1 ")
440
                            if ( patron_search_form.find("select[name='sort1_filter']") ) {
441
                                searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
442
                            }
443
                            else {
444
                                searched += paron_search_form.find("select[name='sort1_filter']").val();
445
                            }
446
                        }
447
                        if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
448
                            searched += _(" with sort2 ")
449
                            if ( patron_search_form.find("select[name='sort2_filter']") ) {
450
                                searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
451
                            }
452
                            else {
453
                                searched += paron_search_form.find("select[name='sort2_filter']").val();
454
                            }
455
                        }
456
                        return searched;
457
                    },
458
                    surname: function(){
459
                        let parent_block = $("#[% search_results_block_id | html %]");
460
                        let start_with = parent_block.find(".firstletter_filter").val()
461
                        if (!start_with) return "";
462
                        return _("Surname begins with '%s'".format(start_with));
463
                    },
464
                };
465
            [% END %]
466
421
            [% UNLESS default_sort_column %]
467
            [% UNLESS default_sort_column %]
422
                [% default_sort_column = "name" %]
468
                [% default_sort_column = "name" %]
423
            [% END %]
469
            [% END %]
Lines 730-736 Link Here
730
                    },
776
                    },
731
                [% END %]
777
                [% END %]
732
                fixedHeader: false,
778
                fixedHeader: false,
733
            }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters, undefined, external_filter_nodes);
779
            }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters, undefined, external_filter_nodes, parent_block.find(".search_description"), additional_search_descriptions );
734
780
735
            patron_search_form.on('submit', filter);
781
            patron_search_form.on('submit', filter);
736
            patron_search_form.on('submit', update_search_type);
782
            patron_search_form.on('submit', update_search_type);
Lines 776-782 Link Here
776
            patron_search_form.find(".clear_search").on("click",function(e){
822
            patron_search_form.find(".clear_search").on("click",function(e){
777
                e.preventDefault();
823
                e.preventDefault();
778
                clearFilters();
824
                clearFilters();
779
                parent_block.find(".searchpattern").parent().hide();
780
            });
825
            });
781
826
782
            let loaded_from_state = patrons_table.data('loaded_from_state');
827
            let loaded_from_state = patrons_table.data('loaded_from_state');
Lines 809-859 Link Here
809
            $("#searchtype").val($("#searchtype_filter").val());
854
            $("#searchtype").val($("#searchtype_filter").val());
810
        }
855
        }
811
856
812
        function update_search_description(){
813
            let parent_block = $("#[% search_results_block_id | html %]");
814
            let patron_search_form = get_patron_search_form();
815
            var searched = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
816
            let pattern = patron_search_form.find(".search_patron_filter").val();
817
            if ( pattern ) {
818
                if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
819
                    searched += _(" starting with ");
820
                } else {
821
                    searched += _(" containing ");
822
                }
823
                searched += "'" + pattern + "'";
824
            }
825
            let firstletter_filter = parent_block.find(".firstletter_filter").val();
826
            if ( firstletter_filter ) {
827
                searched += _(" begins with ") + "'" + firstletter_filter +"'";
828
            }
829
830
            if ( patron_search_form.find(".categorycode_filter").val() ) {
831
                searched += _(" with category ") + "'" + patron_search_form.find(".categorycode_filter option:selected").text() + "'";
832
            }
833
            if ( patron_search_form.find(".branchcode_filter").val() ) {
834
                searched += _(" in library ") + patron_search_form.find(".branchcode_filter option:selected").text();
835
            }
836
            if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
837
                searched += _(" with sort1 ")
838
                if ( patron_search_form.find("select[name='sort1_filter']") ) {
839
                    searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
840
                }
841
                else {
842
                    searched += paron_search_form.find("select[name='sort1_filter']").val();
843
                }
844
            }
845
            if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
846
                searched += _(" with sort2 ")
847
                if ( patron_search_form.find("select[name='sort2_filter']") ) {
848
                    searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
849
                }
850
                else {
851
                    searched += paron_search_form.find("select[name='sort2_filter']").val();
852
                }
853
            }
854
            parent_block.find(".searchpattern").text(searched).parent().show();
855
        }
856
857
        function filter() {
857
        function filter() {
858
            let parent_block = $("#[% search_results_block_id | html %]");
858
            let parent_block = $("#[% search_results_block_id | html %]");
859
            let patron_search_form = get_patron_search_form();
859
            let patron_search_form = get_patron_search_form();
Lines 902-910 Link Here
902
            patrons_table.data('loaded_from_state', false);
902
            patrons_table.data('loaded_from_state', false);
903
            first_draw = 1; // Only redirect if we are coming from here
903
            first_draw = 1; // Only redirect if we are coming from here
904
            table_dt.draw();
904
            table_dt.draw();
905
            [% IF display_search_description %]
906
                update_search_description();
907
            [% END %]
908
            return false;
905
            return false;
909
        }
906
        }
910
907
Lines 924-932 Link Here
924
                history.pushState( {}, null, window.location.href.split("?" )[0]);
921
                history.pushState( {}, null, window.location.href.split("?" )[0]);
925
            [% END %]
922
            [% END %]
926
            $("#[% table_id | html %]_search_results").hide();
923
            $("#[% table_id | html %]_search_results").hide();
927
            [% IF display_search_description %]
928
                update_search_description();
929
            [% END %]
930
        }
924
        }
931
925
932
        // User has clicked on a letter
926
        // User has clicked on a letter
Lines 943-951 Link Here
943
            [% END %]
937
            [% END %]
944
938
945
            patrons_table.DataTable().draw();
939
            patrons_table.DataTable().draw();
946
            [% IF display_search_description %]
947
                update_search_description();
948
            [% END %]
949
        }
940
        }
950
941
951
        // modify parent window owner element
942
        // modify parent window owner element
(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-2 / +58 lines)
Lines 1032-1037 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1032
    };
1032
    };
1033
}
1033
}
1034
1034
1035
function update_search_description(table_node, table_dt, additional_search_descriptions) {
1036
    let description_node = additional_search_descriptions.node;
1037
    let description_fns  = additional_search_descriptions.additional_search_descriptions;
1038
    let description = [];
1039
    let global_search = table_dt.search()
1040
    if ( global_search.length ) {
1041
        description.push(__("Anywhere: %s").format(global_search));
1042
    }
1043
    let additional_searches = [];
1044
    for ( f in description_fns ) {
1045
        let d = description_fns[f]();
1046
        if (d.length){
1047
            additional_searches.push(d);
1048
        }
1049
    }
1050
    if (additional_searches.length){
1051
        description.push(additional_searches.join(", "));
1052
    }
1053
    let column_searches = [];
1054
    table_dt.columns().search().each((search, i) => {
1055
        if( search.length ) {
1056
            // Retrieve the value from the dropdown list if there is one
1057
            var visible_i = table_dt.column.index('fromData', i);
1058
            let option = $(table_node).find('thead tr:eq(1) th:eq(%s) select option:selected'.format(visible_i));
1059
            if ( option.length ) {
1060
                search = $(option).text();
1061
            }
1062
1063
            column_searches.push("%s=%s".format(table_dt.column(i).header().innerHTML, search));
1064
        }
1065
    });
1066
    if(column_searches.length){
1067
        description.push(column_searches.join(", "));
1068
    }
1069
1070
    if ( description.length ) {
1071
        let display = description.length ? "block" : "none";
1072
        let description_str = $(description_node).data('prefix').format(description.join("<br/>"));
1073
        $(description_node).html(description_str).show();
1074
    } else {
1075
        $(description_node).html("").hide();
1076
    }
1077
}
1078
1035
(function($) {
1079
(function($) {
1036
1080
1037
    /**
1081
    /**
Lines 1047-1055 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1047
    *                                                available from the columns_settings template toolkit include
1091
    *                                                available from the columns_settings template toolkit include
1048
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
1092
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
1049
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1093
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1094
    * @param  {Object}  filters_options              Build selects for the filters row, and pass their value.
1095
    *                                                eg. { 1 => vendors } will build a select with the vendor list in the second column
1096
    * @param  {Object}  show_search_descriptions     Whether or not display the search descriptions when the table is drawn
1097
    *                                                Expect a node in which to place the descriptions. It must have a data-prefix attribute to build the description properly.
1098
    * @param  {Object}  aditional_search_descriptions Pass additional descriptions
1099
    *                                                 eg. { surname => () => { 'Surname with '.format($("#surname_form").val()) } }
1050
    * @return {Object}                               The dataTables instance
1100
    * @return {Object}                               The dataTables instance
1051
    */
1101
    */
1052
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes) {
1102
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes, show_search_descriptions, additional_search_descriptions) {
1053
        var settings = null;
1103
        var settings = null;
1054
1104
1055
        if(options) {
1105
        if(options) {
Lines 1114-1119 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1114
            toggledClearFilter(table_dt.search(), settings.nTable.id);
1164
            toggledClearFilter(table_dt.search(), settings.nTable.id);
1115
        });
1165
        });
1116
1166
1167
        if ( show_search_descriptions !== undefined ) {
1168
            table_dt.on( 'draw', function ( e, settings ) {
1169
                update_search_description(table, table_dt, { node: show_search_descriptions, additional_search_descriptions } );
1170
            });
1171
            update_search_description(table, table_dt, { node: show_search_descriptions, additional_search_descriptions } );
1172
        }
1173
1117
        return table;
1174
        return table;
1118
    };
1175
    };
1119
1176
1120
- 

Return to bug 38116