From c75124ebe533153055e17b935f701dce5bae3ae6 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 20 May 2012 16:55:38 -0400 Subject: [PATCH] Ability to add records to permanent bookbags in TPAC. Add an actor usr setting for holding the name of a default book list: opac.default_list. Add a button on the my list interface to choose a list should as the default list for adding titles. There is presently no way to unset a default menu, though the default can be changed to any other menu at any time by clicking that list's button. Modify opac/record and opac/results so that if a patron is logged in their my lists will populate a menu. This menu will include options to add to a temporary list, the default list (if any), up to 10 of the user's other lists, to add to a newly created list, or to see all of their lists and add to one that does not appear on the menu. Adding to a temporary list will function the same as adding to a list does prior to this enhancement. Adding to a list chosen from the menu will add the record to that list, and return the user to the search results or record page that they were looking at. Choosing to add to a new list will take the user to their "my lists" page where they can create a new list. After the list is created, the record they wanted to add will be added to the new list and they will be returned to the search results or record that they were looking at. Choosing the "see all" menu option will also take the user to their "my lists" page. However, all of their bookbags will be visible and not just the normal limit of 10. Their will be a button next to each list's name with the text "Add to this list." When the user clicks one of those buttons, the record will be added to that list and the user's session redirected back to their search or result page. The user will have the option to create a new list when viewing all of their lists. The user will also be able to use the "Add to this list" feature when they have chosen the "Add to new list" menu option. This is done from simplicity in the design, but also allows the user to change their mind at the last second. If a patron is not logged in, the add to my list will appear the same as it does prior to this development. It will continue to function as it does prior to this development. Signed-off-by: Jason Stephenson --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 109 ++++++++++++++++-- .../lib/OpenILS/WWW/EGCatLoader/Record.pm | 6 + .../lib/OpenILS/WWW/EGCatLoader/Search.pm | 3 + Open-ILS/src/templates/opac/myopac/lists.tt2 | 33 ++++++ .../templates/opac/myopac/prefs_settings.tt2 | 9 +- .../templates/opac/parts/record/summary.tt2 | 61 +++++++++- .../src/templates/opac/parts/result/table.tt2 | 64 +++++++++- Open-ILS/web/css/skin/default/opac/style.css | 72 ++++++++++++ 8 files changed, 346 insertions(+), 11 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 2346542f85..f716f1d01a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -257,6 +257,37 @@ sub fetch_optin_prefs { return [map { {cust => $_, value => $user_set->{$_->name} } } @$opt_ins]; } +sub _load_lists_and_settings { + my $self = shift; + my $e = $self->editor; + my $stat = $self->_load_user_with_prefs; + unless ($stat) { + my $exclude = 0; + my $setting_map = $self->ctx->{user_setting_map}; + $exclude = $$setting_map{'opac.default_list'} if ($$setting_map{'opac.default_list'}); + $self->ctx->{bookbags} = $e->search_container_biblio_record_entry_bucket( + [ + {owner => $self->ctx->{user}->id, btype => 'bookbag', id => {'<>' => $exclude}}, { + order_by => {cbreb => 'name'}, + limit => $self->cgi->param('limit') || 10, + offset => $self->cgi->param('offset') || 0 + } + ] + ); + # We also want a total count of the user's bookbags. + my $q = { + 'select' => { 'cbreb' => [ { 'column' => 'id', 'transform' => 'count', 'aggregate' => 'true', 'alias' => 'count' } ] }, + 'from' => 'cbreb', + 'where' => { 'btype' => 'bookbag', 'owner' => $self->ctx->{user}->id } + }; + my $r = $e->json_query($q); + $self->ctx->{bookbag_count} = $r->[0]->{'count'}; + } else { + return $stat; + } + return undef; +} + sub update_optin_prefs { my $self = shift; my $user_prefs = shift; @@ -351,6 +382,7 @@ sub load_myopac_prefs_settings { opac.hits_per_page opac.default_search_location opac.default_pickup_location + opac.temporary_list_warn /; my $stat = $self->_load_user_with_prefs; @@ -1645,7 +1677,10 @@ sub load_myopac_bookbags { $e->rollback; return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; } - + + # We load the user prefs to get their default bookbag. + $self->_load_user_with_prefs; + # If the user wants a specific bookbag's items, load them. # XXX add bookbag item paging support @@ -1697,6 +1732,16 @@ sub load_myopac_bookbags { $bookbag->items($items); } + # If we have add_rec, we got here from the "Add to new list" + # or "See all" popmenu items. + if (my $add_rec = $self->cgi->param('add_rec')) { + $self->ctx->{add_rec} = $add_rec; + $self->ctx->{where_from} = $self->ctx->{referer}; + if ( my $anchor = $self->cgi->param('anchor') ) { + $self->ctx->{where_from} =~ s/#.*|$/#$anchor/; + } + } + $e->rollback; return Apache2::Const::OK; } @@ -1714,7 +1759,7 @@ sub load_myopac_bookbag_update { $action = 'save_notes' if $cgi->param('save_notes'); $action ||= $cgi->param('action'); - $list_id ||= $cgi->param('list'); + $list_id ||= $cgi->param('list') || $cgi->param('bbid'); my @add_rec = $cgi->param('add_rec') || $cgi->param('record'); my @selected_item = $cgi->param('selected_item'); @@ -1743,9 +1788,20 @@ sub load_myopac_bookbag_update { $list->owner($e->requestor->id); $list->btype('bookbag'); $list->pub($shared ? 't' : 'f'); - $success = $U->simplereq('open-ils.actor', - 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list) - + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list); + if (ref($success) ne 'HASH' && scalar @add_rec) { + $list_id = (ref($success)) ? $success->id : $success; + foreach my $add_rec (@add_rec) { + my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new; + $item->bucket($list_id); + $item->target_biblio_record_entry($add_rec); + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item); + last unless $success; + } + $url = $cgi->param('where_from') if ($success && $cgi->param('where_from')); + } } elsif($action eq 'place_hold') { # @hold_recs comes from anon lists redirect; selected_itesm comes from existing buckets @@ -1779,7 +1835,21 @@ sub load_myopac_bookbag_update { if($action eq 'delete') { $success = $U->simplereq('open-ils.actor', 'open-ils.actor.container.full_delete', $e->authtoken, 'biblio', $list_id); - + if ($success) { + # We check to see if we're deleting the user's default list. + $self->_load_user_with_prefs; + my $settings_map = $self->ctx->{user_setting_map}; + if ($$settings_map{'opac.default_list'} == $list_id) { + # We unset the user's opac.default_list setting. + $success = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.patron.settings.update', + $e->authtoken, + $e->requestor->id, + { 'opac.default_list' => 0 } + ); + } + } } elsif($action eq 'show') { unless($U->is_true($list->pub)) { $list->pub('t'); @@ -1810,8 +1880,15 @@ sub load_myopac_bookbag_update { 'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item); last unless $success; } - - } elsif($action eq 'del_item') { + # Redirect back where we came from if we have an anchor parameter: + if ( my $anchor = $cgi->param('anchor') ) { + $url = $self->ctx->{referer}; + $url =~ s/#.*|$/#$anchor/; + } elsif ($cgi->param('where_from')) { + # Or, if we have a "where_from" parameter. + $url = $cgi->param('where_from'); + } + } elsif ($action eq 'del_item') { foreach (@selected_item) { $success = $U->simplereq( 'open-ils.actor', @@ -1822,6 +1899,22 @@ sub load_myopac_bookbag_update { } elsif ($action eq 'save_notes') { $success = $self->update_bookbag_item_notes; $url .= "&bbid=" . uri_escape($cgi->param("bbid")) if $cgi->param("bbid"); + } elsif ($action eq 'make_default') { + $success = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.patron.settings.update', + $e->authtoken, + $list->owner, + { 'opac.default_list' => $list_id } + ); + } elsif ($action eq 'remove_default') { + $success = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.patron.settings.update', + $e->authtoken, + $list->owner, + { 'opac.default_list' => 0 } + ); } return $self->generic_redirect($url) if $success; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm index c7e9b4d29e..67e6369822 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -49,6 +49,12 @@ sub load_record { $self->fetch_related_search_info($rec_id); $self->timelog("past related search info"); + # Check for user and load lists and prefs + if ($self->ctx->{user}) { + $self->_load_lists_and_settings; + $self->timelog("load user lists and settings"); + } + # run copy retrieval in parallel to bib retrieval # XXX unapi my $cstore = OpenSRF::AppSession->create('open-ils.cstore'); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index e4e23e5757..bba1a0ac31 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -447,6 +447,9 @@ sub load_rresults { return $stat if $stat; } + # load temporary_list settings for user and ou: + $self->_load_lists_and_settings if ($ctx->{user}); + # shove recs into context in search results order for my $rec_id (@$rec_ids) { push( diff --git a/Open-ILS/src/templates/opac/myopac/lists.tt2 b/Open-ILS/src/templates/opac/myopac/lists.tt2 index efefd4d6f4..7d0ce867e0 100644 --- a/Open-ILS/src/templates/opac/myopac/lists.tt2 +++ b/Open-ILS/src/templates/opac/myopac/lists.tt2 @@ -16,6 +16,12 @@ [%- INCLUDE "opac/parts/preserve_params.tt2"; %] + [% IF ctx.add_rec %] + + [% END %] + [% IF ctx.where_from %] + + [% END %] @@ -67,6 +73,19 @@

[% bbag.name | html %]

[% IF bbag.description %]
[% bbag.description | html %]
[% END %] + [% IF ctx.add_rec %] +
+
+ + + + [% IF ctx.where_from %] + + [% END %] + +
+
+ [% END %]
@@ -114,6 +133,20 @@ -%]'>[% l('HTML View') %] [% END %]
+ [% setting = 'opac.default_list'; %] + +
+ + [%- INCLUDE "opac/parts/preserve_params.tt2"; %] + [% IF ctx.user_setting_map.$setting == bbag.id %] + + + [% ELSE %] + + + [% END %] +
+
[% IF CGI.param("bbid") == bbag.id %] diff --git a/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 b/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 index 4ee61903cf..864ca99ba6 100644 --- a/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 +++ b/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 @@ -77,7 +77,14 @@ [% IF ctx.user_setting_map.$setting; %] checked='checked' [% END %]/> - + + [% l('Warn when adding to temporary book list?') %] + + [% setting = 'opac.temporary_list_warn' %] + + +