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