TPac: on-fly-list management improvements
authorBill Erickson <berick@esilibrary.com>
Fri, 9 Sep 2011 18:08:31 +0000 (14:08 -0400)
committerBill Erickson <berick@esilibrary.com>
Sun, 11 Sep 2011 22:26:32 +0000 (18:26 -0400)
* implemented remove-from-list function
* After add or remove from list on results page, direct user back to the
context record via page anchor

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm
Open-ILS/src/templates/opac/parts/result/table.tt2

index a9d0565..651ac48 100644 (file)
@@ -97,6 +97,7 @@ sub load {
     return $self->load_cnbrowse if $path =~ m|opac/cnbrowse|;
 
     return $self->load_mylist_add if $path =~ m|opac/mylist/add|;
+    return $self->load_mylist_delete if $path =~ m|opac/mylist/delete|;
     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|;
index be45ffc..a51ddc5 100644 (file)
@@ -56,7 +56,21 @@ sub load_mylist_add {
     return $self->mylist_action_redirect($cache_key);
 }
 
-# Removes a record ID from My List, or moves to an actual bookbag
+sub load_mylist_delete {
+    my $self = shift;
+    my $rec_id = $self->cgi->param('record');
+
+    my ($cache_key, $list) = $self->fetch_mylist;
+    $list = [ grep { $_ ne $rec_id } @$list ];
+
+    $cache_key = $U->simplereq(
+        'open-ils.actor',
+        'open-ils.actor.anon_cache.set_value', 
+        $cache_key, ANON_CACHE_MYLIST, $list);
+
+    return $self->mylist_action_redirect($cache_key);
+}
+
 sub load_mylist_move {
     my $self = shift;
     my @rec_ids = $self->cgi->param('record');
@@ -112,8 +126,16 @@ sub mylist_action_redirect {
     my $self = shift;
     my $cache_key = shift;
 
+    my $url;
+    if( my $anchor = $self->cgi->param('anchor') ) {
+        # on the results page, we want to redirect 
+        # back to record that was affected
+        $url = $self->ctx->{referer};
+        $url =~ s/#.*|$/#$anchor/g;
+    } 
+
     return $self->generic_redirect(
-        undef, 
+        $url,
         $self->cgi->cookie(
             -name => COOKIE_ANON_CACHE,
             -path => '/',
index 905307e..3948515 100644 (file)
@@ -53,7 +53,7 @@
                                                 name='result_table_title_cell'
                                                 valign="top">
                                                 <div class="bold">
-                                                    <a title="[% attrs.title | uri %]" name='item_title'
+                                                    <a name='record_[% rec.id %]' title="[% attrs.title | uri %]" name='item_title'
                                                         href="[% mkurl(ctx.opac_root _ '/record/' _ rec.id) %]"
                                                         class='search_link'>[% attrs.title | html %]</a>
                                                 </div>
                                                             [%  
                                                                 operation = ctx.mylist.grep(rec.id).size ? "delete" : "add";
                                                                 label = (operation == "add") ? l("Add to my list") : l("Remove from my list");
+                                                                href = mkurl(ctx.opac_root _ '/mylist/' _ operation, 
+                                                                        {record => rec.id, anchor => 'record_' _ rec.id}, 1);
                                                             %]      
-                                                            <a href="[% mkurl(ctx.opac_root _ '/mylist/' _ operation, {record => rec.id}, 1) %]" class="no-dec">
+                                                            <a href="[% href %]" class="no-dec">
                                                                 <img src="[% ctx.media_prefix %]/images/clipboard.png" alt="" />
                                                                 [% label %]
                                                             </a>