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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/av-build-dropbox.inc (-2 / +10 lines)
Lines 12-18 Link Here
12
[% DEFAULT class = '' size = 20 %]
12
[% DEFAULT class = '' size = 20 %]
13
13
14
[% IF avs.count %]
14
[% IF avs.count %]
15
  <select id="[% name | html %]" name="[% name | html %]" class="[% class | html %]" >
15
  [% IF no_id %]
16
    <select name="[% name | html %]" class="[% class | html %]" >
17
  [% ELSE %]
18
    <select id="[% name | html %]" name="[% name | html %]" class="[% class | html %]" >
19
  [% END %]
16
  [% IF all %]<option value="">All</option>[% END %]
20
  [% IF all %]<option value="">All</option>[% END %]
17
  [% IF empty %]<option value=""></option>[% END %]
21
  [% IF empty %]<option value=""></option>[% END %]
18
  [% FOR av IN avs %]
22
  [% FOR av IN avs %]
Lines 24-28 Link Here
24
  [% END %]
28
  [% END %]
25
  </select>
29
  </select>
26
[% ELSE %]
30
[% ELSE %]
27
  <input type="text" id="[% name | html %]" name="[% name | html %]" size="[% size | html %]" value="[% default | html_entity %]" class="[% class | html %]" />
31
  [% IF no_id %]
32
    <input type="text" name="[% name | html %]" size="[% size | html %]" value="[% default | html_entity %]" class="[% class | html %]" />
33
  [% ELSE %]
34
    <input type="text" id="[% name | html %]" name="[% name | html %]" size="[% size | html %]" value="[% default | html_entity %]" class="[% class | html %]" />
35
  [% END %]
