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