Bug 23590: Only return patrons that have the suggestions_manage permission
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / common / patron_search.tt
blob19cd0ab9527a06c02726a89c49172c0033927ff5
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE Branches %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Koha &rsaquo; Patron search</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 <style> .modal-body .close { display: none; } </style>
10 </head>
12 <body id="common_patron_search" class="common">
13 <div id="patron_search" class="yui-t7">
14     <div class="container-fluid">
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 %]"/>
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>
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 %]
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 %]
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>
67         <div id="info" class="dialog message"></div>
68         <div id="error" class="dialog alert"></div>
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>
94 <div id="closewindow"><a href="#" class="btn btn-default btn-default close">Close</a></div>
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>
116 </div>
117 </div>
119 [% MACRO jsinclude BLOCK %]
120     [% INCLUDE 'datatables.inc' %]
122     <script type="text/javascript">
123         var search = 1;
124         $(document).ready(function(){
125             $("#info").hide();
126             $("#error").hide();
128             [% IF view != "show_results" %]
129                 $("#searchresults").hide();
130                 search = 0;
131             [% END %]
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': 'category_sorton',
158                         'value': 'categories.description',
159                     },{
160                         'name': 'branch_sorton',
161                         'value': 'branches.branchname'
162                     },{
163                         'name': 'template_path',
164                         'value': '[% json_template | html %]',
165                     },{
166                         'name': 'selection_type',
167                         'value': '[% selection_type | html %]',
168                     }
169                     [% IF patrons_with_acq_perm_only %]
170                     ,{
171                         'name': 'has_permission',
172                         'value': 'acquisition.order_manage',
173                     }
174                     [% ELSIF patrons_with_suggestion_perm_only %]
175                     ,{
176                         'name': 'has_permission',
177                         'value': 'acquisition.suggestions_manage',
178                     }
179                     [% END %]
180                     );
181                     $.ajax({
182                         'dataType': 'json',
183                         'type': 'POST',
184                         'url': sSource,
185                         'data': aoData,
186                         'success': function(json){
187                             fnCallback(json);
188                         }
189                     });
190                 },
191                 'aoColumns':[
192                     [% FOR column IN columns %]
193                         [% IF column == 'action' %]
194                             { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
195                         [% ELSIF column == 'address' %]
196                             { 'mDataProp': 'dt_address', 'bSortable': false }
197                         [% ELSE %]
198                             { 'mDataProp': 'dt_[% column | html %]' }
199                         [% END %]
200                         [% UNLESS loop.last %],[% END %]
201                     [% END %]
202                 ],
203                 'bAutoWidth': false,
204                 [% IF patrons_with_acq_perm_only %]
205                     'bPaginate': false,
206                 [% ELSE %]
207                     'sPaginationType': 'full_numbers',
208                     "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
209                 [% END %]
210                 'aaSorting': [[[% aaSorting || 0 | html %], 'asc']],
211                 'bFilter': false,
212                 'bProcessing': true,
213             }));
215             $("#searchform").on('submit', filter);
216             $(".filterByLetter").on("click",function(e){
217                 e.preventDefault();
218                 filterByFirstLetterSurname($(this).text());
219             });
220             $("body").on("click",".add_user",function(e){
221                 e.preventDefault();
222                 var borrowernumber = $(this).data("borrowernumber");
223                 var firstname = $(this).data("firstname");
224                 var surname = $(this).data("surname");
225                 add_user( borrowernumber, firstname + " " + surname );
226             });
228             $("body").on("click",".select_user",function(e){
229                 e.preventDefault();
230                 var borrowernumber = $(this).data("borrowernumber");
231                 var borrower_data = $("#borrower_data"+borrowernumber).val();
232                 select_user( borrowernumber, JSON.parse(borrower_data) );
233             });
235             $("body").on("click",".patron_preview", function( e ){
236                 e.preventDefault();
237                 var borrowernumber = $(this).data("borrowernumber");
238                 var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
239                 $("#patronPreview .modal-body").load( page + " div.container-fluid" );
240                 $('#patronPreview').modal({show:true});
241             });
243             $("#patronPreview").on('hidden.bs.modal', function (e) {
244                 $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
245             });
247         });
249         function filter() {
250             search = 1;
251             $("#firstletter_filter").val('');
252             $("#searchresults").show();
253             dtMemberResults.fnDraw();
254             return false;
255         }
257         // User has clicked on a letter
258         function filterByFirstLetterSurname(letter) {
259             $("#firstletter_filter").val(letter);
260             search = 1;
261             $("#searchresults").show();
262             dtMemberResults.fnDraw();
263         }
265         // modify parent window owner element
266         [% IF selection_type == 'add' %]
267             function add_user(borrowernumber, borrowername) {
268                 var p = window.opener;
269                 // In one place (serials/routing.tt), the page is reload on every add
270                 // We have to wait for the page to be there
271                 function wait_for_opener () {
272                     if ( ! $(opener.document).find('body').size() ) {
273                         setTimeout(wait_for_opener, 500);
274                     } else {
275                         [%# Note that add_user could sent data instead of borrowername too %]
276                         $("#info").hide();
277                         $("#error").hide();
278                         if ( p.add_user(borrowernumber, borrowername) < 0 ) {
279                             $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
280                             $("#error").show();
281                         } else {
282                             $("#info").html(_("Patron '%s' added.").format(borrowername));
283                             $("#info").show();
284                         }
285                     }
286                 }
287                 wait_for_opener();
288             }
289         [% ELSIF selection_type == 'select' %]
290             function select_user(borrowernumber, data) {
291                 var p = window.opener;
292                 p.select_user(borrowernumber, data);
293                 window.close();
294             }
295         [% END %]
296     </script>
297 [% END %]
299 [% SET popup_window = 1 %]
300 [% INCLUDE 'intranet-bottom.inc' %]