Add a warning when the user adds a record to a temporary list.
authorJason Stephenson <jason@sigio.com>
Tue, 26 Jun 2012 00:26:27 +0000 (20:26 -0400)
committerJason Stephenson <jason@sigio.com>
Wed, 27 Jun 2012 23:15:34 +0000 (19:15 -0400)
TPAC has been modified so that a user will see a warning before adding
a record to a temporary bookbag.  This message serves to inform the
user that they are adding to a temporary list that will disappear when
their session ends.

A new org. unit setting has been added,
opac.patron.temporary_list_warn, that will enable this warning when
set.  Sites may choose not to display this warning.

The user may also set a preference in their search preferences to
disable this warning.  The setting only works when a user is logged
in, of course.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/temp_warn.tt2 [new file with mode: 0644]

index 63f919a..6ce61b7 100644 (file)
@@ -127,6 +127,8 @@ sub load {
     return $self->load_mylist_move if $path =~ m|opac/mylist/move|;
     return $self->load_mylist if $path =~ m|opac/mylist|;
     return $self->load_cache_clear if $path =~ m|opac/cache/clear|;
+    return $self->load_temp_warn_post if $path =~ m|opac/temp_warn/post|;
+    return $self->load_temp_warn if $path =~ m|opac/temp_warn|;
 
     # ----------------------------------------------------------------
     #  Everything below here requires SSL
index 6cc6796..269cbc2 100644 (file)
@@ -59,6 +59,12 @@ sub load_mylist_add {
         'open-ils.actor.anon_cache.set_value', 
         $cache_key, (ref $self)->ANON_CACHE_MYLIST, $list);
 
+    # Check if we need to warn patron about adding to a "temporary"
+    # list:
+    if ($self->check_for_temp_list_warning) {
+        return $self->mylist_warning_redirect($cache_key);
+    }
+
     return $self->mylist_action_redirect($cache_key);
 }
 
@@ -151,6 +157,38 @@ sub mylist_action_redirect {
     );
 }
 
+# called after an anon-cache / my list addition when we are configured
+# to show a warning to the user.
+
+sub mylist_warning_redirect {
+    my $self = shift;
+    my $cache_key = shift;
+
+    my $base_url = sprintf(
+        "%s://%s%s/temp_warn",
+        $self->cgi->https ? 'https' : 'http',
+        $self->apache->hostname,
+        $self->ctx->{opac_root}
+    );
+
+    my $redirect = $self->ctx->{referer};
+    if (my $anchor = $self->cgi->param('anchor')) {
+        $redirect =~ s/#.*|$/#$anchor/;
+    }
+
+    $base_url .= '?redirect_to=' . uri_escape($redirect);
+
+    return $self->generic_redirect(
+        $base_url,
+        $self->cgi->cookie(
+            -name => (ref $self)->COOKIE_ANON_CACHE,
+            -path => '/',
+            -value => ($cache_key) ? $cache_key : '',
+            -expires => ($cache_key) ? undef : '-1h'
+        )
+    );
+}
+
 sub load_mylist {
     my ($self) = shift;
     (undef, $self->ctx->{mylist}, $self->ctx->{mylist_marc_xml}) =
@@ -159,4 +197,24 @@ sub load_mylist {
     return Apache2::Const::OK;
 }
 
+sub load_temp_warn_post {
+    my $self = shift;
+    my $url = $self->cgi->param('redirect_to');
+    return $self->generic_redirect(
+        $url,
+        $self->cgi->cookie(
+            -name => 'no_temp_list_warn',
+            -path => '/',
+            -value => ($self->cgi->param('no_temp_list_warn')) ? '1' : '',
+            -expires => ($self->cgi->param('no_temp_list_warn')) ? undef : '-1h'
+        )
+    );
+}
+
+sub load_temp_warn {
+    my $self = shift;
+    $self->ctx->{'redirect_to'} = $self->cgi->param('redirect_to');
+    return Apache2::Const::OK;
+}
+
 1;
index 1733d49..166875c 100644 (file)
@@ -551,7 +551,7 @@ sub check_for_temp_list_warning {
     my $cgi = $self->cgi;
 
     my $lib = $self->_get_search_lib;
-    my $warn = ($ctx->{get_org_setting}->($lib, 'opac.patron_temporary_list_warn')) ? 1 : 0;
+    my $warn = ($ctx->{get_org_setting}->($lib || 1, 'opac.patron.temporary_list_warn')) ? 1 : 0;
 
     if ($warn && $ctx->{user}) {
         $self->_load_user_with_prefs;
diff --git a/Open-ILS/src/templates/opac/temp_warn.tt2 b/Open-ILS/src/templates/opac/temp_warn.tt2
new file mode 100644 (file)
index 0000000..d6be0b3
--- /dev/null
@@ -0,0 +1,28 @@
+[%  PROCESS "opac/parts/header.tt2";
+    PROCESS "opac/parts/misc_util.tt2";
+    WRAPPER "opac/parts/base.tt2";
+    INCLUDE "opac/parts/topnav.tt2";
+    ctx.page_title = l("Temporary List Warning") %]
+    <div id="search-wrapper">
+        [% INCLUDE "opac/parts/searchbar.tt2" %]
+    </div>
+    <div id="content-wrapper">
+        <div id="main-content">
+             <p class="big-strong">[% l('You are adding to a temporary list.') %]
+                [% IF ctx.user ;
+                      l('This information will disappear when you logout, unless you save it to a permanent list.');
+                   ELSE;
+                      l('This information will disappear when you end your session, unless you login and save it to a permanent list.');
+                   END
+                %]</p>
+             <form method="POST" action="[% mkurl(ctx.opac_root _ '/temp_warn/post', {}, 1) %]">
+             <input type="hidden" name="redirect_to" value="[% ctx.redirect_to %]" />
+             <input type="checkbox" name="no_temp_list_warn" value="on" />
+             <label for="no_temp_list_warn">[% l('Do not show this warning again.') %]</label>
+             <br />
+             <input type="submit" class="fixed" value="[% l('OK') %]" />
+             </form>
+            <div class="common-full-pad"></div>        
+        </div>
+    </div>
+[% END %]