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