added i18n filter support for translating text blocks via filters; more login form...
authorberick <berick@esilibrary.com>
Thu, 10 Feb 2011 16:56:59 +0000 (11:56 -0500)
committerberick <berick@esilibrary.com>
Thu, 10 Feb 2011 16:56:59 +0000 (11:56 -0500)
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm [new file with mode: 0644]
Open-ILS/web/templates/default/opac/login.tt2
Open-ILS/web/templates/default/opac/parts/login/form.tt2
Open-ILS/web/templates/default/opac/parts/topnav.tt2

index fb72913..3a62f4f 100644 (file)
@@ -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(
index 807af47..63836f8 100644 (file)
@@ -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 (file)
index 0000000..cc931fa
--- /dev/null
@@ -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;
+
index 3b2e392..2452281 100644 (file)
@@ -1,3 +1,4 @@
+[% USE CGI %]
 [%  WRAPPER "default/opac/parts/base.tt2";
     INCLUDE "default/opac/parts/topnav.tt2";
     ctx.page_title = "Account Login" %]
index 939cd17..38a6a2d 100644 (file)
@@ -1,6 +1,5 @@
-
-
 <!-- TODO: MOVE INTO SEPARATE FORGOT-PASSWORD PAGE 
+
 <div class="hide_me">
        <div class='login_text color_1' style='padding: 4px; text-align: center;'>
                <span>[% l("Login") %]</span>
 
  ^== TODO: MOVE INTO SEPARATE FORGOT-PASSWORD PAGE  -->
 
-
-[% IF ctx.login_failed_event;
+[% IF ctx.login_failed_event %]
+<div id='login-failed-message'>
+[%
     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.");
+        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 %]
-
+%]
+</div>
+[% END %]
 
 <div>
     <div style="height:20px;"></div>
@@ -84,8 +86,8 @@ END %]
                         width="100%">
                         <tr>
                                <td colspan="2" style="padding-bottom: 10px;">
-                                <h1>Log in to Your Account</h1>
-                                Please enter the following information:
+                                <h1>[% l('Log in to Your Account') %]</h1>
+                                [% l('Please enter the following information:') %]
                                 <br /><br />
                             </td>
                         </tr>
@@ -115,7 +117,9 @@ END %]
                             <td valign="top" class="lbl1">
                                 [% l('PIN Number or Password') %]<br />
                                 <span class="lbl2">
-                                    [% l('If this is your first time logging in, please enter [_1] the last 4 digits of your phone number. [_2] Example: 0926', '<br/>', '<br/>') %]
+                                    [% | l('<br/>', '<br/>') %]
+                                       If this is your first time logging in, please enter [_1] the last 4 digits of your phone number. [_2] Example: 0926
+                                    [% END %]
                                 </span>
                             </td>
                             <td valign="top">
@@ -123,13 +127,20 @@ END %]
                                     <input name="password" type="password" />
                                 </div>
                                 <div style="padding-top:7px;">
-                                    <input type='hidden'
-                                        name='redirect_to'
-                                        value='[% CGI.param('redirect_to') || ctx.referer | replace('^http:', 'https:') %]' />
+                                    [%
+                                        # 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:');
+                                    %]
+                                    <input type='hidden' name='redirect_to' value='[% redirect %]'/>
                                     <input type="checkbox" name="persist" /> [% l('Remember Me?') %]
                                 </div>
                                 <div style="padding-top:14px;">
-                                    <input type='image' alt="Log in" src="[% ctx.media_prefix %]/images/login-btn2.png" />
+                                    <input type='image' alt="[% l('Log in') %]" src="[% ctx.media_prefix %]/images/login-btn2.png" />
                                     <!-- TODO
                                     <a href="reset_password"
                                         style="position:relative;top:-13px;left:2px;font-size:10px;">Forgot your PIN?</a>
index a3ddabf..dbd398c 100644 (file)
@@ -1,4 +1,8 @@
 <!-- ****************** top_nav.xml ***************************** -->
+[% 
+    USE CGI; 
+    USE EGI18N;
+%]
 <div id="header">
     <div class="float-left"><a
         href="http://www.kcls.org"><img alt="KCLS Logo"