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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt (-10 / +41 lines)
Lines 218-223 Link Here
218
    [% Asset.js("js/members-menu.js") | $raw %]
218
    [% Asset.js("js/members-menu.js") | $raw %]
219
    <script>
219
    <script>
220
        var singleBranchMode = '[% singleBranchMode | html %]';
220
        var singleBranchMode = '[% singleBranchMode | html %]';
221
        var dtMemberResults;
222
        var search = 1;
223
        /* popstate event triggered by forward and back button. Need to refresh search */
224
        window.addEventListener('popstate', (event) => {
225
            getSearchByLocation( false );
226
        });
227
221
        $(document).ready(function() {
228
        $(document).ready(function() {
222
            $('#merge-patrons').prop('disabled', true);
229
            $('#merge-patrons').prop('disabled', true);
223
            $('#memberresultst').on('change', 'input.selection', function() {
230
            $('#memberresultst').on('change', 'input.selection', function() {
Lines 319-325 Link Here
319
            });
326
            });
320
            $(".filterByLetter").on("click",function(e){
327
            $(".filterByLetter").on("click",function(e){
321
                e.preventDefault();
328
                e.preventDefault();
322
                filterByFirstLetterSurname($(this).text());
329
                filterByFirstLetterSurname( $(this).text(), true );
323
            });
330
            });
324
            $("#select_all").on("click",function(e){
331
            $("#select_all").on("click",function(e){
325
                e.preventDefault();
332
                e.preventDefault();
Lines 335-345 Link Here
335
            });
342
            });
336
            $("#searchform").on("submit", filter);
343
            $("#searchform").on("submit", filter);
337
344
338
        });
339
340
        var dtMemberResults;
341
        var search = 1;
342
        $(document).ready(function() {
343
            [% IF searchmember %]
345
            [% IF searchmember %]
344
                $("#searchmember_filter").val("[% searchmember | html %]");
346
                $("#searchmember_filter").val("[% searchmember | html %]");
345
            [% END %]
347
            [% END %]
Lines 451-456 Link Here
451
                            // redirect if there is only 1 result.
453
                            // redirect if there is only 1 result.
452
                            if ( json.aaData.length == 1 ) {
454
                            if ( json.aaData.length == 1 ) {
453
                                var borrowernumber = json.aaData[0].borrowernumber;
455
                                var borrowernumber = json.aaData[0].borrowernumber;
456
                                /* Overwrite history state of firstletter search since only one result was returned; This prevents a loop upon clicking back */
457
                                history.replaceState( {}, null, window.location.href.split("?" )[0]);
454
                                document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
458
                                document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
455
                                return false;
459
                                return false;
456
                            }
460
                            }
Lines 501-508 Link Here
501
                }
505
                }
502
            }, columns_settings);
506
            }, columns_settings);
503
            update_searched();
507
            update_searched();
508
            /* Initial page load doesn't trigger the popstate event, so we explicitly call this */
509
            getSearchByLocation( false );
510
504
        });
511
        });
505
512
513
        function getSearchByLocation( setstate ){
514
            /* Check to see if the URL contains a search parameter */
515
            if( location.search != ""){
516
                var params = new URLSearchParams( location.search );
517
                var firstletter = params.get("firstletter");
518
                /* Check to see if search is a first letter param */
519
                if( firstletter ){
520
                    /* Trigger function to return search results by letter */
521
                    filterByFirstLetterSurname( firstletter, setstate );
522
                }
523
            } else {
524
                /* No letter search param; Return page to default state with no results */
525
                update_searched();
526
                search = 0;
527
                $("#searchresults").hide();
528
                dtMemberResults.fnDraw();
529
            }
530
        }
531
506
        // Update the string "Results found ..."
532
        // Update the string "Results found ..."
507
        function update_searched(){
533
        function update_searched(){
508
            var searched = $("#searchfieldstype_filter").find("option:selected").text();
534
            var searched = $("#searchfieldstype_filter").find("option:selected").text();
Lines 542-557 Link Here
542
            $("#firstletter_filter").val('');
568
            $("#firstletter_filter").val('');
543
            $("#searchmember_filter").val('');
569
            $("#searchmember_filter").val('');
544
            if(redraw) {
570
            if(redraw) {
545
                search = 1;
571
                /* remove any search string added by firstletter search */
546
                $("#searchresults").show();
572
                history.pushState( {}, null, window.location.href.split("?" )[0]);
573
                update_searched();
574
                search = 0;
575
                $("#searchresults").hide();
547
                dtMemberResults.fnDraw();
576
                dtMemberResults.fnDraw();
548
            }
577
            }
549
        }
578
        }
550
579
551
        // User has clicked on a letter
580
        // User has clicked on a letter
552
        function filterByFirstLetterSurname(letter) {
581
        function filterByFirstLetterSurname( letter, setstate ) {
553
            clearFilters(false);
582
            clearFilters(false);
554
            $("#firstletter_filter").val(letter);
583
            $("#firstletter_filter").val(letter);
584
            if( setstate ){
585
                history.pushState( null, null, "?firstletter=" + letter );
586
            }
555
            update_searched();
587
            update_searched();
556
            search = 1;
588
            search = 1;
557
            $("#searchresults").show();
589
            $("#searchresults").show();
558
- 

Return to bug 27725