Bug 9573: Lost items report - add KohaTable to itemlost
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member.tt
blobad7308493386a37e1f403b85cc41e50284cbbea2
1 [% USE Koha %]
2 [% USE ColumnsSettings %]
3 [% USE Branches %]
4 [% USE Categories %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Koha &rsaquo; Patrons [% IF ( searching ) %]&rsaquo; Search results[% END %]</title>
8 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
9 </head>
11 <body id="pat_member" class="pat">
12 [% INCLUDE 'header.inc' %]
13 [% INCLUDE 'patron-search.inc' %]
15 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; [% IF ( searching ) %]<a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Search results[% ELSE %]Patrons[% END %]</div>
17 <div id="doc3" class="yui-t2">
18   <div id="bd">
19     <div id="yui-main">
20       <div class="yui-b">
21         <div class="yui-g">
22           [% IF CAN_user_tools_manage_patron_lists %]
23             <div id="patron_list_dialog" class="dialog alert">
24               Added <span class="patrons-length"></span> patrons to <a></a>.
25             </div>
26           [% END %]
28           [% IF Koha.Preference( 'NorwegianPatronDBEnable' ) == 1 %]
29             [% SET nl_search_form_title='Search the Norwegian national patron database' %]
30             [% INCLUDE 'nl-search-form.tt' %]
31           [% END %]
33           [% INCLUDE 'patron-toolbar.inc' %]
34           [% INCLUDE 'noadd-warnings.inc' %]
36           <div class="browse">
37             Browse by last name:
38             [% FOREACH letter IN alphabet.split(' ') %]
39                 <a href="#" class="filterByLetter">[% letter %]</a>
40             [% END %]
41           </div>
43           [% IF CAN_user_borrowers_edit_borrowers && pending_borrower_modifications %]
44             <div class="pending-info" id="patron_updates_pending">
45               <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
46               <span class="number_box"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications %]</a></span>
47             </div>
48           [% END %]
50           <div id="searchresults">
51             <div id="searchheader">
52               <h3>Patrons found for: <span id="searchpattern">[% IF searchmember %] for '[% searchmember | html %]'[% END %]</span></h3>
53             </div>
54             [% IF CAN_user_tools_manage_patron_lists %]
55               <div id="searchheader">
56                   <div>
57                       <a href="#" id="select_all"><i class="fa fa-check"></i> Select all</a>
58                       |
59                       <a href="#" id="clear_all"><i class="fa fa-remove"></i> Clear all</a>
60                       |
61                       <span>
62                           <label for="add_to_patron_list">Add selected patrons to:</label>
63                           <select id="add_to_patron_list" name="add_to_patron_list">
64                               <option value=""></option>
65                               [% IF patron_lists %]
66                                   <optgroup label="Patron lists:">
67                                       [% FOREACH pl IN patron_lists %]
68                                           <option value="[% pl.patron_list_id %]">[% pl.name |html %]</option>
69                                       [% END %]
70                                   </optgroup>
71                               [% END %]
73                               <option value="new">[ New list ]</option>
74                           </select>
76                           <input type="text" id="new_patron_list" name="new_patron_list" id="new_patron_list" />
78                           <input id="add_to_patron_list_submit" type="submit" class="submit" value="Save">
79                       </span>
80                   </div>
81               </div>
82             [% END %]
84             <table id="memberresultst">
85               <thead>
86                 <tr>
87                 [% IF CAN_user_tools_manage_patron_lists %]
88                   <th>&nbsp;</th>
89                 [% END %]
90                   <th>Card</th>
91                   <th>Name</th>
92                   <th>Date of birth</th>
93                   <th>Category</th>
94                   <th>Library</th>
95                   <th>Expires on</th>
96                   <th>OD/Checkouts</th>
97                   <th>Fines</th>
98                   <th>Circ note</th>
99                   <th>&nbsp;</th>
100                 </tr>
101               </thead>
102               <tbody></tbody>
103             </table>
104           </div>
105         </div>
106       </div>
107     </div>
108     <div class="yui-b">
109       <form method="get" id="searchform">
110         <input type="hidden" id="firstletter_filter" value="" />
111         <fieldset class="brief">
112           <h3>Filters</h3>
113           <ol>
114             <li>
115               <label for="searchmember_filter">Search:</label>
116               <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
117             </li>
118             <li>
119               <label for="searchfieldstype_filter">Search fields:</label>
120               <select name="searchfieldstype" id="searchfieldstype_filter">
121                 [% IF searchfieldstype == "standard" %]
122                   <option selected="selected" value='standard'>Standard</option>
123                 [% ELSE %]
124                   <option value='standard'>Standard</option>
125                 [% END %]
126                 [% IF searchfieldstype == "surname" %]
127                   <option selected="selected" value='surname'>Surname</option>
128                 [% ELSE %]
129                   <option value='surname'>Surname</option>
130                 [% END %]
131                 [% IF searchfieldstype == "email" %]
132                   <option selected="selected" value='email'>Email</option>
133                 [% ELSE %]
134                   <option value='email'>Email</option>
135                 [% END %]
136                 [% IF searchfieldstype == "borrowernumber" %]
137                   <option selected="selected" value='borrowernumber'>Borrower number</option>
138                 [% ELSE %]
139                   <option value='borrowernumber'>Borrower number</option>
140                 [% END %]
141                 [% IF searchfieldstype == "userid" %]
142                   <option selected="selected" value='userid'>Username</option>
143                 [% ELSE %]
144                   <option value='userid'>Username</option>
145                 [% END %]
146                 [% IF searchfieldstype == "phone" %]
147                   <option selected="selected" value='phone'>Phone number</option>
148                 [% ELSE %]
149                   <option value='phone'>Phone number</option>
150                 [% END %]
151                 [% IF searchfieldstype == "address" %]
152                   <option selected="selected" value='address'>Street address</option>
153                 [% ELSE %]
154                   <option value='address'>Street address</option>
155                 [% END %]
156                 [% IF searchfieldstype == "dateofbirth" %]
157                   <option selected="selected" value='dateofbirth'>Date of birth</option>
158                 [% ELSE %]
159                   <option value='dateofbirth'>Date of birth</option>
160                 [% END %]
161                 [% IF searchfieldstype == "sort1" %]
162                   <option selected="selected" value='sort1'>Sort field 1</option>
163                 [% ELSE %]
164                   <option value='sort1'>Sort field 1</option>
165                 [% END %]
166                 [% IF searchfieldstype == "sort2" %]
167                   <option selected="selected" value='sort2'>Sort field 2</option>
168                 [% ELSE %]
169                   <option value='sort2'>Sort field 2</option>
170                 [% END %]
171               </select>
172             </li>
173             <li>
174               <label for="searchtype_filter">Search type:</label>
175               <select name="searchtype" id="searchtype_filter">
176                 [% IF searchtype == "start_with" %]
177                   <option value='start_with' selected="selected">Starts with</option>
178                   <option value="contain">Contains</option>
179                 [% ELSE %]
180                   <option value='start_with'>Starts with</option>
181                   <option value="contain" selected="selected">Contains</option>
182                 [% END %]
183               </select>
184             </li>
185             <li>
186               <label for="categorycode_filter">Category:</label>
187               [% SET categories = Categories.all() %]
188               <select id="categorycode_filter">
189                 <option value="">Any</option>
190                 [% FOREACH cat IN categories %]
191                   [% IF cat.categorycode == categorycode_filter %]
192                     <option selected="selected" value="[% cat.categorycode %]">[% cat.description |html %]</option>
193                   [% ELSE %]
194                     <option value="[% cat.categorycode %]">[% cat.description |html %]</option>
195                   [% END %]
196                 [% END %]
197               </select>
198             </li>
199             <li>
200               <label for="branchcode_filter">Library:</label>
201               [% SET branches = Branches.all( selected => branchcode_filter, only_from_group => 1 ) %]
202               <select id="branchcode_filter">
203                 [% IF branches.size != 1 %]
204                   <option value="">Any</option>
205                 [% END %]
206                 [% PROCESS options_for_libraries libraries => branches %]
207               </select>
208             </li>
209           </ol>
210           <fieldset class="action">
211             <input type="submit" value="Search" />
212             <input type="button" value="Clear" id="clear_search" />
213           </fieldset>
214         </fieldset>
215       </form>
216     </div>
217   </div>
218   <div class="yui-g">
219     [% INCLUDE 'members-menu.inc' %]
220   </div>
221 </div>
223 [% MACRO jsinclude BLOCK %]
224     [% INCLUDE 'datatables.inc' %]
225     [% INCLUDE 'columns_settings.inc' %]
226     <script type="text/javascript" src="[% interface %]/[% theme %]/js/members-menu_[% KOHA_VERSION %].js"></script>
227     <script type="text/javascript">
228         $(document).ready(function() {
229             $('#add_to_patron_list_submit').prop('disabled', true);
230             $('#new_patron_list').hide();
232             $('#add_to_patron_list').change(function() {
233                 var value = $('#add_to_patron_list').val();
234                 if ( value == 'new' ) {
235                     $('#new_patron_list').val('')
236                     $('#new_patron_list').show();
237                     $('#new_patron_list').focus();
238                 } else if ( value ) {
239                     $('#new_patron_list').hide();
240                     $('#add_to_patron_list_submit').prop('disabled', false);
241                 } else {
242                     $('#new_patron_list').hide();
243                     $('#add_to_patron_list_submit').prop('disabled', true);
244                 }
245             });
247             $('#new_patron_list').on('input', function() {
248                 if ( $('#new_patron_list').val() ) {
249                     $('#add_to_patron_list_submit').prop('disabled', false);
250                 } else {
251                     $('#add_to_patron_list_submit').prop('disabled', true);
252                 }
253             });
255             $("#add_to_patron_list_submit").on('click', function(e){
256                 if ( $('#add_to_patron_list').val() == 'new' ) {
257                     if ( $('#new_patron_list').val() ) {
258                         $("#add_to_patron_list option").each(function() {
259                             if ( $(this).text() == $('#new_patron_list').val() ) {
260                                 alert( _("You already have a list with that name!") );
261                                 return false;
262                             }
263                         });
264                     } else {
265                         alert( _("You must give your new patron list a name!") );
266                         return false;
267                     }
268                 }
270                 if ( $("#memberresultst input:checkbox:checked").length == 0 ) {
271                     alert( _("You have not selected any patrons to add to a list!") );
272                     return false;
273                 }
275                 var borrowernumbers = [];
276                 $("#memberresultst").find("input:checkbox:checked").each(function(){
277                     borrowernumbers.push($(this).val());
278                 });
279                 var data = {
280                     add_to_patron_list: $("#add_to_patron_list").val(),
281                     new_patron_list: $("#new_patron_list").val(),
282                     borrowernumbers: borrowernumbers
283                 };
284                 $.ajax({
285                     data: data,
286                     type: 'POST',
287                     url: '/cgi-bin/koha/svc/members/add_to_list',
288                     success: function(data) {
289                         $("#patron_list_dialog").show();
290                         $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list);
291                         $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id);
292                         $("#patron_list_dialog > a").html(data.patron_list.name);
293                         if ( $('#add_to_patron_list').val() == 'new' ) {
294                             var new_patron_list_added = $("<option>", {
295                                 value: data.patron_list.patron_list_id,
296                                 text: data.patron_list.name
297                             });
298                             $("#add_to_patron_list optgroup").append(new_patron_list_added);
299                             $("#add_to_patron_list").val(data.patron_list.patron_list_id);
300                             $("#new_patron_list").val('');
301                             $('#add_to_patron_list').change();
302                         }
303                     },
304                     error: function() {
305                         alert("an error occurred");
306                     }
307                 });
308                 return true;
309             });
310             $(".filterByLetter").on("click",function(e){
311                 e.preventDefault();
312                 filterByFirstLetterSurname($(this).text());
313             });
314             $("#select_all").on("click",function(e){
315                 e.preventDefault();
316                 $(".selection").prop("checked", true);
317             });
318             $("#clear_all").on("click",function(e){
319                 e.preventDefault();
320                 $(".selection").prop("checked", false);
321             });
322             $("#clear_search").on("click",function(e){
323                 e.preventDefault();
324                 clearFilters(true);
325             });
326             $("#searchform").on("submit", filter);
327         });
329         var dtMemberResults;
330         var search = 1;
331         $(document).ready(function() {
332             [% IF searchmember %]
333                 $("#searchmember_filter").val("[% searchmember | html %]");
334             [% END %]
335             [% IF searchfieldstype %]
336                 $("searchfieldstype_filter").val("[% searchfieldstype %]");
337             [% END %]
338             [% IF searchtype %]
339                 $("#searchtype_filter").val("[% searchtype %]");
340             [% END %]
341             [% IF categorycode %]
342                 $("#categorycode_filter").val("[% categorycode_filter %]");
343             [% END %]
344             [% IF branchcode %]
345                 $("#branchcode_filter").val("[% branchcode_filter %]");
346             [% END %]
348             [% IF view != "show_results" %]
349                 search = 0;
350             [% ELSE %]
351                 $("#searchresults").show();
352             [% END %]
354             // Build the aLengthMenu
355             var aLengthMenu = [
356                 [%PatronsPerPage %], 10, 20, 50, 100, -1
357             ];
358             jQuery.unique(aLengthMenu);
359             aLengthMenu.sort(function( a, b ){
360                 // Put "All" at the end
361                 if ( a == -1 ) {
362                     return 1;
363                 } else if ( b == -1 ) {
364                     return -1;
365                 }
366                 return parseInt(a) < parseInt(b) ? -1 : 1;}
367             );
368             var aLengthMenuLabel = [];
369             $(aLengthMenu).each(function(){
370                 if ( this == -1 ) {
371                     // Label for -1 is "All"
372                     aLengthMenuLabel.push("All");
373                 } else {
374                     aLengthMenuLabel.push(this);
375                 }
376             });
378             // Apply DataTables on the results table
379             var columns_settings = [% ColumnsSettings.GetColumns( 'members', 'member', 'memberresultst', 'json' ) %];
380             [% UNLESS CAN_user_tools_manage_patron_lists %]
381                 [%# Remove the first column if we do not display the checkbox %]
382                 columns_settings.splice(0, 1);
383             [% END %]
384             dtMemberResults = KohaTable("memberresultst", {
385                 'bServerSide': true,
386                 'sAjaxSource': "/cgi-bin/koha/svc/members/search",
387                 'fnServerData': function(sSource, aoData, fnCallback) {
388                     if ( ! search ) {
389                         return;
390                     }
391                     aoData.push({
392                         'name': 'searchmember',
393                         'value': $("#searchmember_filter").val()
394                     },{
395                         'name': 'firstletter',
396                         'value': $("#firstletter_filter").val()
397                     },{
398                         'name': 'searchfieldstype',
399                         'value': $("#searchfieldstype_filter").val()
400                     },{
401                         'name': 'searchtype',
402                         'value': $("#searchtype_filter").val()
403                     },{
404                         'name': 'categorycode',
405                         'value': $("#categorycode_filter").val()
406                     },{
407                         'name': 'branchcode',
408                         'value': $("#branchcode_filter").val()
409                     },{
410                         'name': 'name_sorton',
411                         'value': 'borrowers.surname borrowers.firstname'
412                     },{
413                         'name': 'dateofbirth',
414                         'value': 'borrowers.dateofbirth',
415                     },{
416                         'name': 'category_sorton',
417                         'value': 'categories.description',
418                     },{
419                         'name': 'branch_sorton',
420                         'value': 'branches.branchname'
421                     },{
422                         'name': 'template_path',
423                         'value': 'members/tables/members_results.tt',
424                     });
425                     $.ajax({
426                         'dataType': 'json',
427                         'type': 'POST',
428                         'url': sSource,
429                         'data': aoData,
430                         'success': function(json){
431                             // redirect if there is only 1 result.
432                             if ( json.aaData.length == 1 ) {
433                                 var borrowernumber = json.aaData[0].borrowernumber;
434                                 document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
435                                 return false;
436                             }
437                             fnCallback(json);
438                         }
439                     });
440                 },
441                 'aoColumns':[
442                     [% IF CAN_user_tools_manage_patron_lists %]
443                       { 'mDataProp': 'dt_borrowernumber', 'bSortable': false },
444                     [% END %]
445                     { 'mDataProp': 'dt_cardnumber' },
446                     { 'mDataProp': 'dt_name' },
447                     { 'mDataProp': 'dt_dateofbirth' },
448                     { 'mDataProp': 'dt_category' },
449                     { 'mDataProp': 'dt_branch' },
450                     { 'mDataProp': 'dt_dateexpiry' },
451                     { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
452                     { 'mDataProp': 'dt_fines', 'bSortable': false },
453                     { 'mDataProp': 'dt_borrowernotes' },
454                     { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
455                 ],
456                 'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
457                     /* Center text for 6th column */
458                     $("td:eq(5)", nRow).css("text-align", "center");
460                     return nRow;
461                 },
462                 'bFilter': false,
463                 'bAutoWidth': false,
464                 [% IF CAN_user_tools_manage_patron_lists %]
465                     'aaSorting': [[2, 'asc']],
466                 [% ELSE %]
467                     'aaSorting': [[1, 'asc']],
468                 [% END %]
469                 "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
470                 'sPaginationType': 'full_numbers',
471                 "iDisplayLength": [% PatronsPerPage %],
472                 "bProcessing": true,
473             }, columns_settings);
474             update_searched();
475         });
477         // Update the string "Results found ..."
478         function update_searched(){
479             var searched = $("#searchfieldstype_filter").find("option:selected").text();
480             if ( $("#searchmember_filter").val() ) {
481                 if ( $("#searchtype_filter").val() == 'start_with' ) {
482                     searched += _(" starting with ");
483                 } else {
484                     searched += _(" containing ");
485                 }
486                 searched += "'" + $("#searchmember_filter").val() + "'";
487             }
488             if ( $("#firstletter_filter").val() ) {
489                 searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'";
490             }
491             if ( $("#categorycode_filter").val() ) {
492                 searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'";
493             }
494             if ( $("#branchcode_filter").val() ) {
495                 searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
496             }
497             $("#searchpattern").text(searched);
498         }
500         // Redraw the table
501         function filter() {
502             $("#firstletter_filter").val('');
503             update_searched();
504             search = 1;
505             $("#searchresults").show();
506             dtMemberResults.fnDraw();
507             return false;
508         }
510         // User has clicked on the Clear button
511         function clearFilters(redraw) {
512             $("#searchform select").val('');
513             $("#firstletter_filter").val('');
514             $("#searchmember_filter").val('');
515             if(redraw) {
516                 search = 1;
517                 $("#searchresults").show();
518                 dtMemberResults.fnDraw();
519             }
520         }
522         // User has clicked on a letter
523         function filterByFirstLetterSurname(letter) {
524             clearFilters(false);
525             $("#firstletter_filter").val(letter);
526             update_searched();
527             search = 1;
528             $("#searchresults").show();
529             dtMemberResults.fnDraw();
530         }
531     </script>
532 [% END %]
534 [% INCLUDE 'intranet-bottom.inc' %]