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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc (-1 / +1 lines)
Lines 26-32 Link Here
26
                firstname += ' (' + escape_str(patron.other_name) + ')';
26
                firstname += ' (' + escape_str(patron.other_name) + ')';
27
            }
27
            }
28
            if ( config && config.invert_name ) {
28
            if ( config && config.invert_name ) {
29
                name = surname + ', ' + firstname;
29
                name = surname + ( firstname ? ', ' + firstname : '' );
30
            }
30
            }
31
            else {
31
            else {
32
                name = firstname + ' ' + surname;
32
                name = firstname + ' ' + surname;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt (-312 lines)
Lines 1-312 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Koha %]
4
[% USE Branches %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Patron search &rsaquo; Koha</title>
8
[% INCLUDE 'doc-head-close.inc' %]
9
<style> .modal-body .close { display: none; } </style>
10
</head>
11
12
<body id="common_patron_search" class="common">
13
<div id="patron_search" class="yui-t7">
14
    <div class="container-fluid">
15
16
        <form id="searchform">
17
            <fieldset class="brief">
18
                <h3>Search for patron</h3>
19
                <ol>
20
                    <li>
21
                        <label for="searchmember_filter">Search:</label>
22
                        <input type="text" id="searchmember_filter" value="[% searchmember | html %]" class="focus" />
23
                    </li>
24
                    <li>
25
                        <label for="categorycode_filter">Category:</label>
26
                        <select id="categorycode_filter">
27
                            <option value="">Any</option>
28
                            [% FOREACH category IN categories %]
29
                                <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
30
                            [% END %]
31
                        </select>
32
                    </li>
33
                    <li>
34
                        <label for="branchcode_filter">Library:</label>
35
                        <select id="branchcode_filter">
36
                            [% SET libraries = Branches.all( only_from_group => 1 ) %]
37
                            [% IF libraries.size != 1 %]
38
                                <option value="">Any</option>
39
                            [% END %]
40
                            [% FOREACH l IN libraries %]
41
                                <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
42
                            [% END %]
43
                        </select>
44
                    </li>
45
                </ol>
46
                <fieldset class="action">
47
                    <input type="submit" value="Search" />
48
                </fieldset>
49
            </fieldset>
50
        </form>
51
52
        [% IF patrons_with_acq_perm_only %]
53
            <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div>
54
        [% END %]
55
56
        [% IF patrons_with_suggestion_perm_only %]
57
            <div class="hint">Only staff with superlibrarian or suggestions_manage permissions are returned in the search results</div>
58
        [% END %]
59
60
        <div class="browse">
61
            Browse by last name:
62
            [% FOREACH letter IN alphabet.split(' ') %]
63
                <a href="#" class="filterByLetter">[% letter | html %]</a>
64
            [% END %]
65
        </div>
66
67
        <div id="info" class="dialog message"></div>
68
        <div id="error" class="dialog alert"></div>
69
70
        <input type="hidden" id="firstletter_filter" value="" />
71
        <div id="searchresults">
72
            <table id="memberresultst">
73
                <thead>
74
                    <tr>
75
                        [% FOR column IN columns %]
76
                            [% SWITCH column %]
77
                                [% CASE 'cardnumber' %]<th>Card</th>
78
                                [% CASE 'dateofbirth' %]<th>Date of birth</th>
79
                                [% CASE 'address' %]<th>Address</th>
80
                                [% CASE 'name' %]<th>Name</th>
81
                                [% CASE 'branch' %]<th>Library</th>
82
                                [% CASE 'category' %]<th>Category</th>
83
                                [% CASE 'dateexpiry' %]<th>Expires on</td>
84
                                [% CASE 'borrowernotes' %]<th>Notes</th>
85
                                [% CASE 'action' %]<th>&nbsp;</th>
86
                            [% END %]
87
                        [% END %]
88
                    </tr>
89
                  </thead>
90
                <tbody></tbody>
91
            </table>
92
        </div>
93
94
<div id="closewindow"><a href="#" class="btn btn-default btn-default close">Close</a></div>
95
96
<!-- Patron preview modal -->
97
<div class="modal" id="patronPreview" tabindex="-1" role="dialog" aria-labelledby="patronPreviewLabel">
98
    <div class="modal-dialog" role="document">
99
        <div class="modal-content">
100
            <div class="modal-header">
101
                <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
102
                <h4 class="modal-title" id="patronPreviewLabel"></h4>
103
            </div>
104
            <div class="modal-body">
105
                <div id="loading">
106
                    <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading
107
                </div>
108
            </div>
109
            <div class="modal-footer">
110
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
111
            </div>
112
        </div>
113
    </div>
114
</div>
115
116
</div>
117
</div>
118
119
[% MACRO jsinclude BLOCK %]
120
    [% INCLUDE 'datatables.inc' %]
121
122
    <script>
123
        var search = 1;
124
        $(document).ready(function(){
125
            $("#info").hide();
126
            $("#error").hide();
127
128
            [% IF view != "show_results" %]
129
                $("#searchresults").hide();
130
                search = 0;
131
            [% END %]
132
133
            // Apply DataTables on the results table
134
            dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
135
                'bServerSide': true,
136
                'sAjaxSource': "/cgi-bin/koha/svc/members/search",
137
                'fnServerData': function(sSource, aoData, fnCallback) {
138
                    if ( ! search ) {
139
                        return;
140
                    }
141
                    aoData.push({
142
                        'name': 'searchmember',
143
                        'value': $("#searchmember_filter").val()
144
                    },{
145
                        'name': 'firstletter',
146
                        'value': $("#firstletter_filter").val()
147
                    },{
148
                        'name': 'categorycode',
149
                        'value': $("#categorycode_filter").val()
150
                    },{
151
                        'name': 'branchcode',
152
                        'value': $("#branchcode_filter").val()
153
                    },{
154
                        'name': 'name_sorton',
155
                        'value': 'borrowers.surname borrowers.firstname'
156
                    },{
157
                        'name': 'cardnumber_sorton',
158
                        'value': 'borrowers.cardnumber',
159
                    },{
160
                        'name': 'dateofbirth_sorton',
161
                        'value': 'borrowers.dateofbirth',
162
                    },{
163
                        'name': 'dateexpiry_sorton',
164
                        'value': 'borrowers.dateexpiry',
165
                    },{
166
                        'name': 'category_sorton',
167
                        'value': 'categories.description',
168
                    },{
169
                        'name': 'branch_sorton',
170
                        'value': 'branches.branchname'
171
                    },{
172
                        'name': 'borrowernotes_sorton',
173
                        'value': 'borrowers.borrowernotes'
174
                    },{
175
                        'name': 'template_path',
176
                        'value': '[% json_template | html %]',
177
                    },{
178
                        'name': 'selection_type',
179
                        'value': '[% selection_type | html %]',
180
                    }
181
                    [% IF patrons_with_acq_perm_only %]
182
                    ,{
183
                        'name': 'has_permission',
184
                        'value': 'acquisition.order_manage',
185
                    }
186
                    [% ELSIF patrons_with_suggestion_perm_only %]
187
                    ,{
188
                        'name': 'has_permission',
189
                        'value': 'suggestions.suggestions_manage',
190
                    }
191
                    [% END %]
192
                    );
193
                    $.ajax({
194
                        'dataType': 'json',
195
                        'type': 'POST',
196
                        'url': sSource,
197
                        'data': aoData,
198
                        'success': function(json){
199
                            fnCallback(json);
200
                        }
201
                    });
202
                },
203
                'aoColumns':[
204
                    [% FOR column IN columns %]
205
                        [% IF column == 'action' %]
206
                            { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
207
                        [% ELSIF column == 'address' %]
208
                            { 'mDataProp': 'dt_address', 'bSortable': false }
209
                        [% ELSE %]
210
                            { 'mDataProp': 'dt_[% column | html %]' }
211
                        [% END %]
212
                        [% UNLESS loop.last %],[% END %]
213
                    [% END %]
214
                ],
215
                'bAutoWidth': false,
216
                'sPaginationType': 'full_numbers',
217
                "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
218
                'aaSorting': [[[% aaSorting || 0 | html %], 'asc']],
219
                'bFilter': false,
220
                'bProcessing': true,
221
            }));
222
223
            $("#searchform").on('submit', filter);
224
            $(".filterByLetter").on("click",function(e){
225
                e.preventDefault();
226
                filterByFirstLetterSurname($(this).text());
227
            });
228
            $("body").on("click",".add_user",function(e){
229
                e.preventDefault();
230
                var borrowernumber = $(this).data("borrowernumber");
231
                var firstname = $(this).data("firstname");
232
                var surname = $(this).data("surname");
233
                add_user( borrowernumber, firstname + " " + surname );
234
            });
235
236
            $("body").on("click",".select_user",function(e){
237
                e.preventDefault();
238
                var borrowernumber = $(this).data("borrowernumber");
239
                var borrower_data = $("#borrower_data"+borrowernumber).val();
240
                select_user( borrowernumber, JSON.parse(borrower_data) );
241
            });
242
243
            $("body").on("click",".patron_preview", function( e ){
244
                e.preventDefault();
245
                var borrowernumber = $(this).data("borrowernumber");
246
                var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
247
                $("#patronPreview .modal-body").load( page + " div.container-fluid" );
248
                $('#patronPreview').modal({show:true});
249
            });
250
251
            $("#patronPreview").on('hidden.bs.modal', function (e) {
252
                $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
253
            });
254
255
        });
