From 8cf890a519236156202d0f4505aee63f3934a70b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 10 Aug 2011 13:55:40 -0400 Subject: [PATCH] Tpac: Support for adding/editing pending addresses Signed-off-by: Bill Erickson --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 54 ++++++- .../templates/default/opac/myopac/prefs.tt2 | 150 ++++++++++++------ 2 files changed, 151 insertions(+), 53 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index b329daa748..344696a3a0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -82,7 +82,59 @@ sub local_avail_concern { # user : au object, fleshed sub load_myopac_prefs { my $self = shift; - return $self->prepare_extended_user_info || Apache2::Const::OK; + my $cgi = $self->cgi; + my $e = $self->editor; + my $pending_addr = $cgi->param('pending_addr'); + my $replace_addr = $cgi->param('replace_addr'); + my $delete_pending = $cgi->param('delete_pending'); + + $self->prepare_extended_user_info; + my $user = $self->ctx->{user}; + + return Apache2::Const::OK unless + $pending_addr or $replace_addr or $delete_pending; + + my @form_fields = qw/address_type street1 street2 city county state country post_code/; + + my $paddr; + if( $pending_addr ) { # update an existing pending address + + ($paddr) = grep { $_->id == $pending_addr } @{$user->addresses}; + return Apache2::Const::HTTP_BAD_REQUEST unless $paddr; + $paddr->$_( $cgi->param($_) ) for @form_fields; + + } elsif( $replace_addr ) { # create a new pending address for 'replace_addr' + + $paddr = Fieldmapper::actor::user_address->new; + $paddr->isnew(1); + $paddr->usr($user->id); + $paddr->pending('t'); + $paddr->replaces($replace_addr); + $paddr->$_( $cgi->param($_) ) for @form_fields; + + } elsif( $delete_pending ) { + $paddr = $e->retrieve_actor_user_address($delete_pending); + return Apache2::Const::HTTP_BAD_REQUEST unless + $paddr and $paddr->usr == $user->id and $U->is_true($paddr->pending); + $paddr->isdeleted(1); + } + + my $resp = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.address.pending.cud', + $e->authtoken, $paddr); + + if( $U->event_code($resp) ) { + $logger->error("Error updating pending address: $resp"); + return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; + } + + # in light of these changes, re-fetch latest data + $e->xact_begin; + $self->prepare_extended_user_info; + $e->rollback; + + return Apache2::Const::OK; } sub load_myopac_prefs_notify { diff --git a/Open-ILS/src/templates/default/opac/myopac/prefs.tt2 b/Open-ILS/src/templates/default/opac/myopac/prefs.tt2 index 17783b3777..2150fb1398 100644 --- a/Open-ILS/src/templates/default/opac/myopac/prefs.tt2 +++ b/Open-ILS/src/templates/default/opac/myopac/prefs.tt2 @@ -241,66 +241,112 @@ [% l("Addresses") %] - + [% l("Pending Addresses") %] - - [% FOR addr IN ctx.user.addresses %] - + + [% + # cycle through the non-pending address. For each non-pending addr + # that has a corresponding pending addr, render the pending addr + # along the right inside it's own edit form + pending = {}; + regular = []; + edit_addr_id = CGI.param('edit_address'); + FOR addr IN ctx.user.addresses; + IF addr.pending == 't'; + replaces = addr.replaces; + pending.$replaces = addr; + ELSE; + regular.push(addr); + END; + END; + FOR addr IN regular; + cur_id = addr.id; + pending_addr = pending.$cur_id; + %] + - - - - - - - - - - [% IF addr.street2 %] - - - [% END %] - - - - - - - - - - - - - - - - - - - - - - - - - + +
[% l("Address Type") %][% - IF addr.pending == "t"; - "" _ l("*** PENDING ***") _ " "; - END; - addr.address_type | lower | ucfirst | html ; - %]
[% l("Street") %][% addr.street1 | html %]
[% l("Street") %][% addr.street2 | html %]
[% l("City") %][% addr.city | html %]
[% l("County") %][% addr.county| html %]
[% l("State") %][% addr.state | html %]
[% l("Country") %][% addr.country | html %]
[% l("Zip") %][% addr.post_code | html %]
+ + + + + + + + + [% IF ctx.get_org_setting(ctx.user.home_ou.id, 'opac.allow_pending_address') + AND !pending_addr AND edit_addr_id != cur_id %] - + [% END %]
[% l("Address Type") %][% addr.address_type | html %]
[% l("Street") %][% addr.street1 | html %]
[% l("Street") %][% addr.street2 | html %]
[% l("City") %][% addr.city | html %]
[% l("County") %][% addr.county| html %]
[% l("State") %][% addr.state | html %]
[% l("Country") %][% addr.country | html %]
[% l("Zip") %][% addr.post_code | html %]
- Edit Address + + [% l('Edit Address') %]
+ + + [% IF pending_addr OR edit_addr_id == cur_id; + update_addr = pending_addr || addr %] + +
+ [% IF pending_addr %] + + [% ELSE %] + + [% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
[% l("Address Type") %]
[% l("Street") %]
[% l("Street") %]
[% l("City") %]
[% l("County") %]
[% l("State") %] +
[% l("Country") %]
[% l("Zip") %]
+ [% IF pending_addr; + url = mkurl('', {delete_pending => pending_addr.id}, 1); + ELSE; + url = mkurl('', {}, 1); + END %] + [% l('Discard Pending Address') %] +
[% l('Address changes will be verified by staff') %]
+
+ + [% END %] [% END %] -- 2.43.2