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