Bug 22118: Format hold fee when placing holds in OPAC
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / modules / opac-reserve.tt
1 [% USE Koha %]
2 [% USE Branches %]
3 [% USE KohaDates %]
4 [% USE Price %]
5 [% USE ItemTypes %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Placing a hold</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 [% BLOCK cssinclude %][% END %]
10 </head>
11
12 [% INCLUDE 'bodytag.inc' bodyid='opac-holds' %]
13 [% INCLUDE 'masthead.inc' %]
14
15 <div class="main">
16     <ul class="breadcrumb">
17         <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
18         <li><a href="#">Placing a hold</a></li>
19     </ul>
20
21     <div class="container">
22         <div id="holds">
23             [% IF ( message ) %]
24                 <div id="holdmessages" class="alert">
25                     <p><strong>Sorry</strong>, you cannot place holds.</strong></p>
26                     <ul>
27                         [% IF ( GNA ) %]
28                             <li id="gna">
29                                 According to our records, we don't have up-to-date contact information. Please contact the library.
30                                 <a href="/cgi-bin/koha/opac-memberentry.pl">[% IF ( Koha.Preference('OPACPatronDetails') ) %]Update your contact information[% ELSE %]Go to your contact information[% END %]</a>
31                                 [% IF ( Koha.Preference('OPACPatronDetails') ) %]<em>(Please note: there may be a delay in restoring your account if you submit online.)</em>[% END %]
32                             </li>
33                         [% END %]
34
35                         [% IF ( lost ) %]
36                             <li id="lost">
37                                 Your library card has been marked as lost or stolen.<br />
38                                 <em>If this is an error, please take your card to the circulation desk at your local library and the error will be corrected.</em>
39                             </li>
40                         [% END %]
41
42                         [% IF ( debarred ) %]
43                             <li id="debarred">
44                                 Your account has been frozen.
45                                 [% IF debarred_comment %]
46                                     Comment:
47                                     <span id="userdebarred_comment">
48                                         <strong>
49                                             [% IF debarred_comment.search('OVERDUES_PROCESS') %]
50                                                 Restriction added by overdues process [% debarred_comment.remove('OVERDUES_PROCESS ') | html_line_break %]
51                                             [% ELSE %]
52                                                 [% debarred_comment | html_line_break %]
53                                             [% END %]
54                                         </strong>
55                                     </span>
56                                 [% END %]
57
58                                 [% IF debarred_date && debarred_date != '9999-12-31' %]
59                                     End date:
60                                     <span id="userdebarred_date">[% debarred_date | $KohaDates %]</span>
61                                 [% END %]
62                                 <br /><em>Usually the reason for freezing an account is old overdues or damage fees. If shows your account to be clear, please contact the library.</em> <a href="/cgi-bin/koha/opac-account.pl">Go to your account page</a>
63                             </li>
64                         [% END %]
65
66                         [% IF ( too_much_oweing ) %]
67                             <li id="too_much_oweing">
68                                 You have unpaid fines. Amount: [% too_much_oweing | $Price %].
69                             </li>
70                         [% END %]
71
72                         [% IF ( too_many_reserves ) %]
73                             <li id="too_many_reserves">
74                                 Sorry, you cannot place more than [% too_many_reserves %] holds.
75                             </li>
76                         [% END %]
77
78                         [% IF ( bad_biblionumber ) %]
79                             <li id="bad_biblionumber">
80                                 ERROR: No record found for record id [% bad_biblionumber %].
81                             </li>
82                         [% END %]
83
84                         [% IF ( no_items_selected ) %]
85                             <li id="no_items_selected">
86                                 You must select at least one item.
87                             </li>
88                         [% END %]
89
90                         [% IF ( no_branch_selected ) %]
91                             <li id="no_branch_selected">
92                                 You must select a library for pickup.
93                             </li>
94                         [% END %]
95
96                         [% IF ( no_biblionumber ) %]
97                             <li id="no_biblionumber">
98                                ERROR: No record id specified.
99                            </li>
100                         [% END %]
101
102                         [% IF ( bad_data ) %]
103                             <li id="bad_data">
104                                 ERROR: Internal error: incomplete hold request.
105                             </li>
106                         [% END %]
107
108                         [% IF ( expired_patron ) %]
109                             <li id="expired_patron">
110                                 Your library card has expired. Please contact your librarian if you wish to renew your card.
111                             </li>
112                         [% END %]
113
114                     [% ELSE %]
115
116                         [% IF ( none_available ) %]
117                             <div id="none_available" class="alert">
118                                 <strong>Sorry</strong>, none of these items can be placed on hold.
119                             </div>
120                         [% END %]
121                 </div>
122             [% END # / IF message %]
123
124                     [% UNLESS ( message ) %]
125                         [% UNLESS ( none_available ) %]
126                             <h3>Confirm holds for:[% USER_INFO.firstname %] [% USER_INFO.surname %] ([% USER_INFO.cardnumber %])</h3>
127                         [% END # / UNLESS none_available %]
128
129                         [% IF (RESERVE_CHARGE) %]
130                             <div class="alert" id="reserve_fee">
131                                 [% IF Koha.Preference('HoldFeeMode') == 'any_time_is_collected' %]
132                                     You will be charged a hold fee of [% RESERVE_CHARGE | $Price %] when you collect this item
133                                 [% ELSE %]
134                                     You will be charged a hold fee of [% RESERVE_CHARGE | $Price %] for placing this hold
135                                 [% END %]
136                             </div>
137                         [% END %]
138
139                         [% IF ( new_reserves_allowed ) %]
140                             <div id="new_reserves_allowed" class="alert">
141                                 <strong>Sorry,</strong> you can only place [% new_reserves_allowed %] more holds. Please uncheck the checkboxes for the items you wish to not place holds on.
142                             </div>
143                         [% END %]
144
145                         <form action="/cgi-bin/koha/opac-reserve.pl" method="post" id="hold-request-form">
146                             <input type="hidden" name="place_reserve" value="1"/>
147                             <!-- These values are set dynamically by js -->
148                             <input type="hidden" name="biblionumbers" id="biblionumbers"/>
149                             <input type="hidden" name="selecteditems" id="selections"/>
150                             <div id="bigloop">
151
152                                 [% FOREACH bibitemloo IN bibitemloop %]
153                                     <div class="holdrow">
154                                         <p>
155                                             [% IF ( bibitemloo.holdable ) %]
156                                                 <input class="reserve_mode" name="reserve_mode" type="hidden" value="single"/>
157                                                 <input class="single_bib" name="single_bib" type="hidden" value="[% bibitemloo.biblionumber %]"/>
158                                                 <span class="confirmjs_hold" title="[% bibitemloo.biblionumber %]" style="padding:.3em"></span>
159                                                 <span class="confirm_nonjs">
160                                                     <input type="radio" class="confirmbox checkitem [% bibitemloo.biblionumber %]" name="[% bibitemloo.biblionumber %]" checked="checked" id="single_[% bibitemloo.biblionumber %]" value="any" />
161                                                     <label class="confirm_label" for="single_[% bibitemloo.biblionumber %]">Place a hold on </label>
162                                                 </span>
163                                             [% END # / bibitemloo.holdable %]
164
165                                             <a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% bibitemloo.biblionumber %]">
166                                                 [% bibitemloo.title |html %]
167                                                 [% IF ( bibitemloo.subtitle ) %]
168                                                     [% FOREACH subtitl IN bibitemloo.subtitle %]
169                                                         [% subtitl.subfield %]
170                                                     [% END %]
171                                                 [% END %]
172                                             </a>
173                                             [% IF ( bibitemloo.author ) %],  by [% bibitemloo.author %][% END %]
174                                         </p>
175
176                                         [% UNLESS ( bibitemloo.holdable ) %]
177                                             [% IF ( bibitemloo.ageRestricted ) %]
178                                                 <div class="alert">Sorry, you are too young to reserve this material.</div>
179                                             [% END %]
180                                             [% IF ( bibitemloo.already_reserved ) %]
181                                                 <div class="alert">You have already requested this title.</div>
182                                             [% ELSE %]
183                                                 [% UNLESS ( bibitemloo.bib_available ) %]
184                                                     <div class="alert">No available items.</div>
185                                                 [% ELSE %]
186                                                     [% IF ( bibitemloo.already_patron_possession ) %]
187                                                         <div class="alert">This title cannot be requested because it's already in your possession.</div>
188                                                     [% ELSE %]
189                                                         <div class="alert">This title cannot be requested.</div>
190                                                     [% END %]
191                                                 [% END # / UNLESS bibitemloo.bib_available %]
192                                             [% END # / IF bibitemloo.already_reserved %]
193                                         [% END # / UNLESS bibitemloo.holdable %]
194
195                                         [% IF ( bibitemloo.holdable ) %]
196                                             <fieldset class="rows">
197                                                 <ul>
198                                                     <!-- HOLDABLE -->
199                                                     [% UNLESS ( item_level_itypes ) %]
200                                                         <li class="itype">
201                                                             <span class="label">Item type: </span>
202                                                             [% IF ( bibitemloo.imageurl ) %]<img src="[% bibitemloo.imageurl %]" alt="" />[% END %]
203                                                             [% bibitemloo.translated_description %]
204                                                         </li>
205                                                     [% END %]
206
207                                                     [% SET OPACShowHoldQueueDetails = Koha.Preference('OPACShowHoldQueueDetails') %]
208                                                     [% IF OPACShowHoldQueueDetails == 'holds_priority' || OPACShowHoldQueueDetails == 'priority' %]
209                                                         <li class="priority">
210                                                             <span class="label">Your priority: </span>
211                                                             [% bibitemloo.rank %]
212                                                         </li>
213                                                     [% END %]
214
215                                                     [% IF OPACShowHoldQueueDetails == 'holds_priority' || OPACShowHoldQueueDetails == 'holds' %]
216                                                         <li class="holds-count">
217                                                             <span class="label">Number of holds: </span>
218                                                             [% bibitemloo.reservecount %]
219                                                         </li>
220                                                     [% END %]
221
222
223                                                     [% UNLESS ( singleBranchMode ) %]
224                                                         [% IF ( bibitemloo.holdable && choose_branch ) %]
225                                                             <li class="branch">
226                                                                 <label for="branch_[% bibitemloo.biblionumber %]">Pick up location:</label>
227                                                                 [% UNLESS ( bibitemloo.holdable ) %]
228                                                                     <select name="branch" id="branch_[% bibitemloo.biblionumber %]" disabled="disabled">
229                                                                         [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
230                                                                     </select>
231                                                                 [% ELSE %]
232                                                                     [% SET at_least_one_library_not_available_for_pickup = 0 %]
233                                                                     <select name="branch" id="branch_[% bibitemloo.biblionumber %]">
234                                                                         [% FOREACH library IN Branches.all( selected => branch) %]
235                                                                             [% SET pickup_available_at = bibitemloo.not_available_at.grep(library.branchcode).size ? 0 : 1 %]
236                                                                             [% IF library.selected AND pickup_available_at %]
237                                                                                 <option value="[% library.branchcode %]" selected="selected" >[% library.branchname %]</option>
238                                                                             [% ELSIF pickup_available_at %]
239                                                                                 <option value="[% library.branchcode %]">[% library.branchname %]</option>
240                                                                             [% ELSE %]
241                                                                                 [% SET at_least_one_library_not_available_for_pickup = 1 %]
242                                                                                 <option value="[% library.branchcode %]" disabled="disabled" title="At least one item is available at this library">[% library.branchname %]</option>
243                                                                             [% END %]
244                                                                         [% END %]
245                                                                     </select>
246                                                                     [% IF at_least_one_library_not_available_for_pickup %]
247                                                                         <br>Note: Library policy does not allow hold/pickup of an item available locally. Please come to the library to retrieve these items
248                                                                     [% END %]
249                                                                 [% END # / UNLESS bibitemloo.holdable %]
250                                                             </li>
251                                                         [% END # / IF bibitemloo.holdable && choose_branch %]
252                                                     [% END # / UNLESS singleBranchMode %]
253                                                 </ul>
254
255                                                 <a class="toggle-hold-options" id="toggle-hold-options-[% bibitemloo.biblionumber %]" style="display:none;" href="#">Show more options</a>
256
257                                                 <div id="hold-options-[% bibitemloo.biblionumber %]" class="hold-options">
258
259                                                     <ul>
260                                                         [% IF ( reserve_in_future ) %]
261                                                             <li>
262                                                                 <label for="from[% bibitemloo.biblionumber %]">Hold starts on date:</label>
263                                                                 <input type="text" name="reserve_date_[% bibitemloo.biblionumber %]" id="from[% bibitemloo.biblionumber %]" size="10" class="holddatefrom"/>
264                                                                 <span class="date-format from" data-biblionumber="[% bibitemloo.biblionumber %]">[% INCLUDE 'date-format.inc' %]</span>
265                                                             </li>
266                                                         [% END %]
267
268                                                         <li>
269                                                             <label for="to[% bibitemloo.biblionumber %]">Hold not needed after:</label>
270                                                             <input type="text" name="expiration_date_[% bibitemloo.biblionumber %]" id="to[% bibitemloo.biblionumber %]" size="10" class="holddateto" />
271                                                             <span class="date-format to" data-biblionumber="[% bibitemloo.biblionumber %]">[% INCLUDE 'date-format.inc' %]</span>
272                                                         </li>
273
274                                                         [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
275                                                             [% itemtypes = [] %]
276                                                             [% FOREACH item IN bibitemloo.itemLoop %]
277                                                                 [% itemtypes.push( item.itype ) %]
278                                                             [%- END %]
279                                                             <li>
280                                                                 <label for="itemtype">Request specific item type:</label>
281                                                                 <select name="itemtype" size="1" id="itemtype">
282                                                                     <option value="">Any item type</option>
283                                                                     [% FOREACH i IN itemtypes.unique.sort %]
284                                                                         <option value="[% i %]">[% ItemTypes.GetDescription( i ) %]</option>
285                                                                     [%- END %]
286                                                                 </select>
287                                                             </li>
288                                                         [% END %]
289
290                                                         [% IF ( OpacHoldNotes ) %]
291                                                             <li>
292                                                                 <div class="notesrow" id="notesrow_[% bibitemloo.biblionumber %]">
293                                                                     <label for="holdnotes_[% bibitemloo.biblionumber %]">Hold notes:</label>
294                                                                     [% IF bibitemloo.reqholdnotes %]
295                                                                         <span id="reqholdnotes_[% bibitemloo.biblionumber %]">Please enter additional information about the requested item:</span>
296                                                                     [% END %]
297                                                                     <textarea id="holdnotes_[% bibitemloo.biblionumber %]" rows="2" cols="30" name="notes_[% bibitemloo.biblionumber %]" >[% bibitemloo.holdnotes %]</textarea>
298                                                                 </div>
299                                                             </li>
300                                                         [% END # / IF OpacHoldNotes %]
301
302                                                         [% IF bibitemloo.itemholdable %]
303                                                             <!-- ITEM HOLDS -->
304                                                             <li class="lradio place_on_type" style="display:none;">
305                                                                 [% IF NOT bibitemloo.force_hold %]
306                                                                     <label class="radio inline" for="reqany_[% bibitemloo.biblionumber %]">Next available item</label>
307                                                                     <input type="radio" name="reqtype_[% bibitemloo.biblionumber %]"
308                                                                             id="reqany_[% bibitemloo.biblionumber %]"
309                                                                             class="selectany"
310                                                                             value="Any"
311                                                                             checked="checked"
312                                                                     />
313                                                                 [% END %]
314                                                                 <label class="radio inline" for="reqspecific_[% bibitemloo.biblionumber %]">A specific item</label>
315                                                                 <input type="radio" name="reqtype_[% bibitemloo.biblionumber %]"
316                                                                        id="reqspecific_[% bibitemloo.biblionumber %]"
317                                                                        class="selectspecific"
318                                                                        value="Specific"
319                                                                 />
320                                                             </li>
321                                                         [% END # / IF bibitemloo.itemholdable %]
322                                                     </ul>
323
324                                                     [% IF bibitemloo.itemholdable %]
325                                                         <table class="copiesrow table table-bordered table-striped" id="copiesrow_[% bibitemloo.biblionumber %]">
326                                                             <caption>Select a specific item:</caption>
327                                                             <tr>
328                                                                 <th>Copy number</th>
329                                                                 [% IF ( item_level_itypes ) %]
330                                                                     <th>Item type</th>
331                                                                 [% END %]
332                                                                 <th>Barcode</th>
333                                                                 [% UNLESS ( singleBranchMode ) %]
334                                                                     <th>Home library</th>
335                                                                     <th>Last location</th>
336                                                                 [% END %]
337                                                                 <th>Call number</th>
338                                                                 [% IF ( itemdata_enumchron ) %]
339                                                                     <th>Vol info</th>
340                                                                 [% END %]
341                                                                 <th>Information</th>
342                                                             </tr>
343
344                                                             [% FOREACH itemLoo IN bibitemloo.itemLoop %]
345                                                                 <tr class="[% itemLoo.backgroundcolor %]">
346                                                                     <td class="copynumber">
347                                                                         [% IF ( itemLoo.available ) %]
348                                                                             <input type="radio" class="checkitem checkitem_[% bibitemloo.biblionumber %]" name="checkitem_[% bibitemloo.biblionumber %]" value="[% itemLoo.itemnumber %]" />
349                                                                         [% ELSE %]
350                                                                             <input disabled="disabled" type="radio" class="checkitem" name="checkitem" value="[% itemLoo.itemnumber %]"
351                                                                                    style="display:none;" />
352                                                                             <img src="[% interface %]/lib/famfamfam/silk/cross.png" alt="Cannot be put on hold" title="Cannot be put on hold" />
353                                                                         [% END %]
354
355                                                                         [% IF ( itemLoo.copynumber ) %]
356                                                                             [% itemLoo.copynumber %]
357                                                                         [% END %]
358                                                                     </td>
359
360                                                                     [% IF ( item_level_itypes ) %]
361                                                                         <td class="itype">
362                                                                             [% UNLESS ( noItemTypeImages ) %]
363                                                                                 [% IF ( itemLoo.imageurl ) %]
364                                                                                     <img src="[% itemLoo.imageurl %]" alt="" />
365                                                                                 [% END %]
366                                                                             [% END %]
367                                                                             [% itemLoo.translated_description %]
368                                                                         </td>
369                                                                     [% END %]
370
371                                                                     <td class="barcode">[% itemLoo.barcode %]</td>
372                                                                     [% UNLESS ( singleBranchMode ) %]
373                                                                         <td class="homebranch">[% Branches.GetName( itemLoo.homeBranchName ) %]</td>
374                                                                         <td class="holdingbranch">[% Branches.GetName( itemLoo.holdingBranchName ) %]</td>
375                                                                     [% END %]
376                                                                     <td class="call_no">[% itemLoo.callNumber %]</td>
377                                                                     [% IF ( itemdata_enumchron ) %]
378                                                                         <td class="vol_info">[% itemLoo.enumchron %]</td>
379                                                                     [% END %]
380                                                                     <td class="information">
381                                                                         [% IF ( itemLoo.dateDue ) %]
382                                                                             <span class="checkedout">Due [% itemLoo.dateDue %]</span>
383                                                                         [% ELSIF ( itemLoo.transfertwhen ) %]
384                                                                             <span class="intransit">In transit from [% Branches.GetName( itemLoo.transfertfrom ) %] to [% Branches.GetName( itemLoo.transfertto ) %] since [% itemLoo.transfertwhen %]</span>
385                                                                         [% END %]
386
387                                                                         [% IF ( itemLoo.message ) %]
388                                                                             <span class="lost">Unavailable (lost or missing)</span>
389                                                                         [% END %]
390
391                                                                         [% IF ( itemLoo.notforloan ) %]
392                                                                             <span class="notforloan">Not for loan ([% itemLoo.notforloanvalue %])</span>
393                                                                         [% END %]
394
395                                                                         [% IF ( itemLoo.reservedate ) %]
396                                                                             <span class="waiting">
397                                                                                 [% IF ( itemLoo.waitingdate ) %]
398                                                                                     Waiting
399                                                                                 [% ELSE %]
400                                                                                     On hold
401                                                                                 [% END %]
402                                                                                 for patron
403                                                                                 [% IF ( itemLoo.waitingdate ) %]
404                                                                                     at
405                                                                                 [% ELSE %]
406                                                                                     expected at
407                                                                                 [% END %]
408                                                                                 [% itemLoo.ExpectedAtLibrary %] since
409                                                                                 [% IF ( itemLoo.waitingdate ) %]
410                                                                                     [% itemLoo.waitingdate | $KohaDates %]
411                                                                                 [% ELSE %]
412                                                                                     [% IF ( itemLoo.reservedate ) %]
413                                                                                         [% itemLoo.reservedate %]
414                                                                                     [% END %]
415                                                                                 [% END %].
416                                                                             </span>
417                                                                         [% ELSE %]
418                                                                             <span class="notonhold">Not on hold</span>
419                                                                         [% END # / IF ( itemLoo.reservedate )%]
420                                                                     </td>
421                                                                 </tr>
422                                                             [% END # / FOREACH itemLoo IN bibitemloo.itemLoop%]
423                                                         </table> <!-- / #copiesrow_[% bibitemloo.biblionumber %] -->
424                                                     [% END # / IF ( bibitemloo.itemholdable )%]
425                                                 </div> <!-- / #hold-options-[% bibitemloo.biblionumber %] -->
426                                             </fieldset>
427                                         [% END # / IF ( bibitemloo.holdable ) %]
428                                     </div> <!-- / .holdrow -->
429                                 [% END # / FOREACH bibitemloo IN bibitemloop %]
430                             </div><!-- #bigloop -->
431
432                             [% UNLESS ( none_available ) %]
433                                 <input type="submit" value="Confirm hold" class="btn placehold" />
434                             [% END %]
435
436                         </form>
437                     [% END # / UNLESS message %]
438                 </div> <!-- / #holds -->
439     </div> <!-- / .container -->
440 </div> <!-- / .main -->
441 [% INCLUDE 'opac-bottom.inc' %]
442 [% BLOCK jsinclude %]
443 [% INCLUDE 'calendar.inc' %]
444 <script type="text/javascript">
445 // <![CDATA[
446     var MSG_NO_ITEM_SELECTED = _("Expecting a specific item selection.");
447
448         // Clear the contents of an input field
449         $(".clearfield").on("click",function(e){
450             $(this).closest("td").find("input").val("");
451             e.preventDefault();
452         });
453
454     // Select the first item available
455     function select_first_available(id){
456         var radios = $("input:radio[name='checkitem_" + id + "']");
457         $(radios).first().attr("checked", "checked");
458     }
459
460     $(document).ready(function() {
461         $("#hold-request-form").preventDoubleFormSubmit();
462         var copiesRowId = null;
463         var wasSpecific = false;
464         var lastCopiesRowId = null;
465
466         $(".toggle-hold-options").show();
467         $(".hold-options").hide();
468         $(".holddatefrom,.holddateto").prop("readOnly", true);
469
470         $(".checkitem").parent().click(function(e){
471             if(e.target.tagName.toLowerCase() == 'td'){
472                 $(this).find("input.checkitem").each( function() {
473                     $(this).attr('checked', 'checked');
474                 });
475             }
476         });
477
478         // click on a first td check the confirmjs checkbox
479         $("td.hold").click(function(e){
480           if(e.target.tagName.toLowerCase() == 'td'){
481             $(this).find("input.confirmjs").each( function() {
482                $(this).attr('checked', !$(this).attr('checked'));
483                $(this).change();
484             });
485           }
486         });
487
488         $(".toggle-hold-options").on("click",function(e){
489             e.preventDefault();
490             toggleLink = $(this);
491             var optionsID = this.id.replace("toggle-hold-options-","");
492             $("#hold-options-"+optionsID).toggle(0, function() {
493                 toggleLink.text($(this).is(':visible') ? _("Hide options") : _("Show more options"));
494             });
495         });
496
497         // Hides all 'specific copy' table rows on load.
498         $(".copiesrow").hide();
499
500         [% FOREACH bibitemloo IN bibitemloop %]
501           [% IF bibitemloo.force_hold %]
502             $("#toggle-hold-options-[% bibitemloo.biblionumber %]").click();
503             $("#reqspecific_[% bibitemloo.biblionumber %]").click();
504             $("#copiesrow_[% bibitemloo.biblionumber %]").show();
505           [% END %]
506           [% IF bibitemloo.reqholdnotes %]
507               $("#holdnotes_[% bibitemloo.biblionumber %]").attr( 'required', true );
508           [% END %]
509         [% END %]
510
511         $(".date-format").each(function(){
512             if($(this).hasClass("to")){ var op = "to"; }
513             if($(this).hasClass("from")){ var op = "from"; }
514             var bibNum = $(this).data("biblionumber");
515             $(this).html("<a href=\"#\" class=\"clear-date\" data-op=\"" + op + "\" id=\"clear" + bibNum + "\">" + _("Clear date") + "</a>");
516         });
517
518         $(".clear-date").on("click",function(e){
519             e.preventDefault();
520             var fieldID = this.id.replace("clear","");
521             var op = $(this).data("op");
522             $("#" + op + fieldID).val("");
523         });
524
525         // Replace non-JS single-selection with multi-selection capability.
526         $(".reserve_mode").val("multi");
527         $(".confirm_nonjs").remove();
528         $(".confirmjs_hold").each(function(){
529             var bib = $(this).attr("title");
530             var html = "<label><input type =\"checkbox\" class=\"confirmjs\" checked=\"checked\"";
531             html += "value=\"" + bib + "\" id=\"" + bib + "\" /> " + _("Place a hold on") + " </label> ";
532             $(this).html(html);
533         });
534         $(".confirmjs_nohold").each(function(){
535             var bib = $(this).attr("title");
536             var html = "<label><input type =\"checkbox\" class=\"confirmjs\" disabled=\"disabled\"";
537             html += "value=\"" + bib + "\" id=\"" + bib + "\" />" + _("Place a hold on: ") + "</label>";
538             $(this).html(html);
539         });
540
541         // expand or collapse the copiesrow tr
542         function toggle_copiesrow(biblioNum) {
543             var checkbox = $("input:checkbox[value='"+biblioNum+"']");
544             newCopiesRowId = "#copiesrow_" + biblioNum;
545             var select_specific = $("#reqspecific_"+biblioNum).is(":checked");
546             // If the checkbox is checked AND we want a specific item, we display the items block
547             if ( $(checkbox).is(":checked") && select_specific ) {
548                 $(newCopiesRowId).show();
549             } else {
550                 $(newCopiesRowId).hide();
551              }
552         };
553
554         $("#place_on_hdr").show();
555
556         $(".place_on_type").show();
557         // onload, selectany is checked
558         $(".selectany").attr("checked", "checked");
559
560         // If the user is *allowed* to choose a specific item
561         // The first one is preselected
562         $("table.copiesrow").each(function(){
563             var id = suffixOf($(this).attr("id"), "_");
564             select_first_available(id);
565         });
566
567         // On confirmsjs change
568         $(".confirmjs").change(function(){
569             var id = suffixOf($(this).attr("id"), "_");
570             // If I m checked, I enable radio buttons
571             if ( $(this).is(":checked") ) {
572                 $("#reqspecific_" + id).attr("disabled", false);
573                 $("#reqany_" + id).attr("disabled", false);
574             }
575             // Else its are disabled
576             else {
577                 $("#reqspecific_" + id).attr("disabled", "disabled");
578                 $("#reqany_" + id).attr("disabled", "disabled");
579             }
580             // expand or collaspe the items block
581             toggle_copiesrow(id);
582         });
583
584         // When 'specific copy' or 'first available' radio button is clicked
585         $(".selectspecific, .selectany").click(function() {
586             var id = suffixOf($(this).attr("id"), "_");
587             toggle_copiesrow(id);
588         });
589
590         // Show or hide holds notes
591         $(".shownotes").click(function(){
592             biblioNum = suffixOf($(this).attr("id"), "_");
593             $("#notesrow_"+biblioNum).toggle();
594         });
595
596         // When 'Place Hold' button is clicked
597         $(".placehold").click(function(){
598             var biblionumbers = "";
599             var selections = "";
600
601             [% IF new_reserves_allowed %]
602                 if ($(".confirmjs:checked").size() > [% new_reserves_allowed %] ) {
603                     alert(MSG_MAX_HOLDS_EXCEEDED);
604                     return false;
605                 }
606             [% END %]
607
608             if ($(".confirmjs:checked").size() == 0) {
609                 alert(MSG_NO_RECORD_SELECTED);
610                 return false;
611             }
612
613             // Find the items with the 'Hold' box checked
614             var badBib = null;
615             $(".confirmjs:checked").each(function() {
616                 var biblioNum = $(this).val();
617                 biblionumbers += biblioNum + "/";
618                 selections += biblioNum + "/";
619
620                 // If required hold note is empty, make it visible
621                 if( $("#holdnotes_"+biblioNum).attr( 'required' ) && $("#holdnotes_"+biblioNum).val() == '' ) {
622                     if( !$("#hold-options-"+biblioNum).is(':visible')) {
623                         $("#toggle-hold-options-"+biblioNum).click();
624                     }
625                 }
626
627                 // If the 'specific copy' radio button is checked
628                 if ($("#reqspecific_" + biblioNum + ":checked").size() > 0) {
629                     // Find the selected copy
630                     var item = $(".checkitem_" + biblioNum + ":checked");
631                     if ($(item).size() == 0) {
632                         alert(MSG_NO_ITEM_SELECTED);
633                         badBib = biblioNum;
634                         return false;
635                     } else {
636                       selections += $(item).val();
637                     }
638                 }
639                 selections += "/";
640
641                 // Add the pickup location
642                 var branchSel = $("#branch_" + biblioNum);
643                 if (branchSel.size() > 0) {
644                     selections += $(branchSel).val();
645                 }
646                 selections += "/";
647                 return true;
648             });
649
650             if (badBib) { // alert has been raised already
651                 return false;
652             }
653
654             $("#selections").val(selections);
655             $("#biblionumbers").val(biblionumbers);
656
657             return true;
658         });
659
660         [% FOREACH bibitemloo IN bibitemloop %]
661             [% IF ( bibitemloo.holdable ) %]
662                 // http://jqueryui.com/demos/datepicker/#date-range
663                 var dates[% bibitemloo.biblionumber %] = $( "#from[% bibitemloo.biblionumber %], #to[% bibitemloo.biblionumber %]" ).datepicker({
664                     minDate: 0,
665                     changeMonth: true,
666                     numberOfMonths: 1,
667                     onSelect: function( selectedDate ) {
668                         var option = this.id == "from[% bibitemloo.biblionumber %]" ? "minDate" : "maxDate",
669                             instance = $( this ).data( "datepicker" );
670                             date = $.datepicker.parseDate(
671                                 instance.settings.dateFormat ||
672                                 $.datepicker._defaults.dateFormat,
673                                 selectedDate, instance.settings );
674                         dates[% bibitemloo.biblionumber %].not( this ).datepicker( "option", option, date );
675                     }
676                 });
677             [% END %]
678         [% END %]
679
680  });
681 // ]]>
682 </script>
683 [% END %]