e182688b584547b2acbc07cddf05f3314ddecef3
[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     $("#searchmember_filter").on('keyup', function(){
22         filter();
23     });
24     // Apply DataTables on the results table
25     dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
26         'bServerSide': true,
27         'sAjaxSource': "/cgi-bin/koha/svc/members/search",
28         'fnServerData': function(sSource, aoData, fnCallback) {
29             if ( ! search ) {
30                 return;
31             }
32             aoData.push({
33                 'name': 'searchmember',
34                 'value': $("#searchmember_filter").val()
35             },{
36                 'name': 'name_sorton',
37                 'value': 'borrowers.surname borrowers.firstname'
38             },{
39                 'name': 'category_sorton',
40                 'value': 'categories.description',
41             },{
42                 'name': 'branch_sorton',
43                 'value': 'branches.branchname'
44             },{
45                 'name': 'template_path',
46                 'value': '[% json_template %]',
47             },{
48                 'name': 'selection_type',
49                 'value': '[% selection_type %]',
50             }
51             [% IF patrons_with_acq_perm_only %]
52             ,{
53                 'name': 'has_permission',
54                 'value': 'acquisition.order_manage',
55             }
56             [% END %]
57             );
58             $.ajax({
59                 'dataType': 'json',
60                 'type': 'POST',
61                 'url': sSource,
62                 'data': aoData,
63                 'success': function(json){
64                     fnCallback(json);
65                 }
66             });
67         },
68         'aoColumns':[
69             [% FOR column IN columns %]
70                 [% IF column == 'action' %]
71                     { 'mDataProp': 'dt_action', 'bSortable': false }
72                 [% ELSIF column == 'address' %]
73                     { 'mDataProp': 'dt_address', 'bSortable': false }
74                 [% ELSE %]
75                     { 'mDataProp': 'dt_[% column %]' }
76                 [% END %]
77                 [% UNLESS loop.last %],[% END %]
78             [% END %]
79         ],
80         'bAutoWidth': false,
81         [% IF patrons_with_acq_perm_only %]
82             'bPaginate': false,
83         [% ELSE %]
84             'sPaginationType': 'full_numbers',
85             "iDisplayLength": [% Koha.Preference('PatronsPerPage') %],
86         [% END %]
87         'bFilter': false,
88         'bProcessing': true,
89     }));
90     dtMemberResults.fnAddFilters("filter", 750);
91 });
92
93 var delay = (function(){
94   var timer = 0;
95   return function(callback, ms){
96     clearTimeout (timer);
97     timer = setTimeout(callback, ms);
98   };
99 })();
100
101 function filter() {
102     search = 1;
103
104     $("#searchresults").show();
105
106     if ( $("#searchmember_filter").val().length > 0 ) {
107         delay(function(){
108             dtMemberResults.fnDraw();
109         }, 1000);
110     }
111
112     return false;
113 }
114
115     // modify parent window owner element
116     [% IF selection_type == 'add' %]
117         function add_user(borrowernumber, borrowername) {
118             var p = window.opener;
119             // In one place (serials/routing.tt), the page is reload on every add
120             // We have to wait for the page to be there
121             function wait_for_opener () {
122                 if ( ! $(opener.document).find('body').size() ) {
123                     setTimeout(wait_for_opener, 500);
124                 } else {
125                     [%# Note that add_user could sent data instead of borrowername too %]
126                     $("#info").hide();
127                     $("#error").hide();
128                     if ( p.add_user(borrowernumber, borrowername) < 0 ) {
129                         $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
130                         $("#error").show();
131                     } else {
132                         $("#info").html(_("Borrower '%s' added.").format(borrowername));
133                         $("#info").show();
134                     }
135                 }
136             }
137             wait_for_opener();
138         }
139     [% ELSIF selection_type == 'select' %]
140         function select_user(borrowernumber, data) {
141             var p = window.opener;
142             p.select_user(borrowernumber, data);
143             window.close();
144         }
145     [% END %]
146 //]]>
147 </script>
148
149 </head>
150 <body>
151 <div id="patron_search" class="yui-t7">
152   <div id="bd">
153     <div class="yui-g">
154
155         <h3>Search for patron</h3>
156
157           <label for="searchmember_filter">Search:</label>
158           <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
159
160         [% IF patrons_with_acq_perm_only %]
161             <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>
162         [% END %]
163
164         <div id="info" class="dialog message"></div>
165         <div id="error" class="dialog alert"></div>
166
167         <div id="searchresults">
168             <table id="memberresultst">
169                 <thead>
170                     <tr>
171                         [% FOR column IN columns %]
172                             [% SWITCH column %]
173                                 [% CASE 'cardnumber' %]<th>Card</th>
174                                 [% CASE 'dateofbirth' %]<th>Date of birth</th>
175                                 [% CASE 'address' %]<th>Address</th>
176                                 [% CASE 'name' %]<th>Name</th>
177                                 [% CASE 'branch' %]<th>Library</th>
178                                 [% CASE 'category' %]<th>Category</th>
179                                 [% CASE 'dateexpiry' %]<th>Expires on</td>
180                                 [% CASE 'borrowernotes' %]<th>Notes</th>
181                                 [% CASE 'action' %]<th>&nbsp;</th>
182                             [% END %]
183                         [% END %]
184                     </tr>
185                   </thead>
186                 <tbody></tbody>
187             </table>
188         </div>
189
190 <div id="closewindow"><a href="#" class="close">Close</a></div>
191 </div>
192 </div>
193 [% INCLUDE 'intranet-bottom.inc' %]