Bug 13618: Add html filters to all the variables
[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 [% Asset.css("css/datatables.css") | $raw %]
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 %]"/>
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         <div class="browse">
57             Browse by last name:
58             [% FOREACH letter IN alphabet.split(' ') %]
59                 <a href="#" class="filterByLetter">[% letter | html %]</a>
60             [% END %]
61         </div>
62
63         <div id="info" class="dialog message"></div>
64         <div id="error" class="dialog alert"></div>
65
66         <input type="hidden" id="firstletter_filter" value="" />
67         <div id="searchresults">
68             <table id="memberresultst">
69                 <thead>
70                     <tr>
71                         [% FOR column IN columns %]
72                             [% SWITCH column %]
73                                 [% CASE 'cardnumber' %]<th>Card</th>
74                                 [% CASE 'dateofbirth' %]<th>Date of birth</th>
75                                 [% CASE 'address' %]<th>Address</th>
76                                 [% CASE 'name' %]<th>Name</th>
77                                 [% CASE 'branch' %]<th>Library</th>
78                                 [% CASE 'category' %]<th>Category</th>
79                                 [% CASE 'dateexpiry' %]<th>Expires on</td>
80                                 [% CASE 'borrowernotes' %]<th>Notes</th>
81                                 [% CASE 'action' %]<th>&nbsp;</th>
82                             [% END %]
83                         [% END %]
84                     </tr>
85                   </thead>
86                 <tbody></tbody>
87             </table>
88         </div>
89
90 <div id="closewindow"><a href="#" class="btn btn-default btn-default close">Close</a></div>
91
92 [% MACRO jsinclude BLOCK %]
93     [% INCLUDE 'datatables.inc' %]
94
95     <script type="text/javascript">
96         var search = 1;
97         $(document).ready(function(){
98             $("#info").hide();
99             $("#error").hide();
100
101             [% IF view != "show_results" %]
102                 $("#searchresults").hide();
103                 search = 0;
104             [% END %]
105
106             // Apply DataTables on the results table
107             dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
108                 'bServerSide': true,
109                 'sAjaxSource': "/cgi-bin/koha/svc/members/search",
110                 'fnServerData': function(sSource, aoData, fnCallback) {
111                     if ( ! search ) {
112                         return;
113                     }
114                     aoData.push({
115                         'name': 'searchmember',
116                         'value': $("#searchmember_filter").val()
117                     },{
118                         'name': 'firstletter',
119                         'value': $("#firstletter_filter").val()
120                     },{
121                         'name': 'categorycode',
122                         'value': $("#categorycode_filter").val()
123                     },{
124                         'name': 'branchcode',
125                         'value': $("#branchcode_filter").val()
126                     },{
127                         'name': 'name_sorton',
128                         'value': 'borrowers.surname borrowers.firstname'
129                     },{
130                         'name': 'category_sorton',
131                         'value': 'categories.description',
132                     },{
133                         'name': 'branch_sorton',
134                         'value': 'branches.branchname'
135                     },{
136                         'name': 'template_path',
137                         'value': '[% json_template | html %]',
138                     },{
139                         'name': 'selection_type',
140                         'value': '[% selection_type | html %]',
141                     }
142                     [% IF patrons_with_acq_perm_only %]
143                     ,{
144                         'name': 'has_permission',
145                         'value': 'acquisition.order_manage',
146                     }
147                     [% END %]
148                     );
149                     $.ajax({
150                         'dataType': 'json',
151                         'type': 'POST',
152                         'url': sSource,
153                         'data': aoData,
154                         'success': function(json){
155                             fnCallback(json);
156                         }
157                     });
158                 },
159                 'aoColumns':[
160                     [% FOR column IN columns %]
161                         [% IF column == 'action' %]
162                             { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
163                         [% ELSIF column == 'address' %]
164                             { 'mDataProp': 'dt_address', 'bSortable': false }
165                         [% ELSE %]
166                             { 'mDataProp': 'dt_[% column | html %]' }
167                         [% END %]
168                         [% UNLESS loop.last %],[% END %]
169                     [% END %]
170                 ],
171                 'bAutoWidth': false,
172                 [% IF patrons_with_acq_perm_only %]
173                     'bPaginate': false,
174                 [% ELSE %]
175                     'sPaginationType': 'full_numbers',
176                     "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
177                 [% END %]
178                 'aaSorting': [[[% aaSorting || 0 | html %], 'asc']],
179                 'bFilter': false,
180                 'bProcessing': true,
181             }));
182
183             $("#searchform").on('submit', filter);
184             $(".filterByLetter").on("click",function(e){
185                 e.preventDefault();
186                 filterByFirstLetterSurname($(this).text());
187             });
188             $("body").on("click",".add_user",function(e){
189                 e.preventDefault();
190                 var borrowernumber = $(this).data("borrowernumber");
191                 var firstname = $(this).data("firstname");
192                 var surname = $(this).data("surname");
193                 add_user( borrowernumber, firstname + " " + surname );
194             });
195
196             $("body").on("click",".select_user",function(e){
197                 e.preventDefault();
198                 var borrowernumber = $(this).data("borrowernumber");
199                 var borrower_data = $("#borrower_data"+borrowernumber).val();
200                 select_user( borrowernumber, JSON.parse(borrower_data) );
201             });
202
203         });
204
205         function filter() {
206             search = 1;
207             $("#firstletter_filter").val('');
208             $("#searchresults").show();
209             dtMemberResults.fnDraw();
210             return false;
211         }
212
213         // User has clicked on a letter
214         function filterByFirstLetterSurname(letter) {
215             $("#firstletter_filter").val(letter);
216             search = 1;
217             $("#searchresults").show();
218             dtMemberResults.fnDraw();
219         }
220
221         // modify parent window owner element
222         [% IF selection_type == 'add' %]
223             function add_user(borrowernumber, borrowername) {
224                 var p = window.opener;
225                 // In one place (serials/routing.tt), the page is reload on every add
226                 // We have to wait for the page to be there
227                 function wait_for_opener () {
228                     if ( ! $(opener.document).find('body').size() ) {
229                         setTimeout(wait_for_opener, 500);
230                     } else {
231                         [%# Note that add_user could sent data instead of borrowername too %]
232                         $("#info").hide();
233                         $("#error").hide();
234                         if ( p.add_user(borrowernumber, borrowername) < 0 ) {
235                             $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
236                             $("#error").show();
237                         } else {
238                             $("#info").html(_("Patron '%s' added.").format(borrowername));
239                             $("#info").show();
240                         }
241                     }
242                 }
243                 wait_for_opener();
244             }
245         [% ELSIF selection_type == 'select' %]
246             function select_user(borrowernumber, data) {
247                 var p = window.opener;
248                 p.select_user(borrowernumber, data);
249                 window.close();
250             }
251         [% END %]
252     </script>
253 [% END %]
254
255 [% SET popup_window = 1 %]
256 [% INCLUDE 'intranet-bottom.inc' %]