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 149-155 Link Here
149
        [% END %]
149
        [% END %]
150
    </div>
150
    </div>
151
151
152
    <h3 style="display: none;">Patrons found for: <span class="searchpattern"></span></h3>
152
    <h3 style="display: none;" class="search_description" data-prefix="[% I18N.t("Patrons found for: %s") %]"></h3>
153
153
154
    <div id="[% table_id | html %]_search_results" style="display:none;">
154
    <div id="[% table_id | html %]_search_results" style="display:none;">
155
155
Lines 412-417 Link Here
412
                }
412
                }
413
            };
413
            };
414
414
415
            let additional_search_descriptions = {};
416
            [% IF display_search_description %]
417
                additional_search_descriptions = {
418
                    main: function(){
419
                        let parent_block = $("#[% search_results_block_id | html %]");
420
                        let patron_search_form = get_patron_search_form();
421
                        let searched = "";
422
                        let pattern = patron_search_form.find(".search_patron_filter").val();
423
                        if ( pattern ) {
424
                            let field = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
425
                            if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
426
                                searched += _("%s starting with '%s'".format(field, pattern));
427
                            } else {
428
                                searched += _("%s containing '%s'".format(field, pattern));
429
                            }
430
                        }
431
432
                        if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
433
                            searched += _(" with sort1 ")
434
                            if ( patron_search_form.find("select[name='sort1_filter']") ) {
435
                                searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
436
                            }
437
                            else {
438
                                searched += paron_search_form.find("select[name='sort1_filter']").val();
439
                            }
440
                        }
441
                        if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
442
                            searched += _(" with sort2 ")
443
                            if ( patron_search_form.find("select[name='sort2_filter']") ) {
444
                                searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
445
                            }
446
                            else {
447
                                searched += paron_search_form.find("select[name='sort2_filter']").val();
448
                            }
449
                        }
450
                        return searched;
451
                    },
452
                    surname: function(){
453
                        let parent_block = $("#[% search_results_block_id | html %]");
454
                        let start_with = parent_block.find(".firstletter_filter").val()
455
                        if (!start_with) return "";
456
                        return _("Surname begins with '%s'".format(start_with));
457
                    },
458
                };
459
            [% END %]
460
415
            [% UNLESS default_sort_column %]
461
            [% UNLESS default_sort_column %]
416
                [% default_sort_column = "name" %]
462
                [% default_sort_column = "name" %]
417
            [% END %]
463
            [% END %]
Lines 727-733 Link Here
727
                },
773
                },
728
                [% END %]
774
                [% END %]
729
                fixedHeader: false,
775
                fixedHeader: false,
730
            }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters);
776
            }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters, undefined, parent_block.find(".search_description"), additional_search_descriptions );
731
777
732
            patron_search_form.on('submit', filter);
778
            patron_search_form.on('submit', filter);
733
            patron_search_form.on('submit', update_search_type);
779
            patron_search_form.on('submit', update_search_type);
Lines 773-779 Link Here
773
            patron_search_form.find(".clear_search").on("click",function(e){
819
            patron_search_form.find(".clear_search").on("click",function(e){
774
                e.preventDefault();
820
                e.preventDefault();
775
                clearFilters();
821
                clearFilters();
776
                patron_search_form.find(".searchpattern").parent().hide();
777
            });
822
            });
778
823
779
            let table_dt = patrons_table.DataTable();
824
            let table_dt = patrons_table.DataTable();
Lines 807-857 Link Here
807
            $("#searchtype").val($("#searchtype_filter").val());
852
            $("#searchtype").val($("#searchtype_filter").val());
808
        }
853
        }
809
854
810
        function update_search_description(){
811
            let parent_block = $("#[% search_results_block_id | html %]");
812
            let patron_search_form = get_patron_search_form();
813
            var searched = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
814
            let pattern = patron_search_form.find(".search_patron_filter").val();
815
            if ( pattern ) {
816
                if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
817
                    searched += _(" starting with ");
818
                } else {
819
                    searched += _(" containing ");
820
                }
821
                searched += "'" + pattern + "'";
822
            }
823
            let firstletter_filter = parent_block.find(".firstletter_filter").val();
824
            if ( firstletter_filter ) {
825
                searched += _(" begins with ") + "'" + firstletter_filter +"'";
826
            }
827
828
            if ( patron_search_form.find(".categorycode_filter").val() ) {
829
                searched += _(" with category ") + "'" + patron_search_form.find(".categorycode_filter option:selected").text() + "'";
830
            }
831
            if ( patron_search_form.find(".branchcode_filter").val() ) {
832
                searched += _(" in library ") + patron_search_form.find(".branchcode_filter option:selected").text();
833
            }
834
            if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
835
                searched += _(" with sort1 ")
836
                if ( patron_search_form.find("select[name='sort1_filter']") ) {
837
                    searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
838
                }
839
                else {
840
                    searched += paron_search_form.find("select[name='sort1_filter']").val();
841
                }
842
            }
843
            if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
844
                searched += _(" with sort2 ")
845
                if ( patron_search_form.find("select[name='sort2_filter']") ) {
846
                    searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
847
                }
848
                else {
849
                    searched += paron_search_form.find("select[name='sort2_filter']").val();
850
                }
851
            }
852
            parent_block.find(".searchpattern").text(searched).parent().show();
853
        }
