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