Bug 15109: Make name the default sort order for all patron searches
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / common / patron_search.tt
1 [% USE Koha %]
2 [% INCLUDE 'doc-head-open.inc' %]
3 <title>Koha &rsaquo; Patron search</title>
4 [% INCLUDE 'doc-head-close.inc' %]
5 <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
6 [% INCLUDE 'datatables.inc' %]
7
8 <script type="text/javascript">
9 //<![CDATA[
10
11 var search = 1;
12 $(document).ready(function(){
13     $("#info").hide();
14     $("#error").hide();
15
16     [% IF view != "show_results" %]
17         $("#searchresults").hide();
18         search = 0;
19     [% END %]
20
21     // Apply DataTables on the results table
22     dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
23         'bServerSide': true,
24         'sAjaxSource': "/cgi-bin/koha/svc/members/search",
25         'fnServerData': function(sSource, aoData, fnCallback) {
26             if ( ! search ) {
27                 return;
28             }
29             aoData.push({
30                 'name': 'searchmember',
31                 'value': $("#searchmember_filter").val()
32             },{
33                 'name': 'firstletter',
34                 'value': $("#firstletter_filter").val()
35             },{
36                 'name': 'categorycode',
37                 'value': $("#categorycode_filter").val()
38             },{
39                 'name': 'branchcode',
40                 'value': $("#branchcode_filter").val()
41             },{
42                 'name': 'name_sorton',
43                 'value': 'borrowers.surname borrowers.firstname'
44             },{
45                 'name': 'category_sorton',
46                 'value': 'categories.description',
47             },{
48                 'name': 'branch_sorton',
49                 'value': 'branches.branchname'
50             },{
51                 'name': 'template_path',
52                 'value': '[% json_template %]',
53             },{
54                 'name': 'selection_type',
55                 'value': '[% selection_type %]',
56             }
57             [% IF patrons_with_acq_perm_only %]
58             ,{
59                 'name': 'has_permission',
60                 'value': 'acquisition.order_manage',
61             }
62             [% END %]
63             );
64             $.ajax({
65                 'dataType': 'json',
66                 'type': 'POST',
67                 'url': sSource,
68                 'data': aoData,
69                 'success': function(json){
70                     fnCallback(json);
71                 }
72             });
73         },
74         'aoColumns':[
75             [% FOR column IN columns %]
76                 [% IF column == 'action' %]
77                     { 'mDataProp': 'dt_action', 'bSortable': false }
78                 [% ELSIF column == 'address' %]
79                     { 'mDataProp': 'dt_address', 'bSortable': false }
80                 [% ELSE %]
81                     { 'mDataProp': 'dt_[% column %]' }
82                 [% END %]
83                 [% UNLESS loop.last %],[% END %]
84             [% END %]
85         ],
86         'bAutoWidth': false,
87         [% IF patrons_with_acq_perm_only %]
88             'bPaginate': false,
89         [% ELSE %]
90             'sPaginationType': 'full_numbers',
91             "iDisplayLength": [% Koha.Preference('PatronsPerPage') %],
92         [% END %]
93         'aaSorting': [[[% aaSorting || 0 %], 'asc']],
94         'bFilter': false,
95         'bProcessing': true,
96     }));
97
98     $("#searchform").on('submit', filter);
99 });
100
101 function filter() {
102     search = 1;
103     $("#firstletter_filter").val('');
104     $("#searchresults").show();
105     dtMemberResults.fnDraw();
106     return false;
107 }
108
109 // User has clicked on a letter
110 function filterByFirstLetterSurname(letter) {
111     $("#firstletter_filter").val(letter);
112     search = 1;
113     $("#searchresults").show();
114     dtMemberResults.fnDraw();
115 }
116
117
118     // modify parent window owner element
119     [% IF selection_type == 'add' %]
120         function add_user(borrowernumber, borrowername) {
121             var p = window.opener;
122             // In one place (serials/routing.tt), the page is reload on every add
123             // We have to wait for the page to be there
124             function wait_for_opener () {
125                 if ( ! $(opener.document).find('body').size() ) {
126                     setTimeout(wait_for_opener, 500);
127                 } else {
128                     [%# Note that add_user could sent data instead of borrowername too %]
129                     $("#info").hide();
130                     $("#error").hide();
131                     if ( p.add_user(borrowernumber, borrowername) < 0 ) {
132                         $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
133                         $("#error").show();
134                     } else {
135                         $("#info").html(_("Borrower '%s' added.").format(borrowername));
136                         $("#info").show();
137                     }
138                 }
139             }
140             wait_for_opener();
141         }
142     [% ELSIF selection_type == 'select' %]
143         function select_user(borrowernumber, data) {
144             var p = window.opener;
145             p.select_user(borrowernumber, data);
146             window.close();
147         }
148     [% END %]
149 //]]>
150 </script>
151
152 </head>
153 <body id="common_patron_search" class="common">
154 <div id="patron_search" class="yui-t7">
155   <div id="bd">
156     <div class="yui-g">
157
158         <form id="searchform">
159             <fieldset class="brief">
160                 <h3>Search for patron</h3>
161                 <ol>
162                     <li>
163                         <label for="searchmember_filter">Search:</label>
164                         <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
165                     </li>
166                     <li>
167                         <label for="categorycode_filter">Category:</label>
168                         <select id="categorycode_filter">
169                             <option value="">Any</option>
170                             [% FOREACH category IN categories %]
171                                 <option value="[% category.categorycode %]">[% category.description %]</option>
172                             [% END %]
173                         </select>
174                     </li>
175                     <li>
176                         <label for="branchcode_filter">Library:</label>
177                         <select id="branchcode_filter">
178                             [% IF branches.size != 1 %]
179                                 <option value="">Any</option>
180                             [% END %]
181                             [% FOREACH branch IN branches %]
182                                 <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
183                             [% END %]
184                         </select>
185                     </li>
186                 </ol>
187                 <fieldset class="action">
188                     <input class="btn btn-default" type="submit" value="Search" />
189                 </fieldset>
190             </fieldset>
191         <form>
192
193         [% IF patrons_with_acq_perm_only %]
194             <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>
195         [% END %]
196
197         <div class="browse">
198             Browse by last name:
199             [% FOREACH letter IN alphabet.split(' ') %]
200                 <a style="cursor:pointer" onclick="filterByFirstLetterSurname('[% letter %]');">[% letter %]</a>
201             [% END %]
202         </div>
203
204         <div id="info" class="dialog message"></div>
205         <div id="error" class="dialog alert"></div>
206
207         <input type="hidden" id="firstletter_filter" value="" />
208         <div id="searchresults">
209             <table id="memberresultst">
210                 <thead>
211                     <tr>
212                         [% FOR column IN columns %]
213                             [% SWITCH column %]
214                                 [% CASE 'cardnumber' %]<th>Card</th>
215                                 [% CASE 'dateofbirth' %]<th>Date of birth</th>
216                                 [% CASE 'address' %]<th>Address</th>
217                                 [% CASE 'name' %]<th>Name</th>
218                                 [% CASE 'branch' %]<th>Library</th>
219                                 [% CASE 'category' %]<th>Category</th>
220                                 [% CASE 'dateexpiry' %]<th>Expires on</td>
221                                 [% CASE 'borrowernotes' %]<th>Notes</th>
222                                 [% CASE 'action' %]<th>&nbsp;</th>
223                             [% END %]
224                         [% END %]
225                     </tr>
226                   </thead>
227                 <tbody></tbody>
228             </table>
229         </div>
230
231 <div id="closewindow"><a href="#" class="btn btn-default close">Close</a></div>
232 </div>
233 </div>
234 [% INCLUDE 'intranet-bottom.inc' %]