Bug 28630: Improve date comparisons in tests
[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>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' %]