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 419-424 Link Here
419
                };
419
                };
420
            [% END %]
420
            [% END %]
421
421
422
            let additional_search_descriptions = {};
423
            [% IF display_search_description %]
424
                additional_search_descriptions = {
425
                    main: function(){
426
                        let parent_block = $("#[% search_results_block_id | html %]");
427
                        let patron_search_form = get_patron_search_form();
428
                        let searched = "";
429
                        let pattern = patron_search_form.find(".search_patron_filter").val();
430
                        if ( pattern ) {
431
                            let field = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
432
                            if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
433
                                searched += _("%s starting with '%s'".format(field, pattern));
434
                            } else {
435
                                searched += _("%s containing '%s'".format(field, pattern));
436
                            }
437
                        }
438
439
                        if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
440
                            searched += _(" with sort1 ")
441
                            if ( patron_search_form.find("select[name='sort1_filter']") ) {
442
                                searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
443
                            }
444
                            else {
445
                                searched += paron_search_form.find("select[name='sort1_filter']").val();
446
                            }
447
                        }
448
                        if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
449
                            searched += _(" with sort2 ")
450
                            if ( patron_search_form.find("select[name='sort2_filter']") ) {
451
                                searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
452
                            }
453
                            else {
454
                                searched += paron_search_form.find("select[name='sort2_filter']").val();
455
                            }
456
                        }
457
                        return searched;
458
                    },
459
                    surname: function(){
460
                        let parent_block = $("#[% search_results_block_id | html %]");
461
                        let start_with = parent_block.find(".firstletter_filter").val()
462
                        if (!start_with) return "";
463
                        return _("Surname begins with '%s'".format(start_with));
464
                    },
465
                };
466
            [% END %]
467
422
            [% UNLESS default_sort_column %]
468
            [% UNLESS default_sort_column %]
423
                [% default_sort_column = "name" %]
469
                [% default_sort_column = "name" %]
424
            [% END %]
470
            [% 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 table_dt = patrons_table.DataTable();
827
            let table_dt = patrons_table.DataTable();
Lines 810-860 Link Here
810
            $("#searchtype").val($("#searchtype_filter").val());
855
            $("#searchtype").val($("#searchtype_filter").val());
811
        }
856
        }
812
857
813
        function update_search_description(){
814
            let parent_block = $("#[% search_results_block_id | html %]");
815
            let patron_search_form = get_patron_search_form();
816
            var searched = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
817
            let pattern = patron_search_form.find(".search_patron_filter").val();
818
            if ( pattern ) {
819
                if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
820
                    searched += _(" starting with ");
821
                } else {
822
                    searched += _(" containing ");
823
                }
824
                searched += "'" + pattern + "'";
825
            }
826
            let firstletter_filter = parent_block.find(".firstletter_filter").val();
827
            if ( firstletter_filter ) {
828
                searched += _(" begins with ") + "'" + firstletter_filter +"'";
829
            }
830
831
            if ( patron_search_form.find(".categorycode_filter").val() ) {
832
                searched += _(" with category ") + "'" + patron_search_form.find(".categorycode_filter option:selected").text() + "'";
833
            }
834
            if ( patron_search_form.find(".branchcode_filter").val() ) {
835
                searched += _(" in library ") + patron_search_form.find(".branchcode_filter option:selected").text();
836
            }
837
            if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
838
                searched += _(" with sort1 ")
839
                if ( patron_search_form.find("select[name='sort1_filter']") ) {
840
                    searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
841
                }
842
                else {
843
                    searched += paron_search_form.find("select[name='sort1_filter']").val();
844
                }
845
            }
846
            if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
847
                searched += _(" with sort2 ")
848
                if ( patron_search_form.find("select[name='sort2_filter']") ) {
849
                    searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
850
                }
851
                else {
852
                    searched += paron_search_form.find("select[name='sort2_filter']").val();
853
                }
854
            }
855
            parent_block.find(".searchpattern").text(searched).parent().show();
856
        }
857
858
        function filter() {
858
        function filter() {
859
            let parent_block = $("#[% search_results_block_id | html %]");
859
            let parent_block = $("#[% search_results_block_id | html %]");
860
            let patron_search_form = get_patron_search_form();
860
            let patron_search_form = get_patron_search_form();
Lines 903-911 Link Here
903
            table_dt.settings()[0].loaded_from_state = false;
903
            table_dt.settings()[0].loaded_from_state = false;
904
            first_draw = 1; // Only redirect if we are coming from here
904
            first_draw = 1; // Only redirect if we are coming from here
905
            table_dt.draw();
905
            table_dt.draw();
906
            [% IF display_search_description %]
907
                update_search_description();
908
            [% END %]
909
            return false;
906
            return false;
910
        }
907
        }
