Bug 29058: Don't display 'Always show holds' at the bottom of the patron list
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / reserve / request.tt
index 642b3d7..306b8ea 100644 (file)
@@ -1,45 +1,85 @@
 [% USE raw %]
 [% USE To %]
 [% USE Asset %]
+[% USE JSON.Escape %]
 [% USE Koha %]
+[% USE Biblio %]
 [% USE KohaDates %]
 [% USE Branches %]
 [% USE Categories %]
 [% USE ItemTypes %]
 [% USE AuthorisedValues %]
 [% USE Price %]
+[% USE TablesSettings %]
+[% PROCESS 'i18n.inc' %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 [% UNLESS ( multi_hold ) %]
-    <title>Koha &rsaquo; Circulation &rsaquo; Holds &rsaquo; Place a hold on [% INCLUDE 'biblio-title-head.inc' %]</title>
+    <title>Place a hold on [% INCLUDE 'biblio-title-head.inc' %] &rsaquo; Holds &rsaquo; Circulation &rsaquo; Koha</title>
 [% ELSE %]
-    <title>Koha &rsaquo; Circulation &rsaquo; Holds &rsaquo; Confirm holds</title>
+    <title>Confirm holds &rsaquo; Holds &rsaquo; Circulation &rsaquo; Koha</title>
 [% END %]
 [% INCLUDE 'doc-head-close.inc' %]
+[% Asset.css("css/holds.css") | $raw %]
 </head>
 
 <body id="circ_request" class="catalog">
+
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'circ-search.inc' %]
 
 [% UNLESS ( multi_hold ) %]
-    <div id="breadcrumbs">
-        <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
-        <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo;
-        <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">[% biblio.title | html %]</a> &rsaquo;
-        Place a hold on [% INCLUDE 'biblio-title.inc' %]
-    </div>
+    <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
+        <ol>
+            <li>
+                <a href="/cgi-bin/koha/mainpage.pl">Home</a>
+            </li>
+            <li>
+                <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>
+            </li>
+            <li>
+                [% INCLUDE 'biblio-title.inc' link =1 %]
+            </li>
+            <li>
+                <a href="#" aria-current="page">
+                    Place a hold
+                </a>
+            </li>
+        </ol>
+    </nav>
 [% ELSE %]