256
257
        function filter() {
258
            search = 1;
259
            $("#firstletter_filter").val('');
260
            $("#searchresults").show();
261
            dtMemberResults.fnDraw();
262
            return false;
263
        }
264
265
        // User has clicked on a letter
266
        function filterByFirstLetterSurname(letter) {
267
            $("#firstletter_filter").val(letter);
268
            search = 1;
269
            $("#searchresults").show();
270
            dtMemberResults.fnDraw();
271
        }
272
273
        // modify parent window owner element
274
        [% IF selection_type == 'add' %]
275
            function add_user(borrowernumber, borrowername) {
276
                var p = window.opener;
277
                // In one place (serials/routing.tt), the page is reload on every add
278
                // We have to wait for the page to be there
279
                function wait_for_opener () {
280
                    if ( ! $(opener.document).find('body').size() ) {
281
                        setTimeout(wait_for_opener, 500);
282
                    } else {
283
                        [%# Note that add_user could sent data instead of borrowername too %]
284
                        $("#info").hide();
285
                        $("#error").hide();
286
                        if ( p.add_user(borrowernumber, borrowername) < 0 ) {
287
                            $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
288
                            $("#error").show();
289
                        } else {
290
                            $("#info").html(_("Patron '%s' added.").format(borrowername));
291
                            $("#info").show();
292
                        }
293
                    }
294
                }
295
                wait_for_opener();
296
            }
297
        [% ELSIF selection_type == 'select' %]
298
            function select_user(borrowernumber, data) {
299
                var p = window.opener;
300
                [%  IF callback %]
301
                    p.[% callback | html %](borrowernumber, data);
302
                [%  ELSE %]
303
                    p.select_user(borrowernumber, data);
304
                [%  END %]
305
                window.close();
306
            }
307
        [% END %]
308
    </script>
309
[% END %]
310
311
[% SET popup_window = 1 %]
312
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt (+368 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE To %]
3
[% USE Asset %]
4
[% USE Koha %]
5
[% USE Branches %]
6
[% USE Categories %]
7
[% SET footerjs = 1 %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
[% SET libraries = Branches.all %]
10
[% SET categories = Categories.all.unblessed %]
11
<title>Patron search &rsaquo; Koha</title>
12
[% INCLUDE 'doc-head-close.inc' %]
13
<style> .modal-body .close { display: none; } </style>
14
</head>
15
16
<body id="common_patron_search" class="common">
17
<div id="patron_search" class="yui-t7">
18
    <div class="container-fluid">
19
20
        <form id="searchform">
21
            <fieldset class="brief">
22
                <h3>Search for patron</h3>
23
                <ol>
24
                    <li>
25
                        <label for="searchmember_filter">Search:</label>
26
                        <input type="text" id="searchmember_filter" value="[% searchmember | html %]" class="focus" />
27
                    </li>
28
29
                    [% FOR column IN columns %]
30
                        [% SWITCH column %]
31
                        [% CASE 'branch' %]
32
                            <li>
33
                                <label for="branchcode_filter">Library:</label>
34
                                <select id="branchcode_filter">
35
                                    [% SET libraries = Branches.all( only_from_group => 1 ) %]
36
                                    [% IF libraries.size != 1 %]
37
                                        <option value="">Any</option>
38
                                    [% END %]
39
                                    [% FOREACH l IN libraries %]
40
                                        <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
41
                                    [% END %]
42
                                </select>
43
                            </li>
44
                        [% CASE 'category' %]
45
                            <li>
46
                                <label for="categorycode_filter">Category:</label>
47
                                <select id="categorycode_filter">
48
                                    <option value="">Any</option>
49
                                    [% FOREACH category IN categories %]
50
                                        <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
51
                                    [% END %]
52
                                </select>
53
                            </li>
54
                        [% END %]
55
                    [% END %]
56
                </ol>
57
                <fieldset class="action">
58
                    <input type="submit" value="Search" />
59
                </fieldset>
60
            </fieldset>
61
        </form>
62
63
        [% IF patrons_with_acq_perm_only %]
64
            <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div>
65
        [% END %]
66
67
        [% IF patrons_with_suggestion_perm_only %]
68
            <div class="hint">Only staff with superlibrarian or suggestions_manage permissions are returned in the search results</div>
69
        [% END %]
70
71
        <div class="browse">
72
            Browse by last name:
73
            [% FOREACH letter IN alphabet.split(' ') %]
74
                <a href="#" class="filterByLetter">[% letter | html %]</a>
75
            [% END %]
76
        </div>
77
78
        <div id="info" class="dialog message"></div>
79
        <div id="error" class="dialog alert"></div>
80
81
        <input type="hidden" id="firstletter_filter" value="" />
82
        <div id="searchresults">
83
            <table id="memberresultst">
84
                <thead>
85
                    <tr>
86
                        [% FOR column IN columns %]
87
                            [% SWITCH column %]
88
                                [% CASE 'cardnumber' %]<th>Card</th>
89
                                [% CASE 'dateofbirth' %]<th>Date of birth</th>
90
                                [% CASE 'address' %]<th>Address</th>
91
                                [% CASE 'name' %]<th>Name</th>
92
                                [% CASE 'branch' %]<th data-filter="libraries">Library</th>
93
                                [% CASE 'category' %]<th data-filter="categories">Category</th>
94
                                [% CASE 'dateexpiry' %]<th>Expires on</td>
95
                                [% CASE 'borrowernotes' %]<th>Notes</th>
96
                                [% CASE 'action' %]<th>&nbsp;</th>
97
                            [% END %]
98
                        [% END %]
99
                    </tr>
100
                  </thead>
101
                <tbody></tbody>
102
            </table>
103
        </div>
104
105
<div id="closewindow"><a href="#" class="btn btn-default btn-default close">Close</a></div>
106
107
<!-- Patron preview modal -->
108
<div class="modal" id="patronPreview" tabindex="-1" role="dialog" aria-labelledby="patronPreviewLabel">
109
    <div class="modal-dialog" role="document">
110
        <div class="modal-content">
111
            <div class="modal-header">
112
                <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
113
                <h4 class="modal-title" id="patronPreviewLabel"></h4>
114
            </div>
115
            <div class="modal-body">
116
                <div id="loading">
117
                    <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading
118
                </div>
119
            </div>
120
            <div class="modal-footer">
121
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
122
            </div>
123
        </div>
124
    </div>
125
</div>
126
127
</div>
128
</div>
129
130
[% MACRO jsinclude BLOCK %]
131
    <script>
132
        let categories = [% To.json(categories) | $raw %];
133
        let categories_map = categories.reduce((map, c) => {
134
            map[c.categorycode] = c;
135
            return map;
136
        }, {});
137
        let libraries  = [% To.json(libraries) | $raw %];
138
        let libraries_map = libraries.reduce((map, l) => {
139
            map[l.branchcode] = l;
140
            return map;
141
        }, {});
142
    </script>
143
    [% INCLUDE 'datatables.inc' %]
144
    [% INCLUDE 'js-date-format.inc' %]
145
    [% INCLUDE 'js-patron-get-age.inc' %]
146
    [% INCLUDE 'js-patron-format.inc' %]
147
    [% INCLUDE 'js-patron-format-address.inc' %]
148
149
    <script>
150
        var search = 0;
151
        let patrons_table;
152
        $(document).ready(function(){
153
            $("#info").hide();
154
            $("#error").hide();
155
156
            $("#searchresults").hide();
157
158
            let additional_filters = {
159
                surname: function(){
160
                    let start_with = $("#firstletter_filter").val()
161
                    if (!start_with) return "";
162
                    return { "like": start_with + "%" }
163
                }
164
            };
165
            patrons_table = $("#memberresultst").kohaTable({
166
                "ajax": {
167
                    "url": '/api/v1/patrons'
168
                },
169
                "order": [[ 1, "asc" ]],
170
                "iDeferLoading": 0,
171
                "columns": [
172
                    [% FOR column IN columns %]
173
                        [% SWITCH column %]
174
                            [% CASE 'cardnumber' %]
175
                            {
176
                                "data": "cardnumber",
177
                                "searchable": true,
178
                                "orderable": true
179
                            }
180
                            [% CASE 'dateofbirth' %]
181
                            {
182
                                "data": "date_of_birth",
183
                                "searchable": true,
184
                                "orderable": true,
185
                                "render": function( data, type, row, meta ) {
186
                                    return data ? escape_str($date(data) + " (" + _("%s years").format($get_age(data)) + ")") : "";
187
                                }
188
                            }
189
                            [% CASE 'address' %]
190
                            {
191
                                "data": "me.street_number:me.address:me.address2:me.city:me.state:me.postal_code:me.country",
192
                                "searchable": true,
193
                                "orderable": true,
194
                                "render": function( data, type, row, meta ) {
195
                                    return escape_str($format_address(row) + " ") + escape_str(libraries_map[row.library_id].branchname);
196
                                }
197
                            }
198
                            [% CASE 'name' %]
199
                            {
200
                                "data": "me.firstname:me.surname",
201
                                "searchable": true,
202
                                "orderable": true,
203
                                "render": function( data, type, row, meta ) {
204
                                    return $patron_to_html(row, { invert_name: 1 });
205
                                }
206
                            }
207
                            [% CASE 'branch' %]
208
                            {
209
                                "data": "library_id",
210
                                "searchable": true,
211
                                "orderable": true,
212
                                "render": function( data, type, row, meta ) {
213
                                    return escape_str(libraries_map[data].branchname);
214
                                }
215
                            }
216
                            [% CASE 'category' %]
217
                            {
218
                                "data": "category_id",
219
                                "searchable": true,
220
                                "orderable": true,
221
                                "render": function( data, type, row, meta ) {
222
                                    return escape_str(categories_map[data].description);
223
                                }
224
                            }
225
                            [% CASE 'dateexpiry' %]
226
                            {
227
                                "data": "expiry_date",
228
                                "searchable": true,
229
                                "orderable": true,
230
                                "render": function( data, type, row, meta ) {
231
                                    return data ? escape_str($date(data)) : "";
232
                                }
233
                            }
234
                            [% CASE 'borrowernotes' %]
235
                            {
236
                                "data": "staff_notes",
237
                                "searchable": true,
238
                                "orderable": true,
239
                                [%# We don't escape here, we allow html tag in staff notes %]
240
                            }
241
                            [% CASE 'action' %]
242
                            {
243
                                "data": function( row, type, val, meta ) {
244
245
                                    let patron_id = encodeURIComponent(row.patron_id);
246
                                    [% IF selection_type == 'select' %]
247
                                        return '<a href="#" class="btn btn-default btn-xs select_user" data-borrowernumber="' + patron_id + '">Select</a><input type="hidden" id="borrower_data' + patron_id + '" name="borrower_data'+ patron_id + '" value=\''+JSON.stringify(row)+'\' />';
248
                                    [% ELSE %]
249
                                        return '<a href="#" class="btn btn-default btn-xs add_user" data-borrowernumber="' + patron_id + '" data-firstname="' + encodeURIComponent(row.firstname) + '" data-surname="' + encodeURIComponent(row.surname) + '">Add</a><input type="hidden" id="borrower_data' + patron_id + '" name="borrower_data'+ patron_id + '" />';
250
                                    [% END %]
251
                                },
252
                                "searchable": false,
253
                                "orderable": false
254
                            }
255
                        [% END %]
256
                        [% UNLESS loop.last %],[% END %]
257
                    [% END %]
258
                ],
259
                'bAutoWidth': false,
260
                'sPaginationType': 'full_numbers',
261
                "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
262
            }, null, 1, additional_filters);
263
264
            $("#searchform").on('submit', filter);
265
            $(".filterByLetter").on("click",function(e){
266
                e.preventDefault();
267
                filterByFirstLetterSurname($(this).text());
268
            });
269
            $("body").on("click",".add_user",function(e){
270
                e.preventDefault();
271
                var borrowernumber = $(this).data("borrowernumber");
272
                var firstname = $(this).data("firstname");
273
                var surname = $(this).data("surname");
274
                add_user( borrowernumber, firstname + " " + surname );
275
            });
276
277
            $("body").on("click",".select_user",function(e){
278
                e.preventDefault();
279
                var borrowernumber = $(this).data("borrowernumber");
280
                var borrower_data = $("#borrower_data"+borrowernumber).val();
281
                select_user( borrowernumber, JSON.parse(borrower_data) );
282
            });
283
284
            $("body").on("click",".patron_preview", function( e ){
285
                e.preventDefault();
286
                var borrowernumber = $(this).data("borrowernumber");
287
                var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
288
                $("#patronPreview .modal-body").load( page + " div.container-fluid" );
289
                $('#patronPreview').modal({show:true});
290
            });
291
292
            $("#patronPreview").on('hidden.bs.modal', function (e) {
293
                $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
294
            });
295
296
        });
297
298
        function filter() {
299
            search = 1;
300
            $("#firstletter_filter").val('');
301
            $("#searchresults").show();
302
303
            let table_dt = patrons_table.DataTable();
304
            [% FOR c IN columns %]
305
                [% SWITCH c %]
306
                [% CASE 'branch' %]
307
                    let library_id = $("#branchcode_filter").val();
308
                    patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id);
309
                    table_dt.column([% loop.count - 1 %]).search(library_id);
310
                [% CASE 'category' %]
311
                    let category_id = $("#categorycode_filter").val();
312
                    patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id);
313
                    table_dt.column([% loop.count - 1 %]).search(category_id);
314
                [% END %]
315
            [% END %]
316
            table_dt.search($("#searchmember_filter").val());
317
            table_dt.draw();
318
            return false;
319
        }
320
321
        // User has clicked on a letter
322
        function filterByFirstLetterSurname(letter) {
323
            $("#firstletter_filter").val(letter);
324
            search = 1;
325
            $("#searchresults").show();
326
            patrons_table.fnDraw();
327
        }
328
329
        // modify parent window owner element
330
        [% IF selection_type == 'add' %]
331
            function add_user(borrowernumber, borrowername) {
332
                var p = window.opener;
333
                // In one place (serials/routing.tt), the page is reload on every add
334
                // We have to wait for the page to be there
335
                function wait_for_opener () {
336
                    if ( ! $(opener.document).find('body').size() ) {
337
                        setTimeout(wait_for_opener, 500);
338
                    } else {
339
                        [%# Note that add_user could sent data instead of borrowername too %]
340
                        $("#info").hide();
341
                        $("#error").hide();
342
                        if ( p.add_user(borrowernumber, borrowername) < 0 ) {
343
                            $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
344
                            $("#error").show();
345
                        } else {
346
                            $("#info").html(_("Patron '%s' added.").format(borrowername));
347
                            $("#info").show();
348
                        }
349
                    }
350
                }
351
                wait_for_opener();
352
            }
353
        [% ELSIF selection_type == 'select' %]
354
            function select_user(borrowernumber, data) {
355
                var p = window.opener;
356
                [%  IF callback %]
357
                    p.[% callback | html %](borrowernumber, data);
358
                [%  ELSE %]
359
                    p.select_user(borrowernumber, data);
360
                [%  END %]
361
                window.close();
362
            }
363
        [% END %]
364
    </script>
365
[% END %]
366
367
[% SET popup_window = 1 %]
368
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt (-36 lines)
Lines 1-36 Link Here
1
[% USE raw %]
2
[% USE To %]
3
[% USE Branches %]
4
[% USE KohaDates %]
5
{
6
    "sEcho": [% sEcho | html %],
7
    "iTotalRecords": [% iTotalRecords | html %],
8
    "iTotalDisplayRecords": [% iTotalDisplayRecords | html %],
9
    "aaData": [
10
        [% FOREACH data IN aaData %]
11
            {
12
                "dt_cardnumber":
13
                    "[% data.cardnumber | html %]",
14
                "dt_name":
15
                    "[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames cardnumber = data.cardnumber invert_name = 1%]",
16
                "dt_dateofbirth":
17
                    "[% INCLUDE 'patron-age.inc' patron = data %]",
18
                "dt_address":
19
                    "[% INCLUDE escape_address data=data %]",
20
                "dt_action":
21
                    "<a href=\"#\" class=\"btn btn-default btn-xs select_user\" data-borrowernumber=\"[% data.borrowernumber | html %]\">Select</a><input type=\"hidden\" id=\"borrower_data[% data.borrowernumber | html %]\" name=\"borrower_data[% data.borrowernumber | html %]\" value=\"[% To.json(data) | html %]\" />"
22
            }[% UNLESS loop.last %],[% END %]
23
        [% END %]
24
    ]
25
}
26
[% BLOCK escape_address %]
27
[%~ SET address = data.streetnumber _ ' ' %]
28
[%~ IF data.address %][% SET address = address _ data.address _ ' ' %][% END %]
29
[%~ IF data.address2 %][% SET address = address _ data.address2 _ ' ' %][% END %]
30
[%~ IF data.city %][% SET address = address _ data.city _ ' ' %][% END %]
31
[%~ IF data.state %][% SET address = address _ data.state _ ' ' %][% END %]
32
[%~ IF data.zipcode %][% SET address = address _ data.zipcode _ ' ' %][% END %]
33
[%~ IF data.country %][% SET address = address _ data.country _ ' ' %][% END %]
34
[%~ SET address = address _ Branches.GetName( data.branchcode ) %]
35
[%~ address | html | $To ~%]
36
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-8 / +55 lines)
Lines 602-608 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
602
                                });