854
855
        function filter() {
855
        function filter() {
856
            let parent_block = $("#[% search_results_block_id | html %]");
856
            let parent_block = $("#[% search_results_block_id | html %]");
857
            let patron_search_form = get_patron_search_form();
857
            let patron_search_form = get_patron_search_form();
Lines 900-908 Link Here
900
            table_dt.settings()[0].loaded_from_state = false;
900
            table_dt.settings()[0].loaded_from_state = false;
901
            first_draw = 1; // Only redirect if we are coming from here
901
            first_draw = 1; // Only redirect if we are coming from here
902
            table_dt.draw();
902
            table_dt.draw();
903
            [% IF display_search_description %]
904
                update_search_description();
905
            [% END %]
906
            return false;
903
            return false;
907
        }
904
        }
908
905
Lines 922-930 Link Here
922
                history.pushState( {}, null, window.location.href.split("?" )[0]);
919
                history.pushState( {}, null, window.location.href.split("?" )[0]);
923
            [% END %]
920
            [% END %]
924
            $("#[% table_id | html %]_search_results").hide();
921
            $("#[% table_id | html %]_search_results").hide();
925
            [% IF display_search_description %]
926
                update_search_description();
927
            [% END %]
928
        }
922
        }
929
923
930
        // User has clicked on a letter
924
        // User has clicked on a letter
Lines 941-949 Link Here
941
            [% END %]
935
            [% END %]
942
936
943
            patrons_table.DataTable().draw();
937
            patrons_table.DataTable().draw();
944
            [% IF display_search_description %]
945
                update_search_description();
946
            [% END %]
947
        }
938
        }
948
939
949
        // modify parent window owner element
940
        // modify parent window owner element
(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-2 / +58 lines)
Lines 1011-1016 function _dt_save_restore_state(table_settings){ Link Here
1011
    return {stateSave: true, stateSaveCallback, stateLoadCallback};
1011
    return {stateSave: true, stateSaveCallback, stateLoadCallback};
1012
}
1012
}
1013
1013
1014
function update_search_description(table_node, table_dt, additional_search_descriptions) {
1015
    let description_node = additional_search_descriptions.node;
1016
    let description_fns  = additional_search_descriptions.additional_search_descriptions;
1017
    let description = [];
1018
    let global_search = table_dt.search()
1019
    if ( global_search.length ) {
1020
        description.push(__("Anywhere: %s").format(global_search));
1021
    }
1022
    let additional_searches = [];
1023
    for ( f in description_fns ) {
1024
        let d = description_fns[f]();
1025
        if (d.length){
1026
            additional_searches.push(d);
1027
        }
1028
    }
1029
    if (additional_searches.length){
1030
        description.push(additional_searches.join(", "));
1031
    }
1032
    let column_searches = [];
1033
    table_dt.columns().search().each((search, i) => {
1034
        if( search.length ) {
1035
            // Retrieve the value from the dropdown list if there is one
1036
            var visible_i = table_dt.column.index('fromData', i);
1037
            let option = $(table_node).find('thead tr:eq(1) th:eq(%s) select option:selected'.format(visible_i));
1038
            if ( option.length ) {
1039
                search = $(option).text();
1040
            }
1041
1042
            column_searches.push("%s=%s".format(table_dt.column(i).header().innerHTML, search));
1043
        }
1044
    });
1045
    if(column_searches.length){
1046
        description.push(column_searches.join(", "));
1047
    }
1048
1049
    if ( description.length ) {
1050
        let display = description.length ? "block" : "none";
1051
        let description_str = $(description_node).data('prefix').format(description.join("<br/>"));
1052
        $(description_node).html(description_str).show();
1053
    } else {
1054
        $(description_node).html("").hide();
1055
    }
1056
}
1057
1014
(function($) {
1058
(function($) {
1015
1059
1016
    /**
1060
    /**
Lines 1026-1034 function _dt_save_restore_state(table_settings){ Link Here
1026
    *                                                available from the columns_settings template toolkit include
1070
    *                                                available from the columns_settings template toolkit include
1027
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
1071
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
1028
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1072
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1073
    * @param  {Object}  filters_options              Build selects for the filters row, and pass their value.
1074
    *                                                eg. { 1 => vendors } will build a select with the vendor list in the second column
1075
    * @param  {Object}  show_search_descriptions     Whether or not display the search descriptions when the table is drawn
1076
    *                                                Expect a node in which to place the descriptions. It must have a data-prefix attribute to build the description properly.
1077
    * @param  {Object}  aditional_search_descriptions Pass additional descriptions
1078
    *                                                 eg. { surname => () => { 'Surname with '.format($("#surname_form").val()) } }
1029
    * @return {Object}                               The dataTables instance
1079
    * @return {Object}                               The dataTables instance
1030
    */
1080
    */
1031
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options) {
1081
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, show_search_descriptions, additional_search_descriptions) {
1032
        var settings = null;
1082
        var settings = null;
1033
1083
1034
        if(options) {
1084
        if(options) {
Lines 1099-1104 function _dt_save_restore_state(table_settings){ Link Here
1099
            toggledClearFilter(settings.oPreviousSearch.sSearch, settings.nTable.id);
1149
            toggledClearFilter(settings.oPreviousSearch.sSearch, settings.nTable.id);
1100
        });
1150
        });
1101
1151
1152
        if ( show_search_descriptions !== undefined ) {
1153
            table_dt.on( 'draw', function ( e, settings ) {
1154
                update_search_description(table, table_dt, { node: show_search_descriptions, additional_search_descriptions } );
1155
            });
1156
            update_search_description(table, table_dt, { node: show_search_descriptions, additional_search_descriptions } );
1157
        }
1158
1102
        return table;
1159
        return table;
1103
    };
1160
    };
1104
1161
1105
- 

Return to bug 38116