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