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