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