From 3c109547229036a60b73d830439e0df4427ae770 Mon Sep 17 00:00:00 2001 From: berick Date: Thu, 10 Feb 2011 11:56:59 -0500 Subject: [PATCH] added i18n filter support for translating text blocks via filters; more login form cleanup; moved some global USE's into topnav --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 9 ++- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 6 +- .../perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm | 19 +++++++ Open-ILS/web/templates/default/opac/login.tt2 | 1 + .../templates/default/opac/parts/login/form.tt2 | 65 ++++++++++++++-------- .../web/templates/default/opac/parts/topnav.tt2 | 4 ++ 6 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index fb7291302a..3a62f4ff10 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -82,7 +82,7 @@ sub load { # ---------------------------------------------------------------- unless($self->cgi->https and $self->editor->requestor) { # If a secure resource is requested insecurely, redirect to the login page - my $url = 'https://' . $self->apache->hostname . $self->ctx->{base_path} . "/opac/login"; + my $url = 'https://' . $self->apache->hostname . $self->ctx->{opac_root} . "/login"; $self->apache->print($self->cgi->redirect(-url => $url)); return Apache2::Const::REDIRECT; } @@ -198,6 +198,7 @@ sub load_helpers { ); }; + # retrieve and cache org unit setting values $ctx->{get_org_setting} = sub { my($org_id, $setting) = @_; $cache{org_settings}{$org_id} = {} unless $cache{org_settings}{$org_id}; @@ -218,6 +219,8 @@ sub load_common { my $ctx = $self->ctx; $ctx->{referer} = $self->cgi->referer; + $ctx->{path_info} = $self->cgi->path_info; + $ctx->{opac_root} = $ctx->{base_path} . "/opac"; # absolute base url $ctx->{is_staff} = ($self->apache->headers_in->get('User-Agent') =~ 'oils_xulrunner'); if($e->authtoken($self->cgi->cookie('ses'))) { @@ -259,7 +262,7 @@ sub load_login { my $org_unit = $cgi->param('loc') || $ctx->{aou_tree}->()->id; my $persist = $cgi->param('persist'); - # initial log form loading + # initial log form only return Apache2::Const::OK unless $username and $password; my $seed = $U->simplereq( @@ -310,7 +313,7 @@ sub load_login { sub load_logout { my $self = shift; - my $url = 'http://' . $self->apache->hostname . $self->ctx->{base_path} . "/opac/home"; + my $url = 'http://' . $self->apache->hostname . $self->ctx->{opac_root} . "/home"; $self->apache->print( $self->cgi->redirect( diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 17b226deea..4cbf4795c2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -50,7 +50,8 @@ sub handler { my $tt = Template->new({ OUTPUT => ($as_xml) ? sub { parse_as_xml($r, $ctx, @_); } : $r, INCLUDE_PATH => $ctx->{template_paths}, - DEBUG => $ctx->{debug_template} + DEBUG => $ctx->{debug_template}, + PLUGINS => {EGI18N => 'OpenILS::WWW::EGWeb::I18NFilter'} }); unless($tt->process($template, {ctx => $ctx, l => set_text_handler($ctx, $r)})) { @@ -75,7 +76,8 @@ sub set_text_handler { $lh_cache{$locale} = $lh_cache{'en_US'}; } - return sub { return $lh_cache{$locale}->maketext(@_); }; + return $OpenILS::WWW::EGWeb::I18NFilter::maketext = + sub { return $lh_cache{$locale}->maketext(@_); }; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm new file mode 100644 index 0000000000..cc931fa59f --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm @@ -0,0 +1,19 @@ +package OpenILS::WWW::EGWeb::I18NFilter; +use Template::Plugin::Filter; +use base qw(Template::Plugin::Filter); +our $DYNAMIC = 1; +our $maketext; + +sub filter { + my ($self, $text, $args) = @_; + return $maketext->($text, @$args); +} + +sub init { + my $self = shift; + $self->install_filter('l'); + return $self; +} + +1; + diff --git a/Open-ILS/web/templates/default/opac/login.tt2 b/Open-ILS/web/templates/default/opac/login.tt2 index 3b2e39285d..24522815d7 100644 --- a/Open-ILS/web/templates/default/opac/login.tt2 +++ b/Open-ILS/web/templates/default/opac/login.tt2 @@ -1,3 +1,4 @@ +[% USE CGI %] [% WRAPPER "default/opac/parts/base.tt2"; INCLUDE "default/opac/parts/topnav.tt2"; ctx.page_title = "Account Login" %] diff --git a/Open-ILS/web/templates/default/opac/parts/login/form.tt2 b/Open-ILS/web/templates/default/opac/parts/login/form.tt2 index e140bcb3f5..4c4b768640 100644 --- a/Open-ILS/web/templates/default/opac/parts/login/form.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/login/form.tt2 @@ -1,4 +1,5 @@ - + + +[% IF ctx.login_failed_event %] +
+[% + IF ctx.login_failed_event.textcode == 'PATRON_CARD_INACTIVE'; + l("The barcode used to login is marked as inactive. Please contact your local library."); + ELSIF ctx.login_failed_event.textcode == 'PATRON_INACTIVE'; + l("This account has been deactivated. Please contact your local library."); + ELSE; + l("Login failed. The username or password provided was not valid. + Ensure Caps-Lock is off and try again or contact your local library."); + END; +%] +
+[% END %] + +
@@ -72,8 +90,8 @@ width="100%"> @@ -99,33 +117,36 @@ diff --git a/Open-ILS/web/templates/default/opac/parts/topnav.tt2 b/Open-ILS/web/templates/default/opac/parts/topnav.tt2 index a3ddabf5d6..dbd398c746 100644 --- a/Open-ILS/web/templates/default/opac/parts/topnav.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/topnav.tt2 @@ -1,4 +1,8 @@ +[% + USE CGI; + USE EGI18N; +%]
-

Log in to Your Account

- Please enter the following information: +

[% l('Log in to Your Account') %]

+ [% l('Please enter the following information:') %]

- PIN Number or Password
- If this is your first time - logging in, please enter
- the last 4 digits of your phone number.
- Example: 0926
+ [% l('PIN Number or Password') %]
+ + [% | l('
', '
') %] + If this is your first time logging in, please enter [_1] the last 4 digits of your phone number. [_2] Example: 0926 + [% END %] +
- - - + [% + # If no redirect is offered or it's leading us back to the + # login form, redirect the user to My Account + redirect = CGI.param('redirect_to') || ctx.referer; + IF !redirect OR redirect.match(ctx.path_info _ '$'); + redirect = CGI.url('-full' => 1) _ '/opac/myopac/main'; + END; + redirect = redirect | replace('^http:', 'https:'); + %] + + [% l('Remember Me?') %]
- Log in - - +