# 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 {
<thead>
<tr>
<td><strong>[% l("Addresses") %]</strong></td>
-
+ <td><strong>[% l("Pending Addresses") %]</strong></td>
</tr>
</thead>
- <tbody id='myopac_addr_tbody'>
- [% FOR addr IN ctx.user.addresses %]
- <tr class='[% addr.pending == "t" ? "pending-addr" : "light_border" %]'>
+ <tbody>
+ [%
+ # 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;
+ %]
+ <tr>
<td>
- <table>
- <tr>
- <td>[% l("Address Type") %]</td>
- <td name='myopac_addr_type'>[%
- IF addr.pending == "t";
- "<strong>" _ l("*** PENDING ***") _ "</strong> ";
- END;
- addr.address_type | lower | ucfirst | html ;
- %]</td>
- </tr>
- <tr>
- <td>[% l("Street") %]</td>
- <td name='myopac_addr_street'>[% addr.street1 | html %]</td>
- </tr>
- [% IF addr.street2 %]<tr>
- <td>[% l("Street") %]</td>
- <td name='myopac_addr_street2'>[% addr.street2 | html %]</td>
- </tr>[% END %]
-
- <tr>
- <td>[% l("City") %]</td>
- <td name='myopac_addr_city'>[% addr.city | html %]</td>
- </tr>
-
- <tr>
- <td>[% l("County") %]</td>
- <td name='myopac_addr_county'>[% addr.county| html %]</td>
- </tr>
-
- <tr>
- <td>[% l("State") %]</td>
- <td name='myopac_addr_state'>[% addr.state | html %]</td>
- </tr>
-
- <tr>
- <td>[% l("Country") %]</td>
- <td name='myopac_addr_country'>[% addr.country | html %]</td>
- </tr>
-
- <tr>
- <td>[% l("Zip") %]</td>
- <td name='myopac_addr_zip'>[% addr.post_code | html %]</td>
- </tr>
+ <!-- read-only address display -->
+ <table class='light_border'>
+ <tr><td>[% l("Address Type") %]</td><td>[% addr.address_type | html %]</td></tr>
+ <tr><td>[% l("Street") %]</td><td>[% addr.street1 | html %]</td></tr>
+ <tr><td>[% l("Street") %]</td><td>[% addr.street2 | html %]</td></tr>
+ <tr><td>[% l("City") %]</td><td>[% addr.city | html %]</td></tr>
+ <tr><td>[% l("County") %]</td><td>[% addr.county| html %]</td></tr>
+ <tr><td>[% l("State") %]</td><td>[% addr.state | html %]</td></tr>
+ <tr><td>[% l("Country") %]</td><td>[% addr.country | html %]</td></tr>
+ <tr><td>[% l("Zip") %]</td><td>[% addr.post_code | html %]</td></tr>
+ [% IF ctx.get_org_setting(ctx.user.home_ou.id, 'opac.allow_pending_address')
+ AND !pending_addr AND edit_addr_id != cur_id %]
<tr>
- <td name='myopac_addr_edit_td'
- colspan='2' class='hide_me'>
- <a class='classic_link'
- name='myopac_addr_edit_link'
- href='#'>Edit Address</a>
+ <td colspan='2'>
+ <a href='?edit_address=[% addr.id %]'>[% l('Edit Address') %]</a>
</td>
</tr>
+ [% END %]
</table>
</td>
+
+ <!-- pending address form -->
+ [% IF pending_addr OR edit_addr_id == cur_id;
+ update_addr = pending_addr || addr %]
+ <td>
+ <form method='POST'>
+ [% IF pending_addr %]
+ <input type='hidden' name='pending_addr' value='[% pending_addr.id %]'/>
+ [% ELSE %]
+ <input type='hidden' name='replace_addr' value='[% edit_addr_id | html %]'/>
+ [% END %]
+ <table class='pending-addr'>
+ <tr>
+ <td>[% l("Address Type") %]</td>
+ <td><input name='address_type' value='[% update_addr.address_type | html %]'/></td>
+ </tr>
+ <tr>
+ <td>[% l("Street") %]</td>
+ <td><input name='street1' value='[% update_addr.street1 | html %]'/></td>
+ </tr>
+ <tr>
+ <td>[% l("Street") %]</td>
+ <td><input name='street2' value='[% update_addr.street2 | html %]'/></td>
+ </tr>
+ <tr>
+ <td>[% l("City") %]</td>
+ <td><input name='city' value='[% update_addr.city | html %]'/></td>
+ </tr>
+ <tr>
+ <td>[% l("County") %]</td>
+ <td><input name='county' value='[% update_addr.county| html %]'/></td>
+ </tr>
+ <tr>
+ <td>[% l("State") %]</td>
+ <td><input name='state' value='[% update_addr.state | html %]'</td>
+ </tr>
+ <tr>
+ <td>[% l("Country") %]</td>
+ <td><input name='country' value='[% update_addr.country | html %]'/></td>
+ </tr>
+
+ <tr>
+ <td>[% l("Zip") %]</td>
+ <td><input name='post_code' value='[% update_addr.post_code | html %]'/></td>
+ </tr>
+ <tr>
+ <td><input type='submit' value="[% l('Save Changes') %]"/></td>
+ <td>
+ [% IF pending_addr;
+ url = mkurl('', {delete_pending => pending_addr.id}, 1);
+ ELSE;
+ url = mkurl('', {}, 1);
+ END %]
+ <a href="[% url %]">[% l('Discard Pending Address') %]</a>
+ </td>
+ </tr>
+ <tr><td colspan='2'><i>[% l('Address changes will be verified by staff') %]</i></td></tr>
+ </table>
+ </form>
+ </td>
+ [% END %] <!-- if pending_addr -->
</tr>
[% END %]
</tbody>