911
908
Lines 925-933 Link Here
925
                history.pushState( {}, null, window.location.href.split("?" )[0]);
922
                history.pushState( {}, null, window.location.href.split("?" )[0]);
926
            [% END %]
923
            [% END %]
927
            $("#[% table_id | html %]_search_results").hide();
924
            $("#[% table_id | html %]_search_results").hide();
928
            [% IF display_search_description %]
929
                update_search_description();
930
            [% END %]
931
        }
925
        }
932
926
933
        // User has clicked on a letter
927
        // User has clicked on a letter
Lines 944-952 Link Here
944
            [% END %]
938
            [% END %]
945
939
946
            patrons_table.DataTable().draw();
940
            patrons_table.DataTable().draw();
947
            [% IF display_search_description %]
948
                update_search_description();
949
            [% END %]
950
        }
941
        }
951
942
952
        // modify parent window owner element
943
        // modify parent window owner element
(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-2 / +58 lines)
Lines 1077-1082 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1077
    };
1077
    };
1078
}
1078
}
1079
1079
1080
function update_search_description(table_node, table_dt, additional_search_descriptions) {
1081
    let description_node = additional_search_descriptions.node;
1082
    let description_fns  = additional_search_descriptions.additional_search_descriptions;
1083
    let description = [];
1084
    let global_search = table_dt.search()
1085
    if ( global_search.length ) {
1086
        description.push(__("Anywhere: %s").format(global_search));
1087
    }
1088
    let additional_searches = [];
1089
    for ( f in description_fns ) {
1090
        let d = description_fns[f]();
1091
        if (d.length){
1092
            additional_searches.push(d);
1093
        }
1094
    }
1095
    if (additional_searches.length){
1096
        description.push(additional_searches.join(", "));
1097
    }
1098
    let column_searches = [];
1099
    table_dt.columns().search().each((search, i) => {
1100
        if( search.length ) {
1101
            // Retrieve the value from the dropdown list if there is one
1102
            var visible_i = table_dt.column.index('fromData', i);
1103
            let option = $(table_node).find('thead tr:eq(1) th:eq(%s) select option:selected'.format(visible_i));
1104
            if ( option.length ) {
1105
                search = $(option).text();
1106
            }
1107
1108
            column_searches.push("%s=%s".format(table_dt.column(i).header().innerHTML, search));
1109
        }
1110
    });
1111
    if(column_searches.length){
1112
        description.push(column_searches.join(", "));
1113
    }
1114
1115
    if ( description.length ) {
1116
        let display = description.length ? "block" : "none";
1117
        let description_str = $(description_node).data('prefix').format(description.join("<br/>"));
1118
        $(description_node).html(description_str).show();
1119
    } else {
1120
        $(description_node).html("").hide();
1121
    }
1122
}
1123
1080
(function($) {
1124
(function($) {
1081
1125
1082
    /**
1126
    /**
Lines 1092-1100 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1092
    *                                                available from the columns_settings template toolkit include
1136
    *                                                available from the columns_settings template toolkit include
1093
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
1137
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
1094
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1138
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1139
    * @param  {Object}  filters_options              Build selects for the filters row, and pass their value.
1140
    *                                                eg. { 1 => vendors } will build a select with the vendor list in the second column
1141
    * @param  {Object}  show_search_descriptions     Whether or not display the search descriptions when the table is drawn
1142
    *                                                Expect a node in which to place the descriptions. It must have a data-prefix attribute to build the description properly.
1143
    * @param  {Object}  aditional_search_descriptions Pass additional descriptions
1144
    *                                                 eg. { surname => () => { 'Surname with '.format($("#surname_form").val()) } }
1095
    * @return {Object}                               The dataTables instance
1145
    * @return {Object}                               The dataTables instance
1096
    */
1146
    */
1097
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes) {
1147
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes, show_search_descriptions, additional_search_descriptions) {
1098
        var settings = null;
1148
        var settings = null;
1099
1149
1100
        if(options) {
1150
        if(options) {
Lines 1163-1168 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1163
            toggledClearFilter(settings.oPreviousSearch.sSearch, settings.nTable.id);
1213
            toggledClearFilter(settings.oPreviousSearch.sSearch, settings.nTable.id);
1164
        });
1214
        });
1165
1215
1216
        if ( show_search_descriptions !== undefined ) {
1217
            table_dt.on( 'draw', function ( e, settings ) {
1218
                update_search_description(table, table_dt, { node: show_search_descriptions, additional_search_descriptions } );
1219
            });
1220
            update_search_description(table, table_dt, { node: show_search_descriptions, additional_search_descriptions } );
1221
        }
1222
1166
        return table;
1223
        return table;
1167
    };
1224
    };
1168
1225
1169
- 

Return to bug 38116