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

Return to bug 35329