From 4624bed0e00c3b008d716aadf1d660ecb5ed098e Mon Sep 17 00:00:00 2001 From: berick Date: Fri, 4 Mar 2011 14:43:36 -0500 Subject: [PATCH] added bookbag CRUD+ interface which supports create/delete/rename/show/hide/add_rec/del_item actions; some I18N and cleanup of lists.tt2; added generic redirect sub to replace the bare REDIRECTs spread throughout w/ a more consistent mechanism for finding where to redirect --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 47 +++----- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 85 ++++++++++++- .../lib/OpenILS/WWW/EGCatLoader/Container.pm | 18 ++- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 18 +++ .../web/templates/default/opac/myopac/lists.tt2 | 133 ++++++++------------- 5 files changed, 177 insertions(+), 124 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index db97f859a6..41c6af751b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -118,7 +118,8 @@ sub load { return $self->load_myopac_circs if $path =~ /opac\/myopac\/circs/; return $self->load_myopac_fines if $path =~ /opac\/myopac\/main/; return $self->load_myopac_update_email if $path =~ /opac\/myopac\/update_email/; - return $self->load_myopac_bookbags if $path =~ /opac\/myopac\/bookbags/; + return $self->load_myopac_bookbags if $path =~ /opac\/myopac\/lists/; + return $self->load_myopac_bookbag_update if $path =~ /opac\/myopac\/list\/update/; return $self->load_myopac if $path =~ /opac\/myopac/; return Apache2::Const::OK; @@ -131,8 +132,7 @@ sub load { sub redirect_ssl { my $self = shift; my $new_page = sprintf('https://%s%s', $self->apache->hostname, $self->apache->unparsed_uri); - $self->apache->print($self->cgi->redirect(-url => $new_page)); - return Apache2::Const::REDIRECT; + return $self->generic_redirect($new_page); } # ----------------------------------------------------------------------------- @@ -143,8 +143,7 @@ sub redirect_auth { my $self = shift; my $login_page = sprintf('https://%s%s/login', $self->apache->hostname, $self->ctx->{opac_root}); my $redirect_to = uri_escape($self->apache->unparsed_uri); - $self->apache->print($self->cgi->redirect(-url => "$login_page?redirect_to=$redirect_to")); - return Apache2::Const::REDIRECT; + return $self->generic_redirect("$login_page?redirect_to=$redirect_to"); } # ----------------------------------------------------------------------------- @@ -248,20 +247,16 @@ sub load_login { my $acct = $self->apache->unparsed_uri; $acct =~ s#/login#/myopac/main#; - $self->apache->print( - $cgi->redirect( - -url => $cgi->param('redirect_to') || $acct, - -cookie => $cgi->cookie( - -name => COOKIE_SES, - -path => '/', - -secure => 1, - -value => $response->{payload}->{authtoken}, - -expires => ($persist) ? CORE::time + $response->{payload}->{authtime} : undef - ) + return $self->generic_redirect( + $cgi->param('redirect_to') || $acct, + $cgi->cookie( + -name => COOKIE_SES, + -path => '/', + -secure => 1, + -value => $response->{payload}->{authtoken}, + -expires => ($persist) ? CORE::time + $response->{payload}->{authtime} : undef ) ); - - return Apache2::Const::REDIRECT; } # ----------------------------------------------------------------------------- @@ -274,19 +269,15 @@ sub load_logout { # while logged in, go ahead and clear it out. $self->clear_anon_cache; - $self->apache->print( - $self->cgi->redirect( - -url => $self->ctx->{home_page}, - -cookie => $self->cgi->cookie( - -name => COOKIE_SES, - -path => '/', - -value => '', - -expires => '-1h' - ) + return $self->generic_redirect( + $self->ctx->{home_page}, + $self->cgi->cookie( + -name => COOKIE_SES, + -path => '/', + -value => '', + -expires => '-1h' ) ); - - return Apache2::Const::REDIRECT; } # context additions: 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 334ccafa31..4c32006c15 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -234,8 +234,7 @@ sub load_place_hold { # if successful, return the user to the requesting page $self->apache->log->info("Redirecting back to " . $cgi->param('redirect_to')); - $self->apache->print($cgi->redirect(-url => $cgi->param('redirect_to'))); - return Apache2::Const::REDIRECT; + return $self->generic_redirect; } else { @@ -481,9 +480,8 @@ sub load_myopac_update_email { my $url = $self->apache->unparsed_uri; $url =~ s/update_email/main/; - $self->apache->print($self->cgi->redirect(-url => $url)); - return Apache2::Const::REDIRECT; + return $self->generic_redirect($url); } sub load_myopac_bookbags { @@ -495,7 +493,9 @@ sub load_myopac_bookbags { my $args = {order_by => {cbreb => 'name'}}; $args->{limit} = $limit if $limit; - $args->{offset} = $limit if $limit; + $args->{offset} = $offset if $offset; + + (undef, $ctx->{mylist}) = $self->fetch_mylist; $ctx->{bookbags} = $e->search_container_biblio_record_entry_bucket([ {owner => $self->editor->requestor->id, btype => 'bookbag'}, @@ -506,4 +506,79 @@ sub load_myopac_bookbags { } +# actions are create, delete, show, hide, rename, add_rec, delete_item +# CGI is action, list=list_id, add_rec=bre_id, del_item=bucket_item_id, name=new_bucket_name +sub load_myopac_bookbag_update { + my $self = shift; + my $e = $self->editor; + my $cgi = $self->cgi; + my $action = $cgi->param('action'); + my $list_id = $cgi->param('list'); + my $add_rec = $cgi->param('add_rec'); + my $del_item = $cgi->param('del_item'); + my $name = $cgi->param('name'); + my $success = 0; + my $list; + + if($action eq 'create') { + $list = Fieldmapper::container::biblio_record_entry_bucket->new; + $list->name($name); + $list->owner($e->requestor->id); + $list->btype('bookbag'); + $list->pub('f'); + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list) + + } else { + + $list = $e->retrieve_container_biblio_record_entry_bucket($list_id); + + return Apache2::Const::HTTP_BAD_REQUEST unless + $list and $list->owner == $e->requestor->id; + } + + if($action eq 'delete') { + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.full_delete', $e->authtoken, 'biblio', $list_id); + + } elsif($action eq 'show') { + unless($U->is_true($list->pub)) { + $list->pub('t'); + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list); + } + + } elsif($action eq 'hide') { + if($U->is_true($list->pub)) { + $list->pub('f'); + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list); + } + + } elsif($action eq 'rename') { + if($name) { + $list->name($name); + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list); + } + + } elsif($action eq '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); + + } elsif($action eq 'del_item') { + $success = $U->simplereq('open-ils.actor', + 'open-ils.actor.container.item.delete', $e->authtoken, 'biblio', $del_item); + } + + return $self->generic_redirect if $success; + + $self->ctx->{bucket_action} = $action; + $self->ctx->{bucket_action_failed} = 1; + return Apache2::Const::OK; +} + 1 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm index 934714a77f..49954e7ec6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm @@ -97,19 +97,15 @@ sub mylist_action_redirect { my $self = shift; my $cache_key = shift; - $self->apache->print( - $self->cgi->redirect( - -url => $self->cgi->param('redirect_to') || $self->ctx->{referer} || $self->ctx->{home_page}, - -cookie => $self->cgi->cookie( - -name => COOKIE_ANON_CACHE, - -path => '/', - -value => ($cache_key) ? $cache_key : '', - -expires => ($cache_key) ? undef : '-1h' - ) + return $self->generic_redirect( + undef, + $self->cgi->cookie( + -name => COOKIE_ANON_CACHE, + -path => '/', + -value => ($cache_key) ? $cache_key : '', + -expires => ($cache_key) ? undef : '-1h' ) ); - - return Apache2::Const::REDIRECT; } 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 50495a87e9..63b5213831 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -119,4 +119,22 @@ sub init_ro_object_cache { }; } +sub generic_redirect { + my $self = shift; + my $url = shift; + my $cookie = shift; # can be an array of cgi.cookie's + + $self->apache->print( + $self->cgi->redirect( + -url => $url || + $self->cgi->param('redirect_to') || + $self->ctx->{referer} || + $self->ctx->{home_page}, + -cookie => $cookie + ) + ); + + return Apache2::Const::REDIRECT; +} + 1; diff --git a/Open-ILS/web/templates/default/opac/myopac/lists.tt2 b/Open-ILS/web/templates/default/opac/myopac/lists.tt2 index c93fac5ad8..6d1a6db6e9 100644 --- a/Open-ILS/web/templates/default/opac/myopac/lists.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/lists.tt2 @@ -2,60 +2,49 @@ WRAPPER "default/opac/parts/base.tt2" + "default/opac/parts/myopac/base.tt2"; myopac_page = "lists" %] -
+
+ +
-

Create new list

- Enter the name of the new list:
+

[% l('Create new list') %]

+ [% l('Enter the name of the new list:') %]
+
- Share this list? - Sharing HelpSharing Help - - -
- - + [% l('No') %] +
+ [% l('Yes') %]
- Submit + [% l('Submit') %]       - Cancel + [% l('Cancel') %]
- My Lists - - Export List - + [% l('My Lists') %] + [% l('Export List') %]
- Saving Help[% l('Saving Help') %] - Save + [% l('Save') %]
@@ -63,11 +52,11 @@ @@ -78,16 +67,15 @@
- Temporary List + [% l('Temporary List') %] Anonymous List Help
- @@ -101,24 +89,23 @@
- + Title
+
@@ -158,40 +145,30 @@ - + @@ -212,14 +189,12 @@ @@ -244,13 +219,11 @@ -- 2.11.0
@@ -126,9 +113,9 @@ Title
- + - [% l("Items") %] + [% l("Items") %] - - [% l("No") %] - - - [% l("Yes") %] - - [% l("(View)") %] - - RSS Feed + [% l("No") %] + [% l("Yes") %] + [% l("(View)") %] + + [% l('RSS Feed') %] - [% l("Hide") %] - [% l("Share this Bookbag") %] + [% l("Hide") %] + [% l("Share this Bookbag") %] - [% l("Delete") %] + [% l("Delete") %]
[% l("Share this Bookbag") %] - [% l("(Help)") %] + [% l("(Help)") %] [% l("Yes") %] [% l("No") %] - +
- + - [% l("remove") %] + [% l("remove") %]