Bug 26738: (bug 24819 follow-up) Fix manager selection
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / common / patron_search.tt
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>
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 type="text/javascript">
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': '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': 'suggestions.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                 'sPaginationType': 'full_numbers',
205                 "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
206                 'aaSorting': [[[% aaSorting || 0 | html %], 'asc']],
207                 'bFilter': false,
208                 'bProcessing': true,
209             }));
210
211             $("#searchform").on('submit', filter);
212             $(".filterByLetter").on("click",function(e){
213                 e.preventDefault();
214                 filterByFirstLetterSurname($(this).text());
215             });
216             $("body").on("click",".add_user",function(e){
217                 e.preventDefault();
218                 var borrowernumber = $(this).data("borrowernumber");
219                 var firstname = $(this).data("firstname");
220                 var surname = $(this).data("surname");
221                 add_user( borrowernumber, firstname + " " + surname );
222             });
223
224             $("body").on("click",".select_user",function(e){
225                 e.preventDefault();
226                 var borrowernumber = $(this).data("borrowernumber");
227                 var borrower_data = $("#borrower_data"+borrowernumber).val();
228                 select_user( borrowernumber, JSON.parse(borrower_data) );
229             });
230
231             $("body").on("click",".patron_preview", function( e ){
232                 e.preventDefault();
233                 var borrowernumber = $(this).data("borrowernumber");
234                 var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
235                 $("#patronPreview .modal-body").load( page + " div.container-fluid" );
236                 $('#patronPreview').modal({show:true});
237             });
238
239             $("#patronPreview").on('hidden.bs.modal', function (e) {
240                 $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
241             });
242
243         });
244
245         function filter() {
246             search = 1;
247             $("#firstletter_filter").val('');
248             $("#searchresults").show();
249             dtMemberResults.fnDraw();
250             return false;
251         }
252
253         // User has clicked on a letter
254         function filterByFirstLetterSurname(letter) {
255             $("#firstletter_filter").val(letter);
256             search = 1;
257             $("#searchresults").show();
258             dtMemberResults.fnDraw();
259         }
260
261         // modify parent window owner element
262         [% IF selection_type == 'add' %]
263             function add_user(borrowernumber, borrowername) {
264                 var p = window.opener;
265                 // In one place (serials/routing.tt), the page is reload on every add
266                 // We have to wait for the page to be there
267                 function wait_for_opener () {
268                     if ( ! $(opener.document).find('body').size() ) {
269                         setTimeout(wait_for_opener, 500);
270                     } else {
271                         [%# Note that add_user could sent data instead of borrowername too %]
272                         $("#info").hide();
273                         $("#error").hide();
274                         if ( p.add_user(borrowernumber, borrowername) < 0 ) {
275                             $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
276                             $("#error").show();
277                         } else {
278                             $("#info").html(_("Patron '%s' added.").format(borrowername));
279                             $("#info").show();
280                         }
281                     }
282                 }
283                 wait_for_opener();
284             }
285         [% ELSIF selection_type == 'select' %]
286             function select_user(borrowernumber, data) {
287                 var p = window.opener;
288                 [%  IF callback %]
289                     p.[% callback %](borrowernumber, data);
290                 [%  ELSE %]
291                     p.select_user(borrowernumber, data);
292                 [%  END %]
293                 window.close();
294             }
295         [% END %]
296     </script>
297 [% END %]
298
299 [% SET popup_window = 1 %]
300 [% INCLUDE 'intranet-bottom.inc' %]