@@ -, +, @@
branches
- It makes request.pl stop passing a pickup location to
CanItemBeReserved
- It makes the page use the API to render a dropdown for each item, with
their valid pickup locations
- Items with no valid pickup locations have a nice message about why
they are disabled for selection
location
item
---
.../prog/en/modules/reserve/request.tt | 84 +++++++++++++------
reserve/placerequest.pl | 5 +-
reserve/request.pl | 19 ++---
3 files changed, 70 insertions(+), 38 deletions(-)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
@@ -624,6 +624,8 @@
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 == 'no_valid_pickup_location' %]
+ No valid pickup location
[% ELSE %]
[% itemloo.not_holdable | html %]
[% END %]
@@ -721,10 +723,10 @@
[% END %]
- [% IF itemloo.any_pickup_location %]
- Any library
- [% ELSE %]
- [% itemloo.pickup_locations | html %]
+ [% IF (itemloo.pickup_locations_count > 0) %]
+
[% END %]
@@ -1187,7 +1189,7 @@
[% UNLESS ( multi_hold ) %]
$("#hold-request-form").on("submit", function(){
- return check();
+ return check($(this));
});
[% ELSE %]
$("#hold-request-form").on("submit", function(){
@@ -1288,35 +1290,67 @@
templateResult: display_pickup_location
});
});
+ $(".pickup_locations").each( function () {
+ var this_dropdown = $(this);
+ var patron_id = $(this).data('patron-id');
+ var item_id = $(this).data('item-id');
+
+ this_dropdown.select2({
+ allowClear: true,
+ ajax: {
+ url: '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations',
+ delay: 300, // wait 300 milliseconds before triggering the request
+ dataType: 'json',
+ data: function (params) {
+ var search_term = (params.term === undefined) ? '' : params.term;
+ var query = {
+ "q": JSON.stringify({"name":{"-like":search_term+'%'}}),
+ "_order_by": "name",
+ "patron_id": patron_id
+ };
+ return query;
+ },
+ processResults: function (data) {
+ var results = [];
+ data.forEach( function ( pickup_location ) {
+ results.push(
+ {
+ "id": pickup_location.library_id.escapeHtml(),
+ "text": pickup_location.name.escapeHtml(),
+ "needs_override": pickup_location.needs_override
+ }
+ );
+ });
+ return { "results": results };
+ }
+ },
+ templateResult: display_pickup_location
+ });
+ });
});
- 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 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);
--- a/reserve/placerequest.pl
+++ a/reserve/placerequest.pl
@@ -45,6 +45,7 @@ my $biblionumber = $input->param('biblionumber');
my $borrowernumber = $input->param('borrowernumber');
my $notes = $input->param('notes');
my $branch = $input->param('pickup');
+my $item_pickup = $input->param('item_pickup');
my $startdate = $input->param('reserve_date') || '';
my @rank = $input->multi_param('rank-request');
my $type = $input->param('type');
@@ -99,12 +100,12 @@ if ( $type eq 'str8' && $borrower ) {
$biblionumber = $item->biblionumber;
}
- my $can_item_be_reserved = CanItemBeReserved($borrower->{'borrowernumber'}, $item->itemnumber, $branch)->{status};
+ my $can_item_be_reserved = CanItemBeReserved($borrower->{'borrowernumber'}, $item->itemnumber, $item_pickup)->{status};
if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
AddReserve(
{
- branchcode => $branch,
+ branchcode => $item_pickup,
borrowernumber => $borrower->{'borrowernumber'},
biblionumber => $biblionumber,
priority => $rank[0],
--- a/reserve/request.pl
+++ a/reserve/request.pl
@@ -563,8 +563,7 @@ foreach my $biblionumber (@biblionumbers) {
$item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
- my $reserves_control_branch = $pickup || C4::Reserves::GetReservesControlBranch( $item, $patron_unblessed );
- my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber, $reserves_control_branch )->{status};
+ my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status};
$item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
$item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
@@ -578,17 +577,15 @@ foreach my $biblionumber (@biblionumbers) {
&& IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
)
{
- $item->{available} = 1;
- $num_available++;
-
- if ( $branchitemrule->{'hold_fulfillment_policy'} eq 'any' )
- {
- $item->{any_pickup_location} = 1;
+ # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
+ $item->{pickup_locations_count} = $item_object->pickup_locations({ patron => $patron })->count;
+ if ( $item->{pickup_locations_count} > 0 ) {
+ $num_available++;
+ $item->{available} = 1;
}
else {
- my @pickup_locations = $item_object->pickup_locations({ patron => $patron });
-
- $item->{pickup_locations} = join( ', ', map { $_->branchname } @pickup_locations );
+ $item->{available} = 0;
+ $item->{not_holdable} = "no_valid_pickup_location";
}
push( @available_itemtypes, $item->{itype} );
--