From 11e10ddec4b31afc73ffdf23350fd9f3c96116ab Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 9 Jun 2011 16:04:43 -0400 Subject: [PATCH] Initial support for updating user prefs Starting with hits-per-page and enable/disable circ/hold history Signed-off-by: Bill Erickson --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 44 ++++++++++++++++++++-- .../default/opac/myopac/prefs_settings.tt2 | 5 +-- 2 files changed, 43 insertions(+), 6 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 ecdb3a16fa..4ba5f0c1fa 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -7,6 +7,7 @@ use OpenILS::Utils::Fieldmapper; use OpenILS::Application::AppUtils; use OpenILS::Event; use OpenSRF::Utils::JSON; +use DateTime; my $U = 'OpenILS::Application::AppUtils'; sub prepare_extended_user_info { @@ -106,7 +107,7 @@ sub update_optin_prefs { return $user_prefs; } -sub load_myopac_prefs_settings { +sub _load_user_with_prefs { my $self = shift; my $stat = $self->prepare_extended_user_info('settings'); return $stat if $stat; # not-OK @@ -116,12 +117,49 @@ sub load_myopac_prefs_settings { @{$self->ctx->{user}->settings} }; + return undef; +} + +sub load_myopac_prefs_settings { + my $self = shift; + + my $stat = $self->_load_user_with_prefs; + return $stat if $stat; + return Apache2::Const::OK unless $self->cgi->request_method eq 'POST'; - # process POST request... + # some setting values from the form don't match the + # required value/format for the db, so they have to be + # individually translated. + + my %settings; + my $set_map = $self->ctx->{user_setting_map}; + + my $key = 'opac.hits_per_page'; + my $val = $self->cgi->param($key); + $settings{$key}= $val unless $$set_map{$key} eq $val; + + my $now = DateTime->now->strftime('%F'); + for $key (qw/history.circ.retention_start history.hold.retention_start/) { + $val = $self->cgi->param($key); + if($val and $val eq 'on') { + # Set the start time to 'now' unless a start time already exists for the user + $settings{$key} = $now unless $$set_map{$key}; + } else { + # clear the start time if one previously existed for the user + $settings{$key} = undef if $$set_map{$key}; + } + } + + # Send the modified settings off to be saved + $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.patron.settings.update', + $self->editor->authtoken, undef, \%settings); - return Apache2::Const::OK; + # re-fetch user prefs + return $self->_load_user_with_prefs || Apache2::Const::OK; } sub fetch_user_holds { diff --git a/Open-ILS/web/templates/default/opac/myopac/prefs_settings.tt2 b/Open-ILS/web/templates/default/opac/myopac/prefs_settings.tt2 index cb5335ac24..84ef7a8cd4 100644 --- a/Open-ILS/web/templates/default/opac/myopac/prefs_settings.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/prefs_settings.tt2 @@ -3,13 +3,12 @@ myopac_page = "prefs_notify"; prefs_page = 'settings' %] -
+
- [% l('Save') %] +
-- 2.11.0