28
[% END %]
36
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-110 / +151 lines)
Lines 7-17 Link Here
7
[% USE Asset %]
7
[% USE Asset %]
8
[% USE To %]
8
[% USE To %]
9
9
10
[% SET search_results_block_id = 'searchresults' %]
11
10
[%# Display a simple form %]
12
[%# Display a simple form %]
11
[% BLOCK patron_search_filters_simple  %]
13
[% BLOCK patron_search_filters_simple  %]
12
    <form id="patron_search_form">
14
    <form class="patron_search_form">
13
        <div class="hint">Enter patron card number or partial name:</div>
15
        <div class="hint">Enter patron card number or partial name:</div>
14
        <input type="text" size="40" id="search_patron_filter" class="focus" autocomplete="off" />
16
        <input type="text" size="40" class="search_patron_filter" class="focus" autocomplete="off" />
15
        <input type="submit" class="btn btn-primary" value="Search" />
17
        <input type="submit" class="btn btn-primary" value="Search" />
16
    </form>
18
    </form>
17
[% END %]
19
[% END %]
Lines 27-39 Link Here
27
[%# - search_type: select 'contains' or 'starts with' %]
29
[%# - search_type: select 'contains' or 'starts with' %]
28
[%- searchtype = searchtype || Koha.Preference('DefaultPatronSearchMethod') -%]
30
[%- searchtype = searchtype || Koha.Preference('DefaultPatronSearchMethod') -%]
29
[% BLOCK patron_search_filters %]
31
[% BLOCK patron_search_filters %]
30
    <form id="patron_search_form">
32
33
    <form class="patron_search_form">
31
        <fieldset class="brief">
34
        <fieldset class="brief">
32
            <h3>Search for patron</h3>
35
            <h3>Search for patron</h3>
33
            <ol>
36
            <ol>
34
                <li>
37
                <li>
35
                    <label for="search_patron_filter">Search:</label>
38
                    <label for="search_patron_filter">Search:</label>
36
                    <input type="text" id="search_patron_filter" value="[% search_filter | html %]" class="focus" />
39
                    <input type="text" class="search_patron_filter" value="[% search_filter | html %]" class="focus" />
37
                </li>
40
                </li>
38
41
39
                [% FOR f IN filters %]
42
                [% FOR f IN filters %]
Lines 41-47 Link Here
41
                    [% CASE 'branch' %]
44
                    [% CASE 'branch' %]
42
                        <li>
45
                        <li>
43
                            <label for="branchcode_filter">Library:</label>
46
                            <label for="branchcode_filter">Library:</label>
44
                            <select id="branchcode_filter">
47
                            <select class="branchcode_filter">
45
                                [% SET libraries = Branches.all( only_from_group => 1 ) %]
48
                                [% SET libraries = Branches.all( only_from_group => 1 ) %]
46
                                [% IF libraries.size != 1 %]
49
                                [% IF libraries.size != 1 %]
47
                                    <option value="">Any</option>
50
                                    <option value="">Any</option>
Lines 54-60 Link Here
54
                    [% CASE 'category' %]
57
                    [% CASE 'category' %]
55
                        <li>
58
                        <li>
56
                            <label for="categorycode_filter">Category:</label>
59
                            <label for="categorycode_filter">Category:</label>
57
                            <select id="categorycode_filter">
60
                            <select class="categorycode_filter">
58
                                <option value="">Any</option>
61
                                <option value="">Any</option>
59
                                [% FOREACH category IN Categories.limited.unblessed %]
62
                                [% FOREACH category IN Categories.limited.unblessed %]
60
                                    <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
63
                                    <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
Lines 64-75 Link Here
64
                    [% CASE 'sort1' %]
67
                    [% CASE 'sort1' %]
65
                        <li>
68
                        <li>
66
                            <label for="sort1_filter">Sort 1:</label>
69
                            <label for="sort1_filter">Sort 1:</label>
67
                            [% PROCESS 'av-build-dropbox.inc' name="sort1_filter", category="Bsort1", empty=1, size = 20 %]
70
                            [% PROCESS 'av-build-dropbox.inc' no_id => 1, name="sort1_filter", category="Bsort1", empty=1, size = 20 %]
68
                        </li>
71
                        </li>
69
                    [% CASE 'sort2' %]
72
                    [% CASE 'sort2' %]
70
                        <li>
73
                        <li>
71
                            <label for="sort2_filter">Sort 2:</label>
74
                            <label for="sort2_filter">Sort 2:</label>
72
                            [% PROCESS 'av-build-dropbox.inc' name="sort2_filter", category="Bsort2", empty=1, size = 20 %]
75
                            [% PROCESS 'av-build-dropbox.inc' no_id => 1, name="sort2_filter", category="Bsort2", empty=1, size = 20 %]
73
                        </li>
76
                        </li>
74
                    [% CASE 'search_field' %]
77
                    [% CASE 'search_field' %]
75
                        <li>
78
                        <li>
Lines 78-84 Link Here
78
                    [% CASE 'search_type' %]
81
                    [% CASE 'search_type' %]
79
                        <li>
82
                        <li>
80
                            <label for="searchtype_filter">Search type:</label>
83
                            <label for="searchtype_filter">Search type:</label>
81
                            <select name="searchtype" id="searchtype_filter">
84
                            <select name="searchtype" class="searchtype_filter">
82
                              [% IF searchtype == "starts_with" %]
85
                              [% IF searchtype == "starts_with" %]
83
                                <option value='starts_with' selected="selected">Starts with</option>
86
                                <option value='starts_with' selected="selected">Starts with</option>
84
                                <option value="contains">Contains</option>
87
                                <option value="contains">Contains</option>
Lines 93-99 Link Here
93
            </ol>
96
            </ol>
94
            <fieldset class="action">
97
            <fieldset class="action">
95
                <input type="submit" class="btn btn-primary" value="Search" />
98
                <input type="submit" class="btn btn-primary" value="Search" />
96
                <input type="button" value="Clear" id="clear_search" />
99
                <input type="button" value="Clear" class="clear_search" />
97
            </fieldset>
100
            </fieldset>
98
        </fieldset>
101
        </fieldset>
99
    </form>
102
    </form>
Lines 135-148 Link Here
135
        [% END %]
138
        [% END %]
136
    </div>
139
    </div>
137
140
138
    <h3 style="display: none;">Patrons found for: <span id="searchpattern"></span></h3>
141
    <h3 style="display: none;">Patrons found for: <span class="searchpattern"></span></h3>
139
142
140
    <div id="[% table_id | html %]_search_results" style="display:none;">
143
    <div id="[% table_id | html %]_search_results" style="display:none;">
141
144
142
        <div id="info" class="dialog message" style="display: none;"></div>
145
        <div class="info" class="dialog message" style="display: none;"></div>
143
        <div id="error" class="dialog alert" style="display: none;"></div>
146
        <div class="error" class="dialog alert" style="display: none;"></div>
144
147
145
        <input type="hidden" id="firstletter_filter" value="" />
148
        <input type="hidden" class="firstletter_filter" value="" />
146
        [% IF open_on_row_click %]
149
        [% IF open_on_row_click %]
147
        <table id="[% table_id | html %]" class="selections-table">
150
        <table id="[% table_id | html %]" class="selections-table">
148
        [% ELSE %]
151
        [% ELSE %]
Lines 203-208 Link Here
203
[%# sticky_header and sticky_to: If we need a sticky header %]
206
[%# sticky_header and sticky_to: If we need a sticky header %]
204
[%# callback: name of the JS function that will be called when a patron is selected. Only work with action=select %]
207
[%# callback: name of the JS function that will be called when a patron is selected. Only work with action=select %]
205
[%# display_search_description: boolean, default off. Display the description of the search %]
208
[%# display_search_description: boolean, default off. Display the description of the search %]
209
[%# adjust_history: boolean, default off. Change the current url when a first letter is selected %]
206
[% BLOCK patron_search_js %]
210
[% BLOCK patron_search_js %]
207
211
208
    [% IF redirect_if_one_result && !redirect_url %]
212
    [% IF redirect_if_one_result && !redirect_url %]
Lines 212-244 Link Here
212
    <script>
216
    <script>
213
        [% SET libraries = Branches.all %]
217
        [% SET libraries = Branches.all %]
214
        [% SET categories = Categories.limited.unblessed %]
218
        [% SET categories = Categories.limited.unblessed %]
215
        let categories = [% To.json(categories) | $raw %].map(e => {
219
        var categories = [% To.json(categories) | $raw %].map(e => {
216
            e['_id'] = e.categorycode.toLowerCase();
220
            e['_id'] = e.categorycode.toLowerCase();
217
            e['_str'] = e.description;
221
            e['_str'] = e.description;
218
            return e;
222
            return e;
219
        });
223
        });
220
        let categories_map = categories.reduce((map, e) => {
224
        var categories_map = categories.reduce((map, e) => {
221
            map[e._id] = e;
225
            map[e._id] = e;
222
            return map;
226
            return map;
223
        }, {});
227
        }, {});
224
        let libraries  = [% To.json(libraries) | $raw %].map(e => {
228
        var libraries  = [% To.json(libraries) | $raw %].map(e => {
225
            e['_id'] = e.branchcode;
229
            e['_id'] = e.branchcode;
226
            e['_str'] = e.branchname;
230
            e['_str'] = e.branchname;
227
            return e;
231
            return e;
228
        });
232
        });
229
        let libraries_map = libraries.reduce((map, e) => {
233
        var libraries_map = libraries.reduce((map, e) => {
230
            map[e._id] = e;
234
            map[e._id] = e;
231
            return map;
235
            return map;
232
        }, {});
236
        }, {});
233
237
234
        [% IF Koha.Preference('ExtendedPatronAttributes') %]
238
        [% IF Koha.Preference('ExtendedPatronAttributes') %]
235
            [% SET extended_attribute_types = [ ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) ] %]
239
            [% SET extended_attribute_types = [ ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) ] %]
236
            let extended_attribute_types = [% To.json(extended_attribute_types || []) | $raw %];
240
            var extended_attribute_types = [% To.json(extended_attribute_types || []) | $raw %];
237
        [% END %]
241
        [% END %]
238
242
239
        $(document).ready(function() {
243
        $(document).ready(function() {
240
            $('select#sort1_filter').select2({allowClear:true});
244
            $('select[name="sort1_filter"]').select2({allowClear:true});
241
            $('select#sort2_filter').select2({allowClear:true});
245
            $('select[name="sort2_filter"]').select2({allowClear:true});
242
        });
246
        });
243
    </script>
247
    </script>
244
248
Lines 251-260 Link Here
251
    [% END %]
255
    [% END %]
252
256
253
    <script>
257
    <script>
254
        var first_draw = 0;
258
    {
259
260
        function get_patron_search_form(){
261
            let parent_block = $("#[% search_results_block_id | html %]");
262
            let patron_search_form = parent_block.siblings(".patron_search_form");
263
            if ( !patron_search_form.length ) patron_search_form = $(".patron_search_form");
264
            return patron_search_form;
265
        }
266
        let first_draw = 0;
255
        let patrons_table;
267
        let patrons_table;
256
        var Sticky;
268
        let Sticky;
257
        var singleBranchMode = '[% singleBranchMode | html %]';
269
        let singleBranchMode = '[% singleBranchMode | html %]';
258
        let logged_in_library_id = "[% Branches.GetLoggedInBranchcode | html %]";
270
        let logged_in_library_id = "[% Branches.GetLoggedInBranchcode | html %]";
259
        [% IF do_not_defer_loading %]
271
        [% IF do_not_defer_loading %]
260
            let defer_loading = 0;
272
            let defer_loading = 0;
Lines 262-271 Link Here
262
            let defer_loading = 1;
274
            let defer_loading = 1;
263
        [% END %]
275
        [% END %]
264
276
265
        /* popstate event triggered by forward and back button. Need to refresh search */
277
        [% IF adjust_history %]
266
        window.addEventListener('popstate', (event) => {
278
            /* popstate event triggered by forward and back button. Need to refresh search */
267
            getSearchByLocation( false );
279
            window.addEventListener('popstate', (event) => {
268
        });
280
                getSearchByLocation( false );
281
            });
282
        [% END %]
269
283
270
        [% SWITCH filter %]
284
        [% SWITCH filter %]
271
        [% CASE 'suggestions_managers' %]
285
        [% CASE 'suggestions_managers' %]
Lines 283-293 Link Here
283
        [% END %]
297
        [% END %]
284
        $(document).ready(function(){
298
        $(document).ready(function(){
285
299
286
            $("#info").hide();
300
            let parent_block = $("#[% search_results_block_id | html %]");
287
            $("#error").hide();
301
            let patron_search_form = get_patron_search_form();
302
303
            parent_block.find(".info").hide();
304
            parent_block.find(".error").hide();
288
305
289
            // Build the aLengthMenu
306
            // Build the aLengthMenu
290
            var aLengthMenu = [
307
            let aLengthMenu = [
291
                [% Koha.Preference('PatronsPerPage') | html %], 10, 20, 50, 100, -1
308
                [% Koha.Preference('PatronsPerPage') | html %], 10, 20, 50, 100, -1
292
            ];
309
            ];
293
            jQuery.unique(aLengthMenu);
310
            jQuery.unique(aLengthMenu);
Lines 300-306 Link Here
300
                }
317
                }
301
                return parseInt(a) < parseInt(b) ? -1 : 1;}
318
                return parseInt(a) < parseInt(b) ? -1 : 1;}
302
            );
319
            );
303
            var aLengthMenuLabel = [];
320
            let aLengthMenuLabel = [];
304
            $(aLengthMenu).each(function(){
321
            $(aLengthMenu).each(function(){
305
                if ( this == -1 ) {
322
                if ( this == -1 ) {
306
                    // Label for -1 is "All"
323
                    // Label for -1 is "All"
Lines 312-327 Link Here
312
329
313
            let additional_filters = {
330
            let additional_filters = {
314
                surname: function(){
331
                surname: function(){
315
                    let start_with = $("#firstletter_filter").val()
332
                    let start_with = parent_block.find(".firstletter_filter").val()
316
                    if (!start_with) return "";
333
                    if (!start_with) return "";
317
                    return { "like": start_with + "%" }
334
                    return { "like": start_with + "%" }
318
                },
335
                },
319
                "-and": function(){
336
                "-and": function(){
320
                    let filters = [];
337
                    let filters = [];
321
338
322
                    let search_type = $("#searchtype_filter").val();
339
                    let search_type = patron_search_form.find(".searchtype_filter").val();
323
                    let search_fields = $("#searchfieldstype_filter").val() || "standard";
340
                    let search_fields = patron_search_form.find(".searchfieldstype_filter").val() || "standard";
324
                    let pattern = $("#search_patron_filter").val();
341
                    let pattern = patron_search_form.find(".search_patron_filter").val();
325
342
326
                    filters = buildPatronSearchQuery(
343
                    filters = buildPatronSearchQuery(
327
                        pattern,
344
                        pattern,
Lines 332-344 Link Here
332
                        }
349
                        }
333
                    );
350
                    );
334
351
335
                    let f_sort1 = $("#sort1_filter").val();
352
                    let f_sort1 = patron_search_form.find("select[name='sort1_filter']").val();
336
                    if ( f_sort1 ) {
353
                    if ( f_sort1 ) {
337
                        filters.push({
354
                        filters.push({
338
                            "me.sort1": f_sort1
355
                            "me.sort1": f_sort1
339
                        });
356
                        });
340
                    }
357
                    }
341
                    let f_sort2 = $("#sort2_filter").val();
358
                    let f_sort2 = patron_search_form.find("select[name='sort2_filter']").val();
342
                    if ( f_sort2 ) {
359
                    if ( f_sort2 ) {
343
                        filters.push({
360
                        filters.push({
344
                            "me.sort2": f_sort2
361
                            "me.sort2": f_sort2
Lines 410-416 Link Here
410
                                "searchable": false,
427
                                "searchable": false,
411
                                "orderable": false,
428
                                "orderable": false,
412
                                "render": function( data, type, row, meta ) {
429
                                "render": function( data, type, row, meta ) {
413
                                    return "<label for='check" + data + "' class='content_hidden'>" + _("Select patron") + "</label><input type='checkbox' id='check" + data + "' class='selection' name='borrowernumber' value='" + data + "' />";
430
                                    return "<label for='check" + data + "' class='content_hidden'>" + _("Select patron") + "</label><input type='checkbox' class='check" + data + "' class='selection' name='borrowernumber' value='" + data + "' />";
414
                                }
431
                                }
415
                            }
432
                            }
416
                            [% CASE 'cardnumber' %]
433
                            [% CASE 'cardnumber' %]
Lines 608-614 Link Here
608
                                    [% END %]
625
                                    [% END %]
609
626
610
                                    let patron_str = JSON.stringify(row);
627
                                    let patron_str = JSON.stringify(row);
611
                                    let input_node = $('<input type="hidden" id="borrower_data' + patron_id + '" name="borrower_data'+ patron_id + '"/>');
628
                                    let input_node = $('<input type="hidden" name="borrower_data'+ patron_id + '"/>');
612
                                    $(input_node).val(patron_str);
629
                                    $(input_node).val(patron_str);
613
                                    action_node += $(input_node).prop('outerHTML');
630
                                    action_node += $(input_node).prop('outerHTML');
614
631
Lines 639-665 Link Here
639
                [% END %]
656
                [% END %]
640
            }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters);
657
            }, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters);
641
658
642
            $("#patron_search_form").on('submit', filter);
659
            patron_search_form.on('submit', filter);
643
            $("#patron_search_form").on('submit', update_search_type);
660
            patron_search_form.on('submit', update_search_type);
661
644
            $(".filterByLetter").on("click",function(e){
662
            $(".filterByLetter").on("click",function(e){
645
                e.preventDefault();
663
                e.preventDefault();
646
                filterByFirstLetterSurname($(this).text(), true);
664
                filterByFirstLetterSurname($(this).text(), true);
647
            });
665
            });
648
            $("body").on("click",".add_user",function(e){
666
            patrons_table.on("click",".add_user",function(e){
649
                e.preventDefault();
667
                e.preventDefault();
650
                var borrowernumber = $(this).data("borrowernumber");
668
                var borrowernumber = $(this).data("borrowernumber");
651
                var borrower_data = JSON.parse($("#borrower_data"+borrowernumber).val());
669
                var borrower_data = JSON.parse(patrons_table.find("input[name='borrower_data"+borrowernumber+"']").val());
652
                modal_add_user( borrowernumber, borrower_data.firstname + " " + borrower_data.surname );
670
                modal_add_user( borrowernumber, borrower_data.firstname + " " + borrower_data.surname );
653
            });
671
            });
654
            $("body").on("click",".select_user",function(e){
672
            patrons_table.on("click",".select_user",function(e){
655
                e.preventDefault();
673
                e.preventDefault();
656
                var borrowernumber = $(this).data("borrowernumber");
674
                var borrowernumber = $(this).data("borrowernumber");
657
                var borrower_data = JSON.parse($("#borrower_data"+borrowernumber).val());
675
                var borrower_data = JSON.parse(patrons_table.find("input[name='borrower_data"+borrowernumber+"']").val());
658
                modal_select_user( borrowernumber, borrower_data );
676
                modal_select_user( borrowernumber, borrower_data );
659
                $(this).closest(".modal").modal('hide');
677
                $(this).closest(".modal").modal('hide');
660
            });
678
            });
661
679
662
            $("body").on("click",".patron_preview", function( e ){
680
            patrons_table.on("click",".patron_preview", function( e ){
663
                e.preventDefault();
681
                e.preventDefault();
664
                var borrowernumber = $(this).data("borrowernumber");
682
                var borrowernumber = $(this).data("borrowernumber");
665
                var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
683
                var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
Lines 675-756 Link Here
675
                $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
693
                $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
676
            });
694
            });
677
695
678
            $("#clear_search").on("click",function(e){
696
            patron_search_form.find(".clear_search").on("click",function(e){
679
                e.preventDefault();
697
                e.preventDefault();
680
                clearFilters();
698
                clearFilters();
681
                $("#searchpattern").parent().hide();
699
                patron_search_form.find(".searchpattern").parent().hide();
682
            });
700
            });
683
701
684
            if ( !defer_loading ) {
702
            if ( !defer_loading ) {
685
                $("#patron_search_form").submit();
703
                patron_search_form.submit();
686
            }
704
            }
687
705
688
            /* Initial page load does not trigger the popstate event, so we explicitly call this */
706
            [% IF adjust_history %]
689
            getSearchByLocation( false );
707
                /* Initial page load does not trigger the popstate event, so we explicitly call this */
690
708
                getSearchByLocation( false );
709
            [% END %]
691
        });
710
        });
692
711
693
        function getSearchByLocation( setstate ){
712
        [% IF adjust_history %]
694
            /* Check to see if the URL contains a search parameter */
713
            function getSearchByLocation( setstate ){
695
            if( location.search != ""){
714
                /* Check to see if the URL contains a search parameter */
696
                var params = new URLSearchParams( location.search );
715
                if( location.search != ""){
697
                var firstletter = params.get("firstletter");
716
                    var params = new URLSearchParams( location.search );
698
                /* Check to see if search is a first letter param */
717
                    var firstletter = params.get("firstletter");
699
                if( firstletter ){
718
                    /* Check to see if search is a first letter param */
700
                    /* Trigger function to return search results by letter */
719
                    if( firstletter ){
701
                    filterByFirstLetterSurname( firstletter, setstate );
720
                        /* Trigger function to return search results by letter */
721
                        filterByFirstLetterSurname( firstletter, setstate );
722
                    }
702
                }
723
                }
703
            }
724
            }
704
        }
725
        [% END %]
705
726
706
        function update_search_type(){
727
        function update_search_type(){
707
            $("#searchtype").val($("#searchtype_filter").val());
728
            $("#searchtype").val($("#searchtype_filter").val());
708
        }
729
        }
709
730
710
        function update_search_description(){
731
        function update_search_description(){
711
            var searched = $("#searchfieldstype_filter").find("option:selected").text();
732
            let parent_block = $("#[% search_results_block_id | html %]");
712
            if ( $("#search_patron_filter").val() ) {
733
            let patron_search_form = get_patron_search_form();
713
                if ( $("#searchtype_filter").val() == 'starts_with' ) {
734
            var searched = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text();
735
            let pattern = patron_search_form.find(".search_patron_filter").val();
736
            if ( pattern ) {
737
                if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) {
714
                    searched += _(" starting with ");
738
                    searched += _(" starting with ");
715
                } else {
739
                } else {
716
                    searched += _(" containing ");
740
                    searched += _(" containing ");
717
                }
741
                }
718
                searched += "'" + $("#search_patron_filter").val() + "'";
742
                searched += "'" + pattern + "'";
719
            }
743
            }
720
            if ( $("#firstletter_filter").val() ) {
744
            let firstletter_filter = parent_block.find(".firstletter_filter").val();
721
                searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'";
745
            if ( firstletter_filter ) {
746
                searched += _(" begins with ") + "'" + firstletter_filter +"'";
722
            }
747
            }
723
            if ( $("#categorycode_filter").val() ) {
748
724
                searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'";
749
            if ( patron_search_form.find(".categorycode_filter").val() ) {
750
                searched += _(" with category ") + "'" + patron_search_form.find(".categorycode_filter option:selected").text() + "'";
725
            }
751
            }
726
            if ( $("#branchcode_filter").val() ) {
752
            if ( patron_search_form.find(".branchcode_filter").val() ) {
727
                searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
753
                searched += _(" in library ") + patron_search_form.find(".branchcode_filter option:selected").text();
728
            }
754
            }
729
            if ( $("#sort1_filter").val() ) {
755
            if ( patron_search_form.find("select[name='sort1_filter']").val() ) {
730
                searched += _(" with sort1 ")
756
                searched += _(" with sort1 ")
731
                if ( $("select#sort1_filter") ) {
757
                if ( patron_search_form.find("select[name='sort1_filter']") ) {
732
                    searched += $("select#sort1_filter").find("option:selected").text();
758
                    searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text();
733
                }
759
                }
734
                else {
760
                else {
735
                    searched += $("#sort1_filter").val();
761
                    searched += paron_search_form.find("select[name='sort1_filter']").val();
736
                }
762
                }
737
            }
763
            }
738
            if ( $("#sort2_filter").val() ) {
764
            if ( patron_search_form.find("select[name='sort2_filter']").val() ) {
739
                searched += _(" with sort2 ");
765
                searched += _(" with sort2 ")
740
                if ( $("select#sort2_filter") ) {
766
                if ( patron_search_form.find("select[name='sort2_filter']") ) {
741
                    searched += $("select#sort2_filter").find("option:selected").text();
767
                    searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text();
742
                }
768
                }
743
                else {
769
                else {
744
                    searched += $("#sort2_filter").val();
770
                    searched += paron_search_form.find("select[name='sort2_filter']").val();
745
                }
771
                }
746
            }
772
            }
747
            $("#searchpattern").text(searched);
773
            patron_search_form.find(".searchpattern").text(searched);
748
            $("#searchpattern").parent().show();
774
            patron_search_form.find(".searchpattern").parent().show();
749
        }
775
        }
750
776
751
        function filter() {
777
        function filter() {
778
            let parent_block = $("#[% search_results_block_id | html %]");
779
            let patron_search_form = get_patron_search_form();
752
            [% IF redirect_if_attribute_equal %]
780
            [% IF redirect_if_attribute_equal %]
753
                let filter = $("#search_patron_filter").val();
781
                let filter = patron_search_form.find(".search_patron_filter").val();
754
                if ( filter ) {
782
                if ( filter ) {
755
                    $.ajax({
783
                    $.ajax({
756
                        data: { cardnumber: filter, _match: 'exact' },
784
                        data: { cardnumber: filter, _match: 'exact' },
Lines 771-788 Link Here
771
                    });
799
                    });
772
                }
800
                }
773
            [% END %]
801
            [% END %]
774
            $("#firstletter_filter").val('');
802
            parent_block.find(".firstletter_filter").val('');
775
            $("#[% table_id | html %]_search_results").show();
803
            $("#[% table_id | html %]_search_results").show();
776
804
777
            let table_dt = patrons_table.DataTable();
805
            let table_dt = patrons_table.DataTable();
778
            [% FOR c IN columns %]
806
            [% FOR c IN columns %]
779
                [% SWITCH c %]
807
                [% SWITCH c %]
780
                [% CASE 'branch' %]
808
                [% CASE 'branch' %]
781
                    library_id = $("#branchcode_filter").val() || "";
809
                    let library_id = patron_search_form.find(".branchcode_filter").val() || "";
782
                    patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id);
810
                    patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id);
783
                    table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : '');
811
                    table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : '');
784
                [% CASE 'category' %]
812
                [% CASE 'category' %]
785
                    let category_id = $("#categorycode_filter").val() || "";
813
                    let category_id = patron_search_form.find(".categorycode_filter").val() || "";
786
                    patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id.toLowerCase());
814
                    patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id.toLowerCase());
787
                    table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : '');
815
                    table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : '');
788
                [% END %]
816
                [% END %]
Lines 797-812 Link Here
797
        }
825
        }
798
826
799
        function clearFilters() {
827
        function clearFilters() {
800
            $("#searchfieldstype_filter option:first").prop("selected", true);
828
            let parent_block = $("#[% search_results_block_id | html %]");
801
            $("#searchtype_filter option[value='[% searchtype | html %]']").prop("selected", true);
829
            let patron_search_form = get_patron_search_form();
802
            $("#categorycode_filter option:first").prop("selected", true);
830
            patron_search_form.find(".searchfieldstype_filter option:first").prop("selected", true);
803
            $("#branchcode_filter option:first").prop("selected", true);
831
            patron_search_form.find(".searchtype_filter option[value='[% searchtype | html %]']").prop("selected", true);
804
            $("#sort1_filter").val('').trigger("change");
832
            patron_search_form.find(".categorycode_filter option:first").prop("selected", true);
805
            $("#sort2_filter").val('').trigger("change");
833
            patron_search_form.find(".branchcode_filter option:first").prop("selected", true);
806
            $("#firstletter_filter").val('');
834
            patron_search_form.find("select[name='sort1_filter']").val('').trigger("change");
807
            $("#search_patron_filter").val('');
835
            patron_search_form.find("select[name='sort2_filter']").val('').trigger("change");
808
            /* remove any search string added by firstletter search */
836
            parent_block.find(".firstletter_filter").val('');
809
            history.pushState( {}, null, window.location.href.split("?" )[0]);
837
            patron_search_form.find(".search_patron_filter").val('');
838
            [% IF adjust_history %]
839
                /* remove any search string added by firstletter search */
840
                history.pushState( {}, null, window.location.href.split("?" )[0]);
841
            [% END %]
810
            $("#[% table_id | html %]_search_results").hide();
842
            $("#[% table_id | html %]_search_results").hide();
811
            [% IF display_search_description %]
843
            [% IF display_search_description %]
812
                update_search_description();
844
                update_search_description();
Lines 815-827 Link Here
815
847
816
        // User has clicked on a letter
848
        // User has clicked on a letter
817
        function filterByFirstLetterSurname(letter, setstate ) {
849
        function filterByFirstLetterSurname(letter, setstate ) {
818
            $("#firstletter_filter").val(letter);
850
            let parent_block = $("#[% search_results_block_id | html %]");
851
            parent_block.find(".firstletter_filter").val(letter);
819
852
820
            $("#[% table_id | html %]_search_results").show();
853
            $("#[% table_id | html %]_search_results").show();
821
854
822
            if ( setstate ) {
855
            [% IF adjust_history %]
823
                history.pushState( null, null, "?firstletter=" + letter );
856
                if ( setstate ) {
824
            }
857
                    history.pushState( null, null, "?firstletter=" + letter );
858
                }
859
            [% END %]
825
860
826
            patrons_table.DataTable().draw();
861
            patrons_table.DataTable().draw();
827
            [% IF display_search_description %]
862
            [% IF display_search_description %]
Lines 832-845 Link Here
832
        // modify parent window owner element
867
        // modify parent window owner element
833
        function modal_add_user(borrowernumber, borrowername) {
868
        function modal_add_user(borrowernumber, borrowername) {
834
            [%# Note that add_user could sent data instead of borrowername too %]
869
            [%# Note that add_user could sent data instead of borrowername too %]
835
            $("#info").hide();
870
            let parent_block = $("#[% search_results_block_id | html %]");
836
            $("#error").hide();
871
            parent_block.find(".info").hide();
872
            parent_block.find(".error").hide();
837
            if ( add_user(borrowernumber, borrowername) < 0 ) {
873
            if ( add_user(borrowernumber, borrowername) < 0 ) {
838
                $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
874
                parent_block.find(".error").html(_("Patron '%s' is already in the list.").format(borrowername)).show();
839
                $("#error").show();
840
            } else {
875
            } else {
841
                $("#info").html(_("Patron '%s' added.").format(borrowername));
876
                parent_block.find(".info").html(_("Patron '%s' added.").format(borrowername)).show();
842
                $("#info").show();
843
            }
877
            }
844
        }
878
        }
845
        function modal_select_user(borrowernumber, data) {
879
        function modal_select_user(borrowernumber, data) {
Lines 853-858 Link Here
853
                [% END %]
887
                [% END %]
854
            }
888
            }
855
        }
889
        }
890
    }
856
    </script>
891
    </script>
857
[% END %]
892
[% END %]
858
893
Lines 861-866 Link Here
861
    [% UNLESS patron_search_modal_id %]
896
    [% UNLESS patron_search_modal_id %]
862
        [% patron_search_modal_id = "patron_search_modal" %]
897
        [% patron_search_modal_id = "patron_search_modal" %]
863
    [% END %]
898
    [% END %]
899
    [% UNLESS table_id %]
900
        [% table_id = "memberresultst" %]
901
    [% END %]
902
903
    [% search_results_block_id = patron_search_modal_id _ '_searchresults' %]
904
864
    <div id="[% patron_search_modal_id | html %]" class="modal modal-full" tabindex="-1" role="dialog" aria-labelledby="patronSearchLabel" aria-hidden="true" data-backdrop="">
905
    <div id="[% patron_search_modal_id | html %]" class="modal modal-full" tabindex="-1" role="dialog" aria-labelledby="patronSearchLabel" aria-hidden="true" data-backdrop="">
865
        <div class="modal-dialog" role="document">
906
        <div class="modal-dialog" role="document">
866
            <div class="modal-content">
907
            <div class="modal-content">
Lines 871-877 Link Here
871
                <div class="modal-body">
912
                <div class="modal-body">
872
                    [% PROCESS patron_search_filters filters => ['branch','category','sort1','sort2'] %]
913
                    [% PROCESS patron_search_filters filters => ['branch','category','sort1','sort2'] %]
873
914
874
                    <div id="searchresults">
915
                    <div id="[% search_results_block_id | html %]"> <!-- FIXME removed style from #searchresults, is that bad? -->
875
                        [% IF columns.grep('checkbox').size %]
916
                        [% IF columns.grep('checkbox').size %]
876
                            <div class="searchheader fh-fixedHeader" id="searchheader" style="display:none;">
917
                            <div class="searchheader fh-fixedHeader" id="searchheader" style="display:none;">
877
                                <div>
918
                                <div>
Lines 884-890 Link Here
884
                                </div>
925
                                </div>
885
                            </div>
926
                            </div>
886
                        [% END %]
927
                        [% END %]
887
                        [% PROCESS patron_search_table table_id => 'memberresultst' columns => columns %]
928
                        [% PROCESS patron_search_table table_id => table_id, columns => columns %]
888
                    </div>
929
                    </div>
889
                </div>
930
                </div>
890
                <div class="modal-footer">
931
                <div class="modal-footer">
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc (-1 / +1 lines)
Lines 84-90 Link Here
84
        <select name="searchfieldstype" id="searchfieldstype" class="form-control">
84
        <select name="searchfieldstype" id="searchfieldstype" class="form-control">
85
    [% ELSE %]
85
    [% ELSE %]
86
        <label for="searchfieldstype_filter">Search field:</label>
86
        <label for="searchfieldstype_filter">Search field:</label>
87
        <select name="searchfieldstype" id="searchfieldstype_filter">
87
        <select name="searchfieldstype" class="searchfieldstype_filter">
88
    [% END %]
88
    [% END %]
89
        [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname|middle_name|surname|othernames|cardnumber|userid' %]
89
        [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname|middle_name|surname|othernames|cardnumber|userid' %]
90
        [%# Above is needed for adding fields from the DefaultPatronSearchFields preference to the dropdowns %]
90
        [%# Above is needed for adding fields from the DefaultPatronSearchFields preference to the dropdowns %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (-26 / +11 lines)
Lines 4-9 Link Here
4
[% USE Branches %]
4
[% USE Branches %]
5
[% USE Price %]
5
[% USE Price %]
6
[% PROCESS 'i18n.inc' %]
6
[% PROCESS 'i18n.inc' %]
7
[% PROCESS 'patron-search.inc' %]
7
[% SET footerjs = 1 %]
8
[% SET footerjs = 1 %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
9
10
Lines 344-350 Link Here
344
        [% ELSE %]
345
        [% ELSE %]
345
            <span  id="budget_owner_name"></span>
346
            <span  id="budget_owner_name"></span>
346
        [% END %]
347
        [% END %]
347
        <a id="edit_owner" class="new_window" href="#"><i class="fa fa-search"></i> Select owner</a>
348
        <a id="edit_owner" href="#patron_search_modal_owner" data-toggle="modal"><i class="fa fa-search"></i> Select owner</a>
348
        <a id="remove_owner" href="#"><i class="fa fa-trash-can"></i> Remove owner</a>
349
        <a id="remove_owner" href="#"><i class="fa fa-trash-can"></i> Remove owner</a>
349
        <input type="hidden" name="budget_owner_id" id="budget_owner_id"
350
        <input type="hidden" name="budget_owner_id" id="budget_owner_id"
350
            value="[% budget_owner.borrowernumber | html %]" />
351
            value="[% budget_owner.borrowernumber | html %]" />
Lines 372-378 Link Here
372
                    &bull; <a href="#" class="del_user" data-borrowernumber="[% user.borrowernumber | html %]"><i class="fa fa-trash-can"></i> Remove</a>
373
                    &bull; <a href="#" class="del_user" data-borrowernumber="[% user.borrowernumber | html %]"><i class="fa fa-trash-can"></i> Remove</a>
373
                </li>
374
                </li>
374
            [% END %]
375
            [% END %]
375
            <li><a href="#" id="add_user_button"><i class="fa fa-plus"></i> Add users</a></li>
376
            <li><a href="#patron_search_modal_users" id="add_user_button" data-toggle="modal"><i class="fa fa-plus"></i> Add users</a></li>
376
        </ul>
377
        </ul>
377
        <input type="hidden" name="budget_users_ids" id="budget_users_id" value="[% budget_users_ids | html %]" />
378
        <input type="hidden" name="budget_users_ids" id="budget_users_id" value="[% budget_users_ids | html %]" />
378
    </li>
379
    </li>
Lines 540-561 Link Here
540
        <script>
541
        <script>
541
        //<![CDATA[
542
        //<![CDATA[
542
543
543
            function userPopup() {
544
                window.open("/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add&filter=funds_users",
545
                    'PatronPopup',
546
                    'width=1024,height=768,location=yes,toolbar=no,'
547
                    + 'scrollbars=yes,resize=yes'
548
                );
549
            }
550
551
            function ownerPopup() {
552
                window.open("/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=select&filter=funds_owners",
553
                    'PatronPopup',
554
                    'width=1024,height=768,location=yes,toolbar=no,'
555
                    + 'scrollbars=yes,resize=yes'
556
                );
557
            }
558
559
            function select_user(borrowernumber, borrower) {
544
            function select_user(borrowernumber, borrower) {
560
                ownerRemove();
545
                ownerRemove();
561
                var borrowername = borrower.firstname + ' ' + borrower.surname;
546
                var borrowername = borrower.firstname + ' ' + borrower.surname;
Lines 672-690 Link Here
672
                    e.preventDefault();
657
                    e.preventDefault();
673
                    ownerRemove();
658
                    ownerRemove();
674
                });
659
                });
675
                $("#edit_owner").on("click",function(e){
676
                    e.preventDefault();
677
                    ownerPopup();
678
                });
679
                $("body").on("click",".del_user",function(e){
660
                $("body").on("click",".del_user",function(e){
680
                    e.preventDefault();
661
                    e.preventDefault();
681
                    var borrowernumber = $(this).data("borrowernumber");
662
                    var borrowernumber = $(this).data("borrowernumber");
682
                    del_user(borrowernumber);
663
                    del_user(borrowernumber);
683
                });
664
                });
684
                $("#add_user_button").on("click",function(e){
685
                    e.preventDefault();
686
                    userPopup();
687
                });
688
                $("#edit_fund").on("submit",function(e){
665
                $("#edit_fund").on("submit",function(e){
689
                    e.preventDefault();
666
                    e.preventDefault();
690
                    Check(this);
667
                    Check(this);
Lines 692-697 Link Here
692
            });
669
            });
693
        //]]>
670
        //]]>
694
        </script>
671
        </script>
672
673
        [% INCLUDE 'select2.inc' %]
674
        [% SET columns = ['cardnumber','name','category','branch','action'] %]
675
        [% PROCESS patron_search_modal columns => columns, modal_title => t("Add users"), patron_search_modal_id => 'patron_search_modal_users', table_id => 'patron_search_modal_users_table' %]
676
        [% PROCESS patron_search_js columns => columns, filter => 'funds_users', actions => ["add"], preview_on_name_click => 1, table_id => 'patron_search_modal_users_table' %]
677
        [% PROCESS patron_search_modal columns => columns, modal_title => t("Select owner"), patron_search_modal_id => 'patron_search_modal_owner', table_id => 'patron_search_modal_owner_table' %]
678
        [% PROCESS patron_search_js columns => columns, filter => 'funds_owners', actions => ["select"], preview_on_name_click => 1, table_id => 'patron_search_modal_owner_table' %]
679
695
    [% ELSIF op == 'list' %]
680
    [% ELSIF op == 'list' %]
696
        [% INCLUDE 'datatables.inc' %]
681
        [% INCLUDE 'datatables.inc' %]
697
        [% INCLUDE 'columns_settings.inc' %]
682
        [% INCLUDE 'columns_settings.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt (-6 / +1 lines)
Lines 305-314 Link Here
305
            [% IF branchcode_filter %]
305
            [% IF branchcode_filter %]
306
                $("#branchcode_filter").val("[% branchcode_filter | html %]");
306
                $("#branchcode_filter").val("[% branchcode_filter | html %]");
307
            [% END %]
307
            [% END %]
308
309
            $("#searchheader").hide();
310
            $("#patron_search_form").on('submit', function(){$("#searchheader").show();});
311
            $("#clear_search").on("click",function(e){$("#searchheader").hide();});
312
        });
308
        });
313
309
314
        function patronListAdd(){
310
        function patronListAdd(){
Lines 371-377 Link Here
371
    [% ELSE %]
367
    [% ELSE %]
372
        [% SET redirect_url = '/cgi-bin/koha/members/moremember.pl' %]
368
        [% SET redirect_url = '/cgi-bin/koha/members/moremember.pl' %]
373
    [% END %]
369
    [% END %]
374
    [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, columns => columns,actions => ['edit', 'checkout'], redirect_if_one_result => 1, redirect_url => redirect_url, sticky_header => "searchheader", sticky_to => "searchresults", default_sort_column => 'name-address', display_search_description => 1, remember_selections => 1 %]
370
    [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, columns => columns,actions => ['edit', 'checkout'], redirect_if_one_result => 1, redirect_url => redirect_url, sticky_header => "searchheader", sticky_to => "searchresults", default_sort_column => 'name-address', display_search_description => 1, remember_selections => 1, adjust_history => 1 %]
375
371
376
[% END %]
372
[% END %]
377
[% INCLUDE 'intranet-bottom.inc' %]
373
[% INCLUDE 'intranet-bottom.inc' %]
378
- 

Return to bug 35329