return;
}
+# Given an event returned by a failed attempt to create a hold, do we have
+# permission to override? XXX Should the permission check be scoped to a
+# given org_unit context?
+sub test_could_override {
+ my ($self) = @_;
+ my $event = $self->ctx->{"hold_failed_event"};
+
+ return 0 unless $event;
+ return 1 if $self->editor->allowed($event . ".override");
+ return 1 if $event->{"fail_part"} and
+ $self->editor->allowed($event->{"fail_part"} . ".override");
+ return 0;
+}
+
+# Find out whether we care that local copies are available
+sub local_avail_concern {
+ my ($self, $allowed, $request_lib) = @_;
+
+ my ($block, $alert);
+ if ($allowed->{"success"} and $allowed->{"local_avail"}) {
+ $block = $self->ctx->{get_org_setting}->
+ ($request_lib, "circ.holds.hold_has_copy_at.block");
+ $alert = (
+ $self->ctx->{get_org_setting}->
+ ($request_lib, "circ.holds.hold_has_copy_at.alert")
+ and not $self->cgi->param("override")
+ );
+ }
+ return ($block, $alert);
+}
+
# context additions:
# user : au object, fleshed
sub load_myopac_prefs {
sub load_place_hold {
my $self = shift;
my $ctx = $self->ctx;
+ my $gos = $ctx->{get_org_setting};
my $e = $self->editor;
my $cgi = $self->cgi;
$self->ctx->{page} = 'place_hold';
$ctx->{hold_target} = $cgi->param('hold_target');
$ctx->{hold_type} = $cgi->param('hold_type');
- $ctx->{default_pickup_lib} = $e->requestor->home_ou; # XXX staff
+
+ # Although in the context of staff placing holds for other users, this
+ # does not yield the appropriate pickup lib, that situation is addressed
+ # in the client with javascript when possible.
+ $ctx->{default_pickup_lib} = $e->requestor->home_ou;
+
+ my $request_lib = $e->requestor->ws_ou || $e->requestor->home_ou;
# XXX check for failure of the retrieve_* methods called below, and
# possibly replace all the if,elsif with a dispatch table (meh, elegance)
$ctx->{hold_failed} = 1;
$ctx->{hold_failed_event} = $usr;
}
+ # XXX Does $actor need to be explicity disconnected/destroyed?
}
my $args = {
$e->authtoken, $args
);
- if($allowed->{success} == 1) {
+ $logger->info('hold permit result ' . OpenSRF::Utils::JSON->perl2JSON($allowed));
+
+ my ($local_block, $local_alert) =
+ $self->local_avail_concern($allowed, $request_lib);
+
+ if ($local_block) {
+ $ctx->{hold_failed} = 1;
+ $ctx->{hold_local_block} = 1;
+ } elsif ($local_alert) {
+ $ctx->{hold_failed} = 1;
+ $ctx->{hold_local_alert} = 1;
+ } elsif ($allowed->{success}) {
my $hold = Fieldmapper::action::hold_request->new;
$hold->pickup_lib($pickup_lib);
$hold->hold_type($ctx->{hold_type});
# frozen, expired, etc..
+ my $method = "open-ils.circ.holds.create";
+ $method .= ".override" if $cgi->param("override");
+
my $stat = $U->simplereq(
- 'open-ils.circ',
- 'open-ils.circ.holds.create',
- $e->authtoken, $hold
+ "open-ils.circ", $method, $e->authtoken, $hold
);
- if($stat and $stat > 0) {
+ # The following did not cover all the possible return values of
+ # open-ils.circ.holds.create
+ #if($stat and $stat > 0) {
+ if ($stat and (not ref $stat) and $stat > 0) {
# if successful, return the user to the requesting page
- $self->apache->log->info("Redirecting back to " . $cgi->param('redirect_to'));
+ $self->apache->log->info(
+ "Redirecting back to " . $cgi->param('redirect_to')
+ );
return $self->generic_redirect;
} else {
$ctx->{hold_failed} = 1;
+
+ # Give the original CGI params back to the user in case they
+ # want to try to override something.
+ $ctx->{orig_params} = $cgi->Vars;
+ delete $ctx->{orig_params}{submit};
+
+ if (ref $stat eq 'ARRAY') {
+ $ctx->{hold_failed_event} = shift @$stat;
+ } elsif (defined $U->event_code($stat)) {
+ $ctx->{hold_failed_event} = $stat;
+ } else {
+ $self->apache->log->info(
+ "attempt to create hold returned $stat"
+ );
+ }
+
+ $ctx->{could_override} = $self->test_could_override;
}
} else { # hold *check* failed
$ctx->{hold_failed} = 1; # XXX process the events, etc
}
# hold permit failed
- $logger->info('hold permit result ' . OpenSRF::Utils::JSON->perl2JSON($allowed));
}
return Apache2::Const::OK;
<div><big><strong>[% l("Hold was successfully placed"); %]</strong></big></div>
[% ELSIF ctx.hold_failed %]
<div><big><strong>[% l("Hold was not successfully placed"); %]</strong></big></div>
- [% IF ctx.hold_failed_event %]
+ [% IF ctx.hold_failed_event || ctx.hold_local_alert %]
<div>
<strong>[% l('Problem:') %]</strong>
<span title="[% ctx.hold_failed_event.textcode %]">
<em>[% ctx.hold_failed_event.desc ||
ctx.hold_failed_event.payload.fail_part ||
- ctx.hold_failed_event.textcode %]</em>
+ ctx.hold_failed_event.textcode ||
+ (ctx.hold_local_alert ?
+ l("There is already a copy available at your local library") :
+ l("Unknown problem")) %]
</span>
+ [% IF ctx.could_override %]
+ <p>
+ <big>[% l("You have permission to place this hold anyway.") %]</big>
+ <br />
+ [% l("Click submit below to override the system's objection and place your hold.") %]
+ </p>
+ <form method="POST">
+ <input type="hidden" type="name" name="override" value="1" />
+ [% FOR k IN ctx.orig_params.keys %]
+ <input type="hidden" name="[% k %]" value="[% ctx.orig_params.$k | html %]" />
+ [% END %]
+ <input type="image" name="submit" value="submit" title="[% l('Submit') %]"
+ alt="[% l('Submit') %]" src="[% ctx.media_prefix %]/images/btnSubmit.png" />
+ </form>
+ [% END %]
</div>
[% END;
+ ELSIF ctx.hold_local_block;
+ l("There is already a copy available at your local library");
ELSE %]
<form method="POST">
<br/>