From 92a9cfc4c9a8fa0d216ab76a4a70506cd37a3e62 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 22 Dec 2022 11:24:08 -0600 Subject: [PATCH] LP1797025 Allow patrons to add/edit their preferred name Added a feature to allow patrons to update/edit their preferred name. The form is located in the Account Preferences tab in the OPAC. 2 new files were added for the bootstrap & non-bootstrap versions. These 2 files contain the html form. update_preferred_name.tt2 Signed-off-by: Scott --- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 25 ++++++++++++++ .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 39 ++++++++++++++++++++++ .../src/templates-bootstrap/opac/css/style.css.tt2 | 11 +++++- .../src/templates-bootstrap/opac/myopac/prefs.tt2 | 17 ++++++++++ .../opac/myopac/update_preferred_name.tt2 | 36 ++++++++++++++++++++ Open-ILS/src/templates/opac/css/style.css.tt2 | 10 +++++- Open-ILS/src/templates/opac/myopac/prefs.tt2 | 17 ++++++++++ .../opac/myopac/update_preferred_name.tt2 | 39 ++++++++++++++++++++++ 8 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/templates-bootstrap/opac/myopac/update_preferred_name.tt2 create mode 100644 Open-ILS/src/templates/opac/myopac/update_preferred_name.tt2 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 56df630e79..40a281bba0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -1695,6 +1695,20 @@ __PACKAGE__->register_method( } ); +__PACKAGE__->register_method( + method => "update_passwd", + api_name => "open-ils.actor.user.preferred_name.update", + signature => { + desc => "Update the operator's preferred name", + params => [ + { desc => 'Authentication token', type => 'string' }, + { desc => 'User', type => 'hash' }, + { desc => 'Current password', type => 'string' } + ], + return => {desc => '1 on success, Event on error or incorrect current password'} + } +); + sub update_passwd { my( $self, $conn, $auth, $new_val, $orig_pw ) = @_; my $e = new_editor(xact=>1, authtoken=>$auth); @@ -1741,6 +1755,17 @@ sub update_passwd { } elsif( $api =~ /locale/o ) { $db_user->locale($new_val); $at_event++; + } elsif( $api =~ /preferred_name/o ) { + if(ref($new_val) eq 'HASH'){ + foreach(qw/ pref_prefix pref_first_given_name pref_second_given_name pref_family_name pref_suffix/){ + $db_user->$_($new_val->{$_}); + # Set the value to NULL when no data is submitted. + eval '$db_user->clear_' . $_ . '();' if($new_val->{$_} eq '' ); + } + $at_event++; + }else { + return new OpenILS::Event('BAD_PARAMS'); + } } } 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 78bba4acac..d406fb5e38 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -2854,6 +2854,45 @@ sub load_myopac_update_password { return $self->generic_redirect($url); } +sub load_myopac_update_preferred_name { + my $self = shift; + my $e = $self->editor; + my $ctx = $self->ctx; + + $self->prepare_extended_user_info; + + return Apache2::Const::OK + unless $self->cgi->request_method eq 'POST'; + + my $current_pw = $self->cgi->param('current_pw') || ''; + + my %opac_vals = (); + + foreach(qw/ pref_prefix pref_first_given_name pref_second_given_name pref_family_name pref_suffix/ ){ + $opac_vals{$_} = $self->cgi->param($_) if($self->cgi->param($_) && $self->cgi->param($_) ne ''); + } + + my $evt = $U->simplereq('open-ils.actor', 'open-ils.actor.user.preferred_name.update', + $e->authtoken, \%opac_vals, $current_pw); + + if($U->event_equals($evt, 'INCORRECT_PASSWORD')) { + $ctx->{password_incorrect} = 1; + return Apache2::Const::OK; + } + + if($U->event_equals($evt, 'BAD_PARAM')) { + $ctx->{bad_param} = 1; + return Apache2::Const::OK; + } + + foreach(qw/ pref_prefix pref_first_given_name pref_second_given_name pref_family_name pref_suffix/ ){ + $self->ctx->{user}->$_($opac_vals{$_}); + } + + return $self->generic_redirect($self->apache->unparsed_uri); + +} + sub _update_bookbag_metadata { my ($self, $bookbag) = @_; diff --git a/Open-ILS/src/templates-bootstrap/opac/css/style.css.tt2 b/Open-ILS/src/templates-bootstrap/opac/css/style.css.tt2 index fbbd9dd59f..c59d3ae3cf 100755 --- a/Open-ILS/src/templates-bootstrap/opac/css/style.css.tt2 +++ b/Open-ILS/src/templates-bootstrap/opac/css/style.css.tt2 @@ -2215,7 +2215,16 @@ div#facet_sidebar { .subtle-button:hover { text-decoration: underline; cursor: pointer; } .no-dec:hover { text-decoration: none; } .pending-addr td { background-color: [% css_colors.background_alert %] !important; border: 0 !important; } - +#account-update-preferred-name table { text-align: center; padding: 20px; margin-top: 18px; border-collapse: collapse; } +#account-update-preferred-name table td { + [% IF rtl == 't' -%] + text-align: right; + [% ELSE -%] + text-align: left; + [% END -%] + padding: 5px 15px 5px 15px; + border-bottom: 1px solid [% css_colors.accent_lighter %]; +} #account-update-email table { text-align: center; padding: 20px; margin-top: 18px; border-collapse: collapse; } #account-update-email table td { [% IF rtl == 't' -%] diff --git a/Open-ILS/src/templates-bootstrap/opac/myopac/prefs.tt2 b/Open-ILS/src/templates-bootstrap/opac/myopac/prefs.tt2 index e21a757574..43ae634a36 100755 --- a/Open-ILS/src/templates-bootstrap/opac/myopac/prefs.tt2 +++ b/Open-ILS/src/templates-bootstrap/opac/myopac/prefs.tt2 @@ -9,6 +9,23 @@
+ + + + + + + + [% IF ctx.user.pref_first_given_name || ctx.user.pref_second_given_name || ctx.user.pref_family_name %] diff --git a/Open-ILS/src/templates-bootstrap/opac/myopac/update_preferred_name.tt2 b/Open-ILS/src/templates-bootstrap/opac/myopac/update_preferred_name.tt2 new file mode 100644 index 0000000000..8c464f43c7 --- /dev/null +++ b/Open-ILS/src/templates-bootstrap/opac/myopac/update_preferred_name.tt2 @@ -0,0 +1,36 @@ +[% PROCESS "opac/parts/header.tt2"; + PROCESS "opac/parts/misc_util.tt2"; + WRAPPER "opac/parts/myopac/base.tt2"; + myopac_page = "prefs" %] +

[% l('Update Username') %]

+
+ +
+ [% l('Update Username') %] +
+ +[% IF ctx.password_incorrect %] + + +[% END %] + +
+
[% l("Preferred Name") %][% l( + HUMAN_NAME_FORMAT, + ctx.user.pref_prefix, + (ctx.user.pref_first_given_name || ctx.user.first_given_name), + ctx.user.pref_second_given_name, + (ctx.user.pref_family_name || ctx.user.family_name), + ctx.user.pref_suffix + ) | html %][% l("Change") %]
[% l("Preferred Name") %]
+ + + + + + + + + + + + +
[% l('Current Prefix') %] [% ctx.user.pref_prefix | html %]
[% l('Current First Name') %] [% ctx.user.pref_first_given_name | html %]
[% l('Current Second Name') %] [% ctx.user.pref_second_given_name | html %]
[% l('Current Family Name') %] [% ctx.user.pref_family_name | html %]
[% l('Current Suffix') %] [% ctx.user.pref_suffix | html %]
+ + +[% END %] diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2 index c17da05a39..d24fc94ea9 100644 --- a/Open-ILS/src/templates/opac/css/style.css.tt2 +++ b/Open-ILS/src/templates/opac/css/style.css.tt2 @@ -1818,7 +1818,15 @@ div#facet_sidebar { .subtle-button:hover { text-decoration: underline; cursor: pointer; } .no-dec:hover { text-decoration: none; } .pending-addr td { background-color: [% css_colors.background_alert %] !important; border: 0 !important; } - +#account-update-preferred-name table { text-align: center; padding: 20px; margin-top: 18px; border-collapse: collapse; } +#account-update-preferred-name table td { + [% IF rtl == 't' -%] + text-align: right; + [% ELSE -%] + text-align: left; + [% END -%] + padding: 5px 15px 5px 15px; border-bottom: 1px solid [% css_colors.accent_lighter %]; +} #account-update-email table { text-align: center; padding: 20px; margin-top: 18px; border-collapse: collapse; } #account-update-email table td { [% IF rtl == 't' -%] diff --git a/Open-ILS/src/templates/opac/myopac/prefs.tt2 b/Open-ILS/src/templates/opac/myopac/prefs.tt2 index 683d36ca89..a32c7a0b29 100644 --- a/Open-ILS/src/templates/opac/myopac/prefs.tt2 +++ b/Open-ILS/src/templates/opac/myopac/prefs.tt2 @@ -10,6 +10,23 @@ + + + + + + + + [% IF ctx.user.pref_first_given_name || ctx.user.pref_second_given_name || ctx.user.pref_family_name %]
[% l("Preferred Name") %][% l( + HUMAN_NAME_FORMAT, + ctx.user.pref_prefix, + (ctx.user.pref_first_given_name || ctx.user.first_given_name), + ctx.user.pref_second_given_name, + (ctx.user.pref_family_name || ctx.user.family_name), + ctx.user.pref_suffix + ) | html %][% l("Change") %]
[% l('Update Preferred Name') %] + +
+ [% l('Update Preferred Name') %] +
+ +[% IF ctx.password_incorrect %] +
+ [% |l %]Your current password was not correct.[% END %] +
+[% END %] + +
+ + + + + + + + + + + + + +
[% l('Current Prefix') %] [% ctx.user.pref_prefix | html %]
[% l('Current First Name') %] [% ctx.user.pref_first_given_name | html %]
[% l('Current Second Name') %] [% ctx.user.pref_second_given_name | html %]
[% l('Current Family Name') %] [% ctx.user.pref_family_name | html %]
[% l('Current Suffix') %] [% ctx.user.pref_suffix | html %]
+
+ +[% END %] + + -- 2.11.0