602
                                });
603
603
604
                                if ( default_filters ) {
604
                                if ( default_filters ) {
605
                                    and_query_parameters.push(default_filters);
605
                                    let additional_filters = {};
606
                                    for ( f in default_filters ) {
607
                                        if ( typeof(default_filters[f]) === 'function' ) {
608
                                            let val = default_filters[f]();
609
                                            if ( val != undefined && val != "" ) {
610
                                                additional_filters[f] = val;
611
                                            }
612
                                        } else {
613
                                            additional_filters[f] = default_filters[f];
614
                                        }
615
                                    }
616
                                    if ( Object.keys(additional_filters).length ) {
617
                                        and_query_parameters.push(additional_filters);
618
                                    }
606
                                }
619
                                }
607
                                query_parameters = and_query_parameters;
620
                                query_parameters = and_query_parameters;
608
                                if ( or_query_parameters.length) {
621
                                if ( or_query_parameters.length) {
Lines 778-793 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
778
            $(this).find('thead tr:eq(1) th').each( function (i) {
791
            $(this).find('thead tr:eq(1) th').each( function (i) {
779
                var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable;
792
                var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable;
780
                if ( is_searchable ) {
793
                if ( is_searchable ) {
781
                    var title = $(this).text();
794
                    let input_type = 'input';
782
                    var existing_search = table_dt.column(i).search();
795
                    if ( $(this).data('filter') ) {
783
                    if ( existing_search ) {
796
                        input_type = 'select'
784
                        $(this).html( '<input type="text" value="%s" style="width: 100%" />'.format(existing_search) );
797
                        let filter_type = $(this).data('filter');
798
                        if ( filter_type == 'libraries' ) {
799
                            var existing_search = table_dt.column(i).search();
800
                            let select = $('<select><option value=""></option></select');
801
802
                            $(libraries).each(function(){
803
                                let o = $('<option value="%s">%s</option>'.format(this.branchcode, this.branchname));
804
                                if ( existing_search == this.branchcode ) {
805
                                    o.prop("selected", "selected");
806
                                }
807
                                o.appendTo(select);
808
                            });
809
                            $(this).html( select );
810
                        } else if ( filter_type == 'categories' ) {
811
                            var existing_search = table_dt.column(i).search();
812
                            let select = $('<select><option value=""></option></select');
813
814
                            $(categories).each(function(){
815
                                let o = $('<option value="%s">%s</option>'.format(this.categorycode, this.description));
816
                                if ( existing_search == this.categorycode ) {
817
                                    o.prop("selected", "selected");
818
                                }
819
                                o.appendTo(select);
820
                            });
821
                            $(this).html( select );
822
                        } else {
823
                            console.log("Unknown filter " + filter_type);
824
                            return;
825
                        }
785
                    } else {
826
                    } else {
786
                        var search_title = _("%s search").format(title);
827
                        var title = $(this).text();
787
                        $(this).html( '<input type="text" placeholder="%s" style="width: 100%" />'.format(search_title) );
828
                        var existing_search = table_dt.column(i).search();
829
                        if ( existing_search ) {
830
                            $(this).html( '<input type="text" value="%s" style="width: 100%" />'.format(existing_search) );
831
                        } else {
832
                            var search_title = _("%s search").format(title);
833
                            $(this).html( '<input type="text" placeholder="%s" style="width: 100%" />'.format(search_title) );
834
                        }
788
                    }
835
                    }
789
836
790
                    $( 'input', this ).on( 'keyup change', function () {
837
                    $( input_type, this ).on( 'keyup change', function () {
791
                        if ( table_dt.column(i).search() !== this.value ) {
838
                        if ( table_dt.column(i).search() !== this.value ) {
792
                            table_dt
839
                            table_dt
793
                                .column(i)
840
                                .column(i)
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (-4 / +4 lines)
Lines 77-88 function update_category_code(category_code) { Link Here
77
}
77
}
78
78
79
function select_user(borrowernumber, borrower, relationship) {
79
function select_user(borrowernumber, borrower, relationship) {
80
    let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrower.borrowernumber}]`).length;
80
    let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrowernumber}]`).length;
81
81
82
    if ( is_guarantor ) {
82
    if ( is_guarantor ) {
83
        alert("Patron is already a guarantor for this patron");
83
        alert("Patron is already a guarantor for this patron");
84
    } else {
84
    } else {
85
        $('#guarantor_id').val(borrower.borrowernumber);
85
        $('#guarantor_id').val(borrowernumber);
86
        $('#guarantor_surname').val(borrower.surname);
86
        $('#guarantor_surname').val(borrower.surname);
87
        $('#guarantor_firstname').val(borrower.firstname);
87
        $('#guarantor_firstname').val(borrower.firstname);
88
88
Lines 113-119 function select_user(borrowernumber, borrower, relationship) { Link Here
113
        fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship );
113
        fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship );
114
        $('#relationship').find('option:eq(0)').prop('selected', true);
114
        $('#relationship').find('option:eq(0)').prop('selected', true);
115
115
116
        fieldset.find('.guarantor-details').first().attr( 'data-borrowernumber', borrower.borrowernumber );
116
        fieldset.find('.guarantor-details').first().attr( 'data-borrowernumber', borrowernumber );
117
117
118
        $('#guarantor_relationships').append( fieldset );
118
        $('#guarantor_relationships').append( fieldset );
119
        fieldset.show();
119
        fieldset.show();
Lines 197-203 $(document).ready(function(){ Link Here
197
197
198
    $('body').on('click', '#guarantor_search', function(e) {
198
    $('body').on('click', '#guarantor_search', function(e) {
199
        e.preventDefault();
199
        e.preventDefault();
200
        var newin = window.open('guarantor_search.pl','popup','width=800,height=600,resizable=no,toolbar=false,scrollbars=yes,top');
200
        var newin = window.open('/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,dateofbirth,address,action','popup','width=800,height=600,resizable=no,toolbar=false,scrollbars=yes,top');
201
    });
201
    });
202
202
203
    $('#guarantor_relationships').on('click', '.guarantor_cancel', function(e) {
203
    $('#guarantor_relationships').on('click', '.guarantor_cancel', function(e) {
(-)a/members/guarantor_search.pl (-18 / +5 lines)
Lines 2-9 Link Here
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
5
# Copyright 2014 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
5
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
6
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
7
# the Free Software Foundation; either version 3 of the License, or
Lines 22-56 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
23
use C4::Auth qw( get_template_and_user );
21
use C4::Auth qw( get_template_and_user );
24
use C4::Output qw( output_html_with_http_headers );
22
use C4::Output qw( output_html_with_http_headers );
25
use C4::Members;
26
27
use Koha::Patron::Categories;
28
23
29
my $input = CGI->new;
24
my $input = CGI->new;
30
25
31
my $dbh = C4::Context->dbh;
32
33
my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
26
my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
34
    {   template_name   => "common/patron_search.tt",
27
    {   template_name   => "members/search.tt",
35
        query           => $input,
28
        query           => $input,
36
        type            => "intranet",
29
        type            => "intranet",
37
        flagsrequired   => { borrowers => 'edit_borrowers' },
30
        flagsrequired   => { catalogue => '*' },
38
    }
31
    }
39
);
32
);
40
33
41
my $q = $input->param('q') || '';
42
my $op = $input->param('op') || '';
43
44
my $referer = $input->referer();
34
my $referer = $input->referer();
45
35
46
my $patron_categories = Koha::Patron::Categories->search_with_library_limits;
36
my @columns = split ',', $input->param('columns');
37
47
$template->param(
38
$template->param(
48
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
39
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
49
    columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ],
40
    columns => \@columns,
50
    json_template => 'members/tables/guarantor_search.tt',
51
    selection_type => 'select',
41
    selection_type => 'select',
52
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
42
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
53
    categories      => $patron_categories,
54
    aaSorting       => 1,
55
);
43
);
56
output_html_with_http_headers( $input, $cookie, $template->output );
44
output_html_with_http_headers( $input, $cookie, $template->output );
57
- 

Return to bug 30055