-    <div id="breadcrumbs">
-        <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
-        <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a> &rsaquo;
-        Confirm holds
-    </div>
+    <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
+        <ol>
+            <li>
+                <a href="/cgi-bin/koha/mainpage.pl">Home</a>
+            </li>
+            <li>
+                <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>
+            </li>
+            <li>
+                [% IF ( patron ) %]
+                    <a href="#" aria-current="page">
+                        Place holds
+                    </a>
+                [% ELSE %]
+                    [% IF clubcount %]
+                        <a href="#" aria-current="page">
+                            Search patrons or clubs
+                        </a>
+                    [% ELSE %]
+                        <a href="#" aria-current="page">
+                            Search patrons
+                        </a>
+                    [% END %]
+                [% END %]
+            </li>
+        </ol>
+    </nav>
 [% END # UNLESS multi_hold %]
 
 <div class="main container-fluid">
     <div class="row">
-        [% IF ( multi_hold ) # No sidebar menu when placing multiple holds %]
+        [% IF ( multi_hold || nobiblio ) # No sidebar menu when placing multiple holds or biblio not found %]
             <div class="col-md-10 col-md-offset-1">
         [% ELSE %]
             <div class="col-sm-10 col-sm-push-2">
 
         <main>
 
+            [% IF ( nobiblio ) %]
+                <div class="dialog alert">
+                [%IF (multi_hold) %]
+                    <strong>Cannot place hold:</strong> one or more records don't exist.
+                [% ELSE %]
+                    <strong>Cannot place hold:</strong> this record doesn't exist.
+                [% END %]
+                </div>
+            [% END %]
             [% IF ( noitems ) %]
                 <div class="dialog alert">
                 [%IF (multi_hold) %]
             [% END %]
 
             [% UNLESS ( multi_hold ) %]
-                <h1>Place a hold on [% INCLUDE 'biblio-default-view.inc' %][% INCLUDE 'biblio-title.inc' %]</a></h1>
+                <h1>Place a hold on [% INCLUDE 'biblio-title.inc' link = 1 %]</h1>
             [% ELSE %]
-                <h1>Confirm holds</h1>
+                <h1>
+                    [% IF ( patron ) %]
+                        Place holds
+                    [% ELSE %]
+                        [% IF clubcount %]
+                            Search patrons or clubs
+                        [% ELSE %]
+                            Search patrons
+                        [% END %]
+                    [% END %]
+                </h1>
             [% END %]
 
-            [% UNLESS club OR patron OR patron.borrowernumber OR noitems %]
+            [% UNLESS club OR patron OR patron.borrowernumber OR noitems OR nobiblio %]
                 [% IF ( messageborrower ) %]
                     <div class="dialog alert">
                         <h3>Patron not found</h3>
                     </div>
                 [% END %]
                 <fieldset class="brief">
-                    <label>Search patrons or clubs</label>
+                    [% UNLESS multi_hold %]
+                        [% IF clubcount %]
+                            <label>Search patrons or clubs</label>
+                        [% ELSE %]
+                            <label>Search patrons</label>
+                        [% END %]
+                    [% END %]
                     <div id="circ_holds_select" class="toptabs">
                         <ul>
                             <li><a href="#holds_patronsearch_pane">Patrons</a></li>
-                            <li><a href="#holds_clubsearch_pane">Clubs</a></li>
+                            [% IF clubcount %]
+                                <li><a href="#holds_clubsearch_pane">Clubs</a></li>
+                            [% END %]
                         </ul>
                         <div id="holds_patronsearch_pane">
                             <form id="holds_patronsearch" action="request.pl?biblionumbers=[% biblionumbers | html %]" method="post">
                                 [% INCLUDE 'circ-patron-search-results.inc' destination = "holds" %]
                             [% END %]
                         </div>
-                        <div id="holds_clubsearch_pane">
-                            <form id="holds_clubsearch" action="request.pl?biblionumber=[% biblionumber | html %]" method="post">
-                                <div class="hint">Enter club ID or partial name:</div>
-                                <input type="text" size="40" id="club" class="focus" name="findclub" autocomplete="off" />
-                                <input type="submit" value="Search" />
-                                [% IF multi_hold %]
-                                    <input type="hidden" name="biblionumbers" value="[% biblionumbers | html %]"/>
-                                [% ELSE %]
-                                    <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
-                                [% END %]
+                        [% IF clubcount %]
+                            <div id="holds_clubsearch_pane">
+                                <form id="holds_clubsearch" action="request.pl?biblionumbers=[% biblionumbers | html %]" method="post">
+                                    <div class="hint">Enter club ID or partial name:</div>
+                                    <input type="text" size="40" id="club" class="focus" name="findclub" autocomplete="off" />
+                                    <input type="submit" value="Search" />
+                                    [% IF multi_hold %]
+                                        <input type="hidden" name="biblionumbers" value="[% biblionumbers | html %]"/>
+                                    [% ELSE %]
+                                        <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
+                                    [% END %]
 
-                            </form> <!-- /#holds_patronsearch -->
-                            [% IF clubs %]
-                                [% INCLUDE 'clubs-table.inc' destination = "holds" %]
-                            [% END %]
-                        </div>
+                                </form> <!-- /#holds_patronsearch -->
+                                [% IF clubs %]
+                                    [% INCLUDE 'clubs-table.inc' destination = "holds" %]
+                                [% END %]
+                            </div>
+                        [% END %]
                     </div>
                 </fieldset>
             [% ELSIF club %]
                             </li>
                             <li>
                                 <label for="pickup">Pickup at:</label>
-                                <select name="pickup" size="1" id="pickup">
+                                <select name="pickup" id="pickup_club">
                                     [% PROCESS options_for_libraries libraries => Branches.all({ selected => club.branchcode, search_params => { pickup_location => 1 } }) %]
                                 </select>
                             </li>
                                             <strong>Too many holds: </strong> Patron can only place a maximum of [% maxreserves | html %] total holds.
                                         </div>
                                     [% END %]
-                                    [% IF ( member.expiry ) %]
+                                    [% IF ( patron.is_expired ) %]
                                         <div>
                                             <i class="fa fa-warning"></i>
                                             <strong>Account has expired</strong>
                                             <strong>Patron has restrictions</strong>
                                         </div>
                                     [% END %]
-                                    [% IF amount_outstanding && Koha.Preference('maxoutstanding') && amount_outstanding > Koha.Preference('maxoutstanding') %]
+                                    [% IF member.amount_outstanding && Koha.Preference('maxoutstanding') && member.amount_outstanding > Koha.Preference('maxoutstanding') %]
                                         <div>
                                             <i class="fa fa-warning"></i>
                                             <strong>Patron has outstanding fines: [% member.amount_outstanding | $Price %]</strong>
                                     [% END %]
                                 </li>
                             [% END %]
-                        </ol>
                         [% UNLESS ( multi_hold ) %]
                             <fieldset class="action">
                                 <input type="submit" value="Place hold" />
                                             [% IF ( biblioloo.alreadyres ) %]
                                                 <ul>
                                             [% ELSE %]
-                                                [% IF ( biblioloo.none_avail ) %]
+                                                [% IF ( biblioloo.none_avail || biblioloo.noitems ) %]
                                                     <ul>
                                                 [% END %]
                                             [% END %]
                                                     <strong>already has a hold</strong> on this item
                                                 </li>
                                             [% END %]
-                                            [% IF ( biblioloo.none_avail ) %]
+                                            [% IF ( biblioloo.none_avail || biblioloo.noitems ) %]
                                                 <li> <strong>No items are available</strong> to be placed on hold</li>
                                             [% END %]
 
                                             [% IF ( biblioloo.alreadyres ) %]
                                                 </ul>
                                             [% ELSE %]
-                                                [% IF ( biblioloo.none_avail ) %]
+                                                [% IF ( biblioloo.none_avail || biblioloo.noitems ) %]
                                                     </ul>
                                                 [% END %]
                                             [% END %]
                         [% END %]
                     </form>
                 </fieldset>
-            [% ELSIF NOT noitems # /UNLESS patron %]
+            [% ELSIF NOT ( noitems || nobiblio ) # /UNLESS patron %]
 
                 [% IF ( checked_previously && !multi_hold ) %]
                     <div class="dialog alert">
                     </div>
                 [% END %]
 
-                [% IF ( exceeded_maxreserves || exceeded_holds_per_record || alreadyreserved || none_available || alreadypossession || ageRestricted ) %]
+                [% IF ( no_reserves_allowed || exceeded_maxreserves || exceeded_holds_per_record || alreadyreserved || none_available || alreadypossession || ageRestricted ) %]
                     <div class="dialog alert">
 
                         [% UNLESS ( multi_hold ) %]
                             <h3>Cannot place hold</h3>
                             <ul>
-                                [% IF ( exceeded_maxreserves ) %]
+                                [% IF ( no_reserves_allowed ) %]
+                                    <li><strong>No holds allowed: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% patron.firstname | html %] [% patron.surname | html %] </a> cannot place a hold on any of these items.</li>
+                                [% ELSIF ( exceeded_maxreserves ) %]
                                     <li><strong>Too many holds: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% patron.firstname | html %] [% patron.surname | html %] </a> can only place a maximum of [% maxreserves | html %] total holds.</li>
                                 [% ELSIF ( exceeded_holds_per_record ) %]
                                     <li><strong>Too many holds for this record: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% patron.firstname | html %] [% patron.surname | html %] </a> can only place a maximum of [% max_holds_for_record | html %] hold(s) on this record.</li>
                             </ul>
                         [% ELSE # UNLESS multi_hold %]
                             <h3>Cannot place hold on some items</h3>
-                            [% IF ( exceeded_maxreserves ) %]
+                            [% IF (no_reserves_allowed ) %]
+                                <li><strong>No holds allowed: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% patron.firstname | html %] [% patron.surname | html %] </a> cannot place holds on some of these title's items.</li>
+                            [% ELSIF ( exceeded_maxreserves ) %]
                                 <li><strong>Too many holds: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% patron.firstname | html %] [% patron.surname | html %] </a> can place [% new_reserves_allowed | html %] of the requested [% new_reserves_count | html %] holds for a maximum of [% maxreserves | html %] total holds.</li>
                             [% ELSIF ( exceeded_holds_per_record ) %]
                                 [% FOREACH biblioloo IN biblioloop %]
                     </div>
                 [% END # /IF ( exceeded_maxreserves || ... %]
 
-                [% IF ( expiry || diffbranch || patron.is_debarred || ( amount_outstanding && Koha.Preference('maxoutstanding') && amount_outstanding > Koha.Preference('maxoutstanding') ) ) %]
+                [% IF ( patron.is_expired || diffbranch || patron.is_debarred || ( amount_outstanding && Koha.Preference('maxoutstanding') && amount_outstanding > Koha.Preference('maxoutstanding') ) ) %]
                     <div class="dialog message">
                         <ul>
-                            [% IF ( expiry ) %]
+                            [% IF ( patron.is_expired ) %]
                                 <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% patron.firstname | html %] [% patron.surname | html %]</a>: <strong>Account has expired</strong></li>
                             [% END %]
 
                             [% END %]
                         </ul> <!-- /.dialog.message -->
                     </div>
-                [% END # /IF expiry || diffbranch ... %]
+                [% END # /IF patron.is_expired || diffbranch ... %]
 
                 [% IF ( messageborrower ) %]
                     <div class="dialog alert">
 
                         [% IF ( multi_hold ) %]
                             <input type="hidden" name="biblionumbers" id="multi_hold_bibs" value="[% biblionumbers | html %]"/>
+                            <input type="hidden" name="multi_holds" id="multi_holds" value="1" />
                             <input type="hidden" name="bad_bibs" id="bad_bibs" value=""/>
                             <input type="hidden" name="request" value="any"/>
                             [% FOREACH biblioloo IN biblioloop %]
                             </li>
                             <li>
                                 <label for="pickup">Pickup at:</label>
-                                <select name="pickup" size="1" id="pickup">
-                                    [% UNLESS ( multi_hold ) %]
-                                        [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
-                                    [% ELSE %]
-                                        [% PROCESS options_for_libraries libraries => Branches.all({ selected => pickup, search_params => { pickup_location => 1 } }) %]
-                                    [% END %]
+                            [% UNLESS ( multi_hold ) %]
+                                <select name="pickup" id="pickup"
+                                        data-biblio-id="[% biblio.biblionumber | html %]"
+                                        data-patron-id="[% patron.borrowernumber | html %]"
+                                        data-pickup-location-source="biblio">
+                                    [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
+                            [% ELSE %]
+                                <select name="pickup" id="pickup_multi" data-patron-id="[% patron.borrowernumber | html %]">
+                                    <option value="" selected="selected"></option>
+                                [% FOREACH pickup_location IN multi_pickup_locations %]
+                                    <option value="[% pickup_location.branchcode | html %]">[% pickup_location.branchname | html %]</option>
+                                [% END %]
+                            [% END %]
                                 </select>
                             </li>
 
                                 [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
                                     <li>
                                         <label for="itemtype">Request specific item type:</label>
-                                        <select name="itemtype" size="1" id="itemtype">
+                                        <select name="itemtype" id="itemtype">
                                             <option value="">Any item type</option>
                                             [%- FOREACH itemtype IN available_itemtypes %]
                                                 <option value="[% itemtype | html %]">[% ItemTypes.GetDescription( itemtype ) | html %]</option>
                             [% IF ( reserve_in_future ) %]
                                 <li>
                                     <label for="from">Hold starts on date:</label>
-                                    <input name="reserve_date" id="from" size="10" class="datepickerfrom" type="text" >
-                                    <input type="hidden" class="datepickerfrom_hidden" />
-                                    <a href="#" id="clear-date-from" class="clear-date">Clear date</a>
+                                    <input id="reserve_date" name="reserve_date" id="from" size="10" type="text" data-date_to="expiration_date" class="flatpickr" data-flatpickr-futuredate="true" />
                                 </li>
                             [% END %]
 
                             <li>
                                 <label for="to">Hold expires on date:</label>
-                                <input name="expiration_date" id="to" size="10" class="datepickerto" type="text" />
-                                <input type="hidden" class="datepickerto_hidden" />
-                                <a href="#" id="clear-date-to" class="clear-date">Clear date</a>
+                                <input id="expiration_date" name="expiration_date" id="to" size="10" type="text" class="flatpickr" data-flatpickr-futuredate="true" />
                             </li>
 
                             [% UNLESS ( multi_hold ) %]
                                 [% IF remaining_holds_for_record > 1 %]
                                     <li>
                                         <label for="holds_to_place_count">Holds to place (count)</label>
-                                        <input id="holds_to_place_count" type="number" name="holds_to_place_count" min="1" max="[% remaining_holds_for_record | html %]" step="1" value="1" />
+                                        <input type="text" inputmode="numeric" pattern="[0-9]*" id="holds_to_place_count" name="holds_to_place_count" maxlength="[% remaining_holds_for_record | html %]" value="1" />
                                     </li>
                                 [% ELSE %]
                                     <input type="hidden" name="holds_to_place_count" value="1" />
                                 <h2 style="padding: 0 1em;">
                                     Place a hold on a specific item
                                     [% IF bibitemloo.force_hold_level == 'item' %]
-                                         <span class="error"><i>(Required)</i></span>
+                                         <span class="error"><em>(Required)</em></span>
                                     [% END %]
                                 </h2>
 
                                             [% IF itemdata_ccode %]
                                                 <th>Collection</th>
                                             [% END %]
-                                            <th>Call no.</th>
+                                            <th>Call number</th>
                                             <th>Copy number</th>
                                             [% IF itemdata_enumchron %]
                                                 <th>Vol no.</th>
                                             [% END %]
-                                            <th class="title-string">Information</th>
-                                            <th class="title-string">Allowed pickup locations</th>
+                                            <th>Information</th>
+                                            <th>Allowed pickup locations</th>
                                         </tr>
                                     </thead>
                                     <tbody>
                                                                         Patron already has hold for this item
                                                                     [% ELSIF itemloo.not_holdable == 'cannotBeTransferred' %]
                                                                         Cannot be transferred to pickup library
+                                                                    [% ELSIF itemloo.not_holdable == 'pickupNotInHoldGroup' %]
+                                                                        Only pickup locations within the same hold group are allowed
+                                                                    [% ELSIF itemloo.not_holdable == 'noReservesAllowed' %]
+                                                                        No reserves are allowed on this item
+                                                                    [% ELSIF itemloo.not_holdable == 'libraryNotPickupLocation' %]
+                                                                        Library is not a pickup location
+                                                                    [% ELSIF itemloo.not_holdable == 'no_valid_pickup_location' %]
+                                                                        No valid pickup location
                                                                     [% ELSE %]
                                                                         [% itemloo.not_holdable | html %]
                                                                     [% END %]
                                                     </td>
                                                     [% IF itemdata_ccode %]
                                                         <td>
-                                                            [% IF ( itemloo.ccode ) %][% AuthorisedValues.GetByCode( 'CCODE', itemloo.ccode ) | html %][% END %]
+                                                            [% IF ( itemloo.ccode ) %][% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => itemloo.ccode ) | html %][% END %]
                                                         </td>
                                                     [% END %]
                                                     <td>
                                                             [% itemloo.enumchron | html %]
                                                         </td>
                                                     [% END %]
-                                                    <td>
-                                                        [% IF ( itemloo.onloan ) %]
-                                                            <span title="[% itemloo.date_due | html %]" class="checkedout">Due [% itemloo.date_due | $KohaDates  as_due_date => 1 %]</span>
-                                                        [% ELSE %]
-                                                            <span title="0000-00-00">
-                                                                [% IF ( itemloo.transfertwhen ) %]
-                                                                    In transit from [% Branches.GetName( itemloo.transfertfrom ) | html %],
-                                                                    to [% Branches.GetName( itemloo.transfertto ) | html %], since [% itemloo.transfertwhen | html %]
-                                                                [% END %]
-                                                            </span>
-                                                        [% END %]
+                                                    [% IF ( itemloo.onloan ) %]
+                                                        <td data-order="[% itemloo.date_due | html %]">
+                                                            <span class="checkedout">Due [% itemloo.date_due | $KohaDates  as_due_date => 1 %]</span>
+                                                    [% ELSE %]
+                                                        <td>
+                                                            [% IF ( itemloo.transfertwhen ) %]
+                                                                In transit from [% Branches.GetName( itemloo.transfertfrom ) | html %],
+                                                                to [% Branches.GetName( itemloo.transfertto ) | html %], since [% itemloo.transfertwhen | html %]
+                                                            [% END %]
+                                                    [% END %]
 
                                                         [% IF ( itemloo.reservedate ) %]
                                                             [% IF ( itemloo.nocancel ) %]
                                                         [% END %]
 
                                                         [% IF ( itemloo.itemlost ) %]
-                                                           <span class="lost">[% AuthorisedValues.GetByCode( 'LOST', itemloo.itemlost ) | html %]</span>
+                                                           <span class="lost">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.itemlost', authorised_value => itemloo.itemlost ) | html %]</span>
                                                         [% END %]
 
                                                         [% IF ( itemloo.damaged ) %]
-                                                            <span class="dmg">[% AuthorisedValues.GetByCode( 'DAMAGED', itemloo.damaged ) | html %]</span>
+                                                            <span class="dmg">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.damaged', authorised_value => itemloo.damaged ) | html %]</span>
                                                         [% END %]
 
                                                         [% IF ( itemloo.withdrawn ) %]
-                                                           <span class="wdn">[% AuthorisedValues.GetByCode( 'WITHDRAWN', itemloo.withdrawn ) | html %]</span>
+                                                           <span class="wdn">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => itemloo.withdrawn ) | html %]</span>
                                                         [% END %]
 
                                                         [% IF ( itemloo.notforloan ) %]
-                                                           <span class="nfl">Not for loan ([% AuthorisedValues.GetByCode( 'NOT_LOAN', itemloo.notforloan ) | html %])</span>
+                                                           <span class="nfl">Not for loan ([% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => itemloo.notforloan ) | html %])</span>
                                                         [% END %]
                                                     </td>
                                                     <td>
-                                                        [% itemloo.pickup_locations | html %]
+                                                    [% IF (itemloo.pickup_locations_count > 0) %]
+                                                        <select name="item_pickup_[% itemloo.itemnumber | html %]" class="pickup_locations" style="width:100%;"
+                                                                data-item-id="[% itemloo.itemnumber | html %]"
+                                                                data-patron-id="[% patron.borrowernumber | html %]"
+                                                                data-pickup-location-source="item">
+                                                        [% IF (itemloo.default_pickup_location) %]
+                                                            <option value="[% itemloo.default_pickup_location.branchcode | html %]" selected="selected">[% itemloo.default_pickup_location.branchname | html %]</option>
+                                                        [% END %]
+                                                        </select>
+                                                    [% END %]
                                                     </td>
                                                 </tr>
                                             [% END # / UNLESS itemloo.hide %]
                                     [% END %]
                                     <th>Priority</th>
                                     <th>Information</th>
+                                    <th>Pickup location</th>
                                 </tr>
                                 [% FOREACH biblioloo IN biblioloop %]
                                     [% IF ( biblioloo.warn ) %]
                                             [% IF ( biblioloo.alreadyres ) %]
                                                 <ul>
                                             [% ELSE %]
-                                                [% IF ( biblioloo.none_avail ) %]
+                                                [% IF ( biblioloo.none_avail || biblioloo.noitems ) %]
                                                     <ul>
                                                 [% END %]
                                             [% END %]
                                                     <strong>already has a hold</strong> on this item
                                                 </li>
                                             [% END %]
-                                            [% IF ( biblioloo.none_avail ) %]
+                                            [% IF ( biblioloo.none_avail || biblioloo.noitems ) %]
                                                 <li> <strong>No items are available</strong> to be placed on hold</li>
                                             [% END %]
 
                                             [% IF ( biblioloo.alreadyres ) %]
                                                 </ul>
                                             [% ELSE %]
-                                                [% IF ( biblioloo.none_avail ) %]
+                                                [% IF ( biblioloo.none_avail || biblioloo.noitems ) %]
                                                     </ul>
                                                 [% END %]
                                             [% END %]
                                         </td>
+                                        <td>
+                                            [% UNLESS ( biblioloo.none_avail || biblioloo.noitems ) %]
+                                                <select name="pickup_[% biblioloo.biblionumber | html %]"
+                                                        class="multi_pickup_select"
+                                                        data-biblio-id="[% biblioloo.biblionumber | html %]"
+                                                        data-patron-id="[% patron.borrowernumber | html %]"
+                                                        data-pickup-locations='[% biblioloo.pickup_locations_codes.json | $raw %]'>
+                                                    <option value=""></option>
+                                                    [% FOREACH pickup_location IN biblioloo.pickup_locations %]
+                                                        <option value="[% pickup_location.branchcode | html %]">[% pickup_location.branchname | html %]</option>
+                                                    [% END %]
+                                                </select>
+                                            [% END %]
+                                        </td>
                                     </tr>
                                 [% END # /FOREACH biblioloo %]
                             </table> <!-- /#requesttitles -->
                         <fieldset class="action">
                             [% IF ( patron AND patron.borrowernumber ) %]
                                 [% IF ( override_required ) %]
-                                    <button type="submit" class="btn btn-default warning"><i class="fa fa-exclamation-triangle "></i> Place hold</button>
+                                    <button type="submit" class="btn btn-default warning"><i class="fa fa-exclamation-triangle "></i> Place holds</button>
                                 [% ELSIF ( none_available ) %]
-                                    <button type="submit" disabled="disabled" class="btn btn-default btn-disabled">Place hold</button>
+                                    <button class="btn btn-default" type="submit">Place holds</button>
                                 [% ELSE %]
                                     [% IF ( multi_hold ) %]
-                                        <button type="submit" class="btn btn-default" id="multi_hold_submit">Place hold</button>
+                                        <button type="submit" class="btn btn-default" id="multi_hold_submit">Place holds</button>
                                     [% ELSE %]
                                         <button type="submit" class="btn btn-default">Place hold</button>
                                     [% END %]
             [% END %]
 
             [% UNLESS ( patron ) %]
+                [% UNLESS borrowers %]
+                    [% SET hold_count = Biblio.HoldsCount( biblio.biblionumber ) | html %]
+                    [% IF hold_count %]
+                        <label for ="always_show_holds">Always show holds</label>
+                        [% IF always_show_holds == 'DONT' %]
+                            <input type="checkbox" name="always_show_holds" id="always_show_holds" value="DO">
+                            [% UNLESS reserveloop %]
+                                <a class="btn btn-default" value="Show holds" id="show_holds_now" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio.biblionumber | uri %]&show_holds_now=1">Show holds ([% hold_count | html %])</a>
+                            [% END %]
+                        [% ELSE %]
+                            <input type="checkbox" name="always_show_holds" value="DO" id="always_show_holds" checked="checked">
+                        [% END %]
+                    [% END %]
+                [% END %]
                 [% IF ( reserveloop ) %]
                     <form id="existing_holds" name="T[% time | html %]" action="modrequest.pl" method="post" style="display:block">
                         [% IF ( multi_hold ) %]
                             <input type = "hidden" name="biblionumbers" value="[% biblionumbers | html %]"/>
                         [% END %]
 
+                        [% IF enqueued %]
+                            <div class="dialog message">
+                                <p>The job has been enqueued! It will be processed as soon as possible.</p>
+                                <p><a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a></p>
+                            </div>
+                        [% END %]
+
                         <h2>Existing holds</h2>
                         <div id="toolbar" class="btn-toolbar">
-                            <input type="submit" name="submit" value="Update hold(s)" />
+                            <input type="submit" name="submit" value="Update hold(s)" /> <button class="cancel_selected_holds" data-bulk="true"></button>
                         <fieldset id="cancellation-reason-fieldset" class="action">
                             [% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %]
                             [% IF hold_cancellation %]
 
                         [% FOREACH biblioloo IN biblioloop %]
                             [% IF ( biblioloo.reserveloop ) %]
-                                [% IF ( multi_hold ) %]
-                                    <h3>
-                                        <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblioloo.biblionumber | uri %]">
-                                            [% biblioloo.title | html %]
-                                        </a>
-                                    </h3>
-                                [% END %]
+                                <div class="hold_title" id="hold_title_[% biblioloo.biblionumber | html %]">
+                                    [% IF ( multi_hold ) %]
+                                        <h3>
+                                            <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblioloo.biblionumber | uri %]">
+                                                [% biblioloo.title | html %]
+                                            </a> <span class="number_box"><span>[% biblioloo.reserveloop.size | html %] [% tn('Hold', 'Holds', biblioloo.reserveloop.size) | $raw %]</span></span>
+                                        </h3>
+                                    [% END %]
 
-                                [% IF Koha.Preference('HoldsSplitQueue') == 'branch' %]
-                                    [% SET branchcodes = [] %]
+                                    [% IF Koha.Preference('HoldsSplitQueue') == 'branch' %]
 
-                                    [% FOREACH h IN biblioloo.reserveloop %]
-                                        [% branchcodes.push( h.branchcode ) %]
-                                    [% END %]
-                                    [% branchcodes = branchcodes.unique %]
+                                        [% SET branchcodes = [] %]
 
-                                    [% FOREACH b IN branchcodes.sort %]
-                                        [% SET holds_by_branch = [] %]
                                         [% FOREACH h IN biblioloo.reserveloop %]
-                                            [% IF h.branchcode == b %]
-                                                [% holds_by_branch.push( h ) %]
-                                            [% END %]
+                                            [% branchcodes.push( h.branchcode ) %]
                                         [% END %]
-                                        <fieldset>
-                                            <legend>[% Branches.GetName( b ) | html %]</legend>
-                                            [% INCLUDE holds_table.inc holds=holds_by_branch %]
-                                        </fieldset>
-                                    [% END # /FOREACh b %]
-                                [% ELSIF Koha.Preference('HoldsSplitQueue') == 'itemtype' %]
-                                    [% SET itemtypes = [] %]
-
-                                    [% FOREACH h IN biblioloo.reserveloop %]
-                                        [% SET hold_itemtype = h.object.item.effective_itemtype || h.itemtype %]
-                                        [% itemtypes.push( hold_itemtype ) %]
-                                    [% END %]
-                                    [% itemtypes = itemtypes.unique %]
+                                        [% branchcodes = branchcodes.unique %]
+                                        [% IF ( branchcodes.empty ) %]
+                                            <div class="note">
+                                                There are no holds on this title.
+                                            </div>
+                                        [% ELSE %]
+
+                                            [% FOREACH b IN branchcodes.sort %]
+                                                [% SET holds_by_branch = [] %]
+                                                [% FOREACH h IN biblioloo.reserveloop %]
+                                                    [% IF h.branchcode == b %]
+                                                        [% holds_by_branch.push( h ) %]
+                                                    [% END %]
+                                                [% END %]
+                                                <div class="holds_by_library">
+                                                    <h4>[% Branches.GetName( b ) | html %]</h4>
+
+                                                    [% INCLUDE holds_table.inc holds=holds_by_branch %]
+                                                </div>
+                                            [% END # /FOREACh b %]
+                                        [% END # /IF ( branchcodes.empty ) %]
+
+                                    [% ELSIF Koha.Preference('HoldsSplitQueue') == 'itemtype' %]
+
+                                        [% SET itemtypes = [] %]
 
-                                    [% FOREACH i IN itemtypes.sort %]
-                                        [% SET holds_by_itemtype = [] %]
                                         [% FOREACH h IN biblioloo.reserveloop %]
                                             [% SET hold_itemtype = h.object.item.effective_itemtype || h.itemtype %]
-                                            [% IF hold_itemtype == i %]
-                                                [% holds_by_itemtype.push( h ) %]
-                                            [% END %]
+                                            [% itemtypes.push( hold_itemtype ) %]
                                         [% END %]
-
-                                        <fieldset>
-                                            [% IF i %]
-                                                <legend>[% ItemTypes.GetDescription( i ) | html %]</legend>
-                                            [% ELSE %]
-                                                <legend>Any item type</legend>
-                                            [% END %]
-                                            [% INCLUDE holds_table.inc holds=holds_by_itemtype %]
-                                        </fieldset>
-                                    [% END # /FOREACH i %]
-                                [% ELSIF Koha.Preference('HoldsSplitQueue') == 'branch_itemtype' %]
-                                    [% SET branchcodes = [] %]
-
-                                    [% FOREACH h IN biblioloo.reserveloop %]
-                                        [% branchcodes.push( h.branchcode ) %]
-                                    [% END %]
-                                    [% branchcodes = branchcodes.unique %]
-
-                                    [% FOREACH b IN branchcodes.sort %]
-                                        <fieldset>
-                                            <legend>[% Branches.GetName( b ) | html %]</legend>
-                                            [% SET holds_by_branch = [] %]
-                                            [% FOREACH h IN biblioloo.reserveloop %]
-                                                [% IF h.branchcode == b %]
-                                                    [% holds_by_branch.push( h ) %]
-                                                [% END %]
-                                            [% END %]
-
-                                            [% SET itemtypes = [] %]
-                                            [% FOREACH h IN holds_by_branch %]
-                                                [% SET hold_itemtype = h.object.item.effective_itemtype || h.itemtype %]
-                                                [% itemtypes.push( hold_itemtype ) %]
-                                            [% END %]
-                                            [% itemtypes = itemtypes.unique %]
+                                        [% itemtypes = itemtypes.unique %]
+                                        [% IF ( itemtypes.empty ) %]
+                                            <div class="note">
+                                                There are no holds on this title.
+                                            </div>
+                                        [% ELSE %]
 
                                             [% FOREACH i IN itemtypes.sort %]
-                                                [% IF i %]
-                                                    <h3>[% ItemTypes.GetDescription( i ) | html %]</h3>
-                                                [% ELSE %]
-                                                    <h3>Any item type</h3>
-                                                [% END %]
-
                                                 [% SET holds_by_itemtype = [] %]
-                                                [% FOREACH h IN holds_by_branch %]
+                                                [% FOREACH h IN biblioloo.reserveloop %]
                                                     [% SET hold_itemtype = h.object.item.effective_itemtype || h.itemtype %]
                                                     [% IF hold_itemtype == i %]
                                                         [% holds_by_itemtype.push( h ) %]
                                                     [% END %]
                                                 [% END %]
-                                                [% INCLUDE holds_table.inc holds=holds_by_itemtype %]
-                                            [% END %]
-                                        </fieldset>
-                                    [% END # /FOREACH b %]
-                                [% ELSE %]
-                                    [% INCLUDE holds_table.inc holds=biblioloo.reserveloop %]
-                                [% END # /IF HoldsSplitQueue %]
 
+                                                <div class="holds_by_itemtype">
+                                                    [% IF i %]
+                                                        <h4>[% ItemTypes.GetDescription( i ) | html %]</h4>
+                                                    [% ELSE %]
+                                                        <h4>Any item type</h4>
+                                                    [% END %]
+                                                    [% INCLUDE holds_table.inc holds=holds_by_itemtype %]
+                                                </div>
+                                            [% END # /FOREACH i %]
+                                        [% END # /IF ( itemtypes.empty ) %]
+
+                                    [% ELSIF Koha.Preference('HoldsSplitQueue') == 'branch_itemtype' %]
+                                        [% SET branchcodes = [] %]
+
+                                        [% FOREACH h IN biblioloo.reserveloop %]
+                                            [% branchcodes.push( h.branchcode ) %]
+                                        [% END %]
+                                        [% branchcodes = branchcodes.unique %]
+                                        [% IF ( branchcodes.empty ) %]
+                                            <div class="note">
+                                                There are no holds on this title.
+                                            </div>
+                                        [% ELSE %]
+
+                                            [% FOREACH b IN branchcodes.sort %]
+                                                <div class="holds_by_library">
+                                                    <h4 class="library_holds">[% Branches.GetName( b ) | html %]</h4>
+                                                    [% SET holds_by_branch = [] %]
+                                                    [% FOREACH h IN biblioloo.reserveloop %]
+                                                        [% IF h.branchcode == b %]
+                                                            [% holds_by_branch.push( h ) %]
+                                                        [% END %]
+                                                    [% END %]
+
+                                                    [% SET itemtypes = [] %]
+                                                    [% FOREACH h IN holds_by_branch %]
+                                                        [% SET hold_itemtype = h.object.item.effective_itemtype || h.itemtype %]
+                                                        [% itemtypes.push( hold_itemtype ) %]
+                                                    [% END %]
+                                                    [% itemtypes = itemtypes.unique %]
+
+                                                    [% FOREACH i IN itemtypes.sort %]
+                                                        <div class="holds_by_itemtype">
+                                                            <h5 class="itemtype_holds">
+                                                                [% IF i %]
+                                                                    [% ItemTypes.GetDescription( i ) | html %]
+                                                                [% ELSE %]
+                                                                    Any item type
+                                                                [% END %]
+                                                            </h5>
+
+                                                            [% SET holds_by_itemtype = [] %]
+                                                            [% FOREACH h IN holds_by_branch %]
+                                                                [% SET hold_itemtype = h.object.item.effective_itemtype || h.itemtype %]
+                                                                [% IF hold_itemtype == i %]
+                                                                    [% holds_by_itemtype.push( h ) %]
+                                                                [% END %]
+                                                            [% END %]
+                                                            [% INCLUDE holds_table.inc holds=holds_by_itemtype %]
+                                                        </div> <!-- /.holds_by_itemtype -->
+                                                    [% END %]
+                                                </div> <!-- /.holds_by_library -->
+                                            [% END # /FOREACH b %]
+                                        [% END # /IF ( branchcodes.empty ) %]
+
+                                    [% ELSE %]
+
+                                        [% IF ( biblioloo.reserveloop.size ) %]
+                                            [% INCLUDE holds_table.inc holds=biblioloo.reserveloop %]
+                                        [% ELSE %]
+                                            <div class="note">
+                                                There are no holds on this title.
+                                            </div>
+                                        [% END %]
+
+                                    [% END # /IF HoldsSplitQueue %]
+                                </div> <!-- /hold_title -->
                             [% END # /IF biblioloo.reserveloop %]
                         [% END # FOREACH biblioloo %]
-                        </fieldset> <!-- /.rows -->
-                    </form> <!-- /name=TTime -->
+                    </form> <!-- /#existing_holds -->
                 [% END # IF reserveloop %]
             [% END # UNLESS patron %]
 
         </main>
 
-        [% IF ( multi_hold ) # No sidebar menu when placing multiple holds %]
+        [% IF ( multi_hold || nobiblio ) # No sidebar menu when placing multiple holds or biblio not found %]
             </div> <!-- /.col-md-10.col-md-offset-1 -->
         [% ELSE %]
             </div> <!-- /.col-sm-10.col-sm-push-2 -->
 
 [% MACRO jsinclude BLOCK %]
     [% INCLUDE 'datatables.inc' %]
-    [% INCLUDE 'calendar.inc' %]
     [% INCLUDE 'columns_settings.inc' %]
     [% Asset.js("lib/hc-sticky.js") | $raw %]
     [% Asset.js("js/circ-patron-search-results.js") | $raw %]
+    [% INCLUDE 'select2.inc' %]
+    [% Asset.js("js/holds.js") | $raw%]
+    [% INCLUDE 'calendar.inc' %]
     <script>
         var Sticky;
         var biblionumber = "[% biblionumber | $raw %]";
         var override_items = {[% FOREACH bibitemloo IN bibitemloop %][% FOREACH itemloo IN bibitemloo.itemloop %][% IF ( itemloo.override ) %]
         [% itemloo.itemnumber | html %]: {
             homebranch: "[% To.json( Branches.GetName( itemloo.homebranch ) ) | $raw %]",
-            holdallowed: [% itemloo.holdallowed | html %]
+            holdallowed: "[% itemloo.holdallowed | html %]"
             },
             [% END %][% END %][% END %]
         };
-        var MSG_NO_ITEMS_AVAILABLE = _("A hold cannot be requested on any of these items.");
         var ERROR_MAP = {
             damaged: _("Item damaged"),
             ageRestricted: _("Age restricted"),
             tooManyReservesToday: _("Daily hold limit reached for patron"),
             tooManyReserves: _("Too many holds"),
             notReservable: _("Not holdable"),
+            noReservesAllowed: _("No reserves allowed"),
             cannotReserveFromOtherBranches: _("Patron is from different library"),
             itemAlreadyOnHold: _("Patron already has hold for this item"),
-            cannotBeTransferred: _("Cannot be transferred to pickup library")
+            cannotBeTransferred: _("Cannot be transferred to pickup library"),
+            pickupNotInHoldGroup: _("Only pickup locations within the same hold group are allowed")
         }
-        columns_settings_borrowers_table = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %]
+
+        var MSG_CANCEL_SELECTED = _("Cancel selected (%s)");
+        columns_settings_borrowers_table = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %];
+        $.fn.select2.defaults.set("width", "100%" );
+        $.fn.select2.defaults.set("dropdownAutoWidth", true );
 
         $(document).ready(function() {
             $('#cancellation-reason-fieldset').hide();
                 });
             [% END %]
 
-            [% IF AutoResumeSuspendedHolds %]
-                $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1);
-            [% END %]
-
-            $(".datepickerto").datepicker("option", "altField", ".datepickerto_hidden");
-            $(".datepickerto").datepicker("option", "altFormat", "yy-mm-dd");
-
-            $(".datepickerfrom").datepicker("option", "altField", ".datepickerfrom_hidden");
-            $(".datepickerfrom").datepicker("option", "altFormat", "yy-mm-dd");
-
             var my_table = $("#requestspecific").dataTable($.extend(true, {}, dataTablesDefaults, {
                 'bPaginate': false,
                 "sDom": '<"top pager"ilf>t',
-                "aoColumnDefs": [
-                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
-                ]
             }));
 
             //Override fieldset styling for dataTables search box
                     data.patron_id = $('input[name="borrowernumber"]').val();
                 if($('textarea[name="notes"]').length)
                     data.notes = $('textarea[name="notes"]').val()||null;
-                if($('.datepickerto_hidden').length)
-                    data.expiration_date = $('.datepickerto_hidden').val()||null;
-                if($('.datepickerfrom_hidden').length)
-                    data.hold_date = $('.datepickerfrom_hidden').val()||null;
                 if($('input[name="itemtype"]').length) {
                     data.item_type = $('input[name="itemtype"]').val()||null;
                 }
 
             [% UNLESS ( multi_hold ) %]
                 $("#hold-request-form").on("submit", function(){
-                    return check();
+                    return check($(this));
                 });
             [% ELSE %]
                 $("#hold-request-form").on("submit", function(){
                 });
             [% END %]
 
+            $(".pickup_location_dropdown").each( function () {
+                $(this).pickup_locations_dropdown();
+            });
+
+            $("#pickup_multi").select2({
+                width: '30%',
+                allowClear: true
+            });
+
+            $('.multi_pickup_select').select2({
+                width: '100%',
+                allowClear: true
+            });
+
+            $("#pickup_multi").on("change", function() {
+                var selection = $(this).val();
+                if ( selection != '' ) {
+                    $(".multi_pickup_select").each(function() {
+                        var valid_pickup_locations = $(this).data('pickup-locations');
+                        if ( valid_pickup_locations.includes(selection) ) {
+                            $(this).val(selection);
+                            $(this).trigger("change");
+                        }
+                    });
+                }
+            });
+
+            $("#pickup").each( function () {
+                $(this).pickup_locations_dropdown();
+            });
+
+            $(".pickup_locations").each(function () {
+                $(this).pickup_locations_dropdown();
+            });
         });
 
-        function check() {
+        function check( table ) {
+
             var msg = "";
-            var count_reserv = 0;
 
-            // check if we have checkitem form
-            if (document.form.checkitem){
-                for (i=0;i<document.form.checkitem.length;i++){
-                    if (document.form.checkitem[i].checked == true) {
-                        count_reserv++ ;
+            if ( $("#requestany").attr("checked") !== "checked" ) {
+                // requestany not selected, go through the item-specific cases
+                if ( $('input[type="radio"]:checked').length > 0 ) {
+                    // got item-specific hold requests in the form!
+                    // verify they have a pickup location selected
+
+                    if (table.find('input[type="radio"]:checked')
+                                .closest('tr')
+                                .find(".pickup_locations").val() === null) {
+
+                        msg = _("- Please select a pickup location for the item" + "\n")
                     }
                 }
-                // for only one item, check the checkitem without consider the loop checkitem
-                if (i==0){
-                    if (document.form.checkitem.checked == true) {
-                        count_reserv++;
-                    }
+                else {
+                    msg = (_("- Please select an item to place a hold") + "\n");
                 }
             }
 
-            if (document.form.requestany.checked == true){
-                count_reserv++ ;
-            }
-
-            if (count_reserv == "0"){
-                msg += (_("- Please select an item to place a hold") + "\n");
-            }
-
             if (msg == "") {
                 $('#hold-request-form').preventDoubleFormSubmit();
                 return(true);
         }
 
         function checkMultiHold() {
-            var spans = $(".multi_hold_item_checkbox:checked");
-            if ($(spans).size() == 0) {
-                alert(MSG_NO_ITEMS_AVAILABLE);
-                return false;
-            }
 
             var biblionumbers = "";
-            $(spans).each(function() {
-                var bibnum = $(this).attr("title");
-                biblionumbers += bibnum + "/";
-            });
+            var selected_bibs = $(".multi_hold_item_checkbox:checked");
+            if ( selected_bibs.length > 0 ) {
+                // there are biblios selected in the form!
+                // verify they have a pickup location selected
+
+                var pickup_not_set = 0;
+                selected_bibs.each(function() {
+                    if ( $(this).closest('tr').find(".multi_pickup_select").val() === "" ) {
+                        pickup_not_set++;
+                    }
+                    else {
+                        var bibnum = $(this).attr("title");
+                        biblionumbers += bibnum + "/";
+                    }
+                });
+                if ( pickup_not_set > 0 ) {
+                    alert( _("Please make sure all selected titles have a pickup location set" + "\n") );
+                    return false;
+                }
+            }
+            else {
+                alert( _("Please select at least one title" + "\n") );
+                return false;
+            }
 
             var badSpans = $(".not_holdable");
             var badBibs = "";
         }
 
          $(document).ready(function() {
+            $("#always_show_holds").change(function(){
+                if( $(this).prop('checked') ){
+                    document.cookie = 'always_show_holds=DO';
+                } else {
+                    document.cookie = 'always_show_holds=DONT';
+                }
+            });
             $("input.needsoverride").click(function() { // This must be before the radio button/checkbox switch logic
                 var itemnumber = this.value;
                 var msg = '';
 
                 switch (override_items[itemnumber].holdallowed) {
-                    case 0: msg = _("This item normally cannot be put on hold."); break;
-                    case 1: msg = _("This item normally cannot be put on hold except for patrons from %s.").format(override_items[itemnumber].homebranch); break;
+                    case "not_allowed": msg = _("This item normally cannot be put on hold."); break;
+                    case "from_home_library": msg = _("This item normally cannot be put on hold except for patrons from %s.").format(override_items[itemnumber].homebranch); break;
                 }
 
                 msg += "\n\n" + _("Place hold on this item?");
                 return false;
             });
             $("#cancelModalConfirmBtn").on("click",function(e) {
-                let borrowernumber = cancel_link.data('borrowernumber');
-                let biblionumber = cancel_link.data('biblionumber');
-                let reserve_id = cancel_link.data('id');
+                let link;
+                if(cancel_link.data('bulk')) {
+                    [% IF biblionumbers %]
+                        link = `request.pl?biblionumbers=[% biblionumbers | url %]&amp;action=cancelBulk&amp;ids=${$('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(',')}`;
+                    [% ELSE %]
+                        link = `request.pl?biblionumber=[% biblionumber | url %]&amp;action=cancelBulk&amp;ids=${$('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(',')}`;
+                    [% END %]
+                } else {
+                    let borrowernumber = cancel_link.data('borrowernumber');
+                    let biblionumber = cancel_link.data('biblionumber');
+                    let reserve_id = cancel_link.data('id');
+                    link = `request.pl?action=cancel&amp;borrowernumber=${ borrowernumber }&amp;biblionumber=${ biblionumber }&amp;reserve_id=${ reserve_id }`;
+                }
                 let reason = $("#modal-cancellation-reason").val();
-                let link = `request.pl?action=cancel&amp;borrowernumber=${ borrowernumber }&amp;biblionumber=${ biblionumber }&amp;reserve_id=${ reserve_id }`;
                 if ( reason ) {
                     link += "&amp;cancellation-reason=" + reason
                 }
                 return false;
             });
 
-            [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems ) %]
+            [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems || nobiblio ) %]
                 [% IF ( PatronAutoComplete ) %]
                 $( "#patron" ).autocomplete({
                     source: "/cgi-bin/koha/circ/ysearch.pl",
                 .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
                     return $( "<li></li>" )
                     .data( "ui-autocomplete-item", item )
-                    .append( "<a>" + item.surname + ", " + item.firstname +
-                             " (" + item.cardnumber + ") <small>" + item.address +
-                             " " + item.city + " " + item.zipcode + " " +
-                             item.country + "</small></a>" )
+                    .append(
+                        "<a>"
+                            + ( item.surname ? item.surname.escapeHtml() : "" )
+                            + ", "
+                            + ( item.firstname ? item.firstname.escapeHtml() : "" )
+                            + " (" + ( item.cardnumber ? item.cardnumber.escapeHtml() : "" ) + ")"
+                            + " "
+                            + "<small>"
+                                + ( item.address ? item.address.escapeHtml() : "" )
+                                + " "
+                                + ( item.city ? item.city.escapeHtml() : "" )
+                                + " "
+                                + ( item.zipcode ? item.zipcode.escapeHtml() : "" )
+                                + " "
+                                + ( item.country ? item.country.escapeHtml() : "" )
+                            + "</small>"
+                        + "</a>" )
                     .appendTo( ul );
                 };
                 [% END %]
                 stickTo: "#existing_holds",
                 stickyClass: "floating"
             });
+
+            if(!localStorage.selectedHolds  || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) {
+                localStorage.selectedHolds = [];
+            }
+
+            $('.holds_table .select_hold').each(function() {
+                if(localStorage.selectedHolds.includes($(this).data('id'))) {
+                    $(this).prop('checked', true);
+                }
+            });
+
+            $('.holds_table .select_hold_all').each(function() {
+                var table = $(this).parents('.holds_table');
+                var count = $('.select_hold:not(:checked)', table).length;
+                $('.select_hold_all', table).prop('checked', !count);
+            });
+
+            $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
+
+            $('.holds_table .select_hold_all').click(function() {
+                var table = $(this).parents('.holds_table');
+                var count = $('.select_hold:checked', table).length;
+                $('.select_hold', table).prop('checked', !count);
+                $(this).prop('checked', !count);
+                $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
+                localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
+            });
+
+            $('.holds_table .select_hold').click(function() {
+                var table = $(this).parents('.holds_table');
+                var count = $('.select_hold:not(:checked)', table).length;
+                $('.select_hold_all', table).prop('checked', !count);
+                $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length));
+                localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'));
+            });
+
+            $('.cancel_selected_holds').click(function(e) {
+                e.preventDefault();
+                if($('.holds_table .select_hold:checked').length) {
+                    cancel_link = $(this);
+                    delete localStorage.selectedHolds;
+                    $('#cancelModal').modal();
+                }
+                return false;
+            });
+
         });
     </script>
 [% END %]