From: Lebbeous Fogle-Weekley Date: Thu, 11 Aug 2011 21:21:58 +0000 (-0400) Subject: Editable item notes. Took more than you'd think. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9eb96bd574d0fb5ff67f7229177110a4a0f557e8;p=evergreen%2Fequinox.git Editable item notes. Took more than you'd think. Had to fix open-ils.actor.container.item_note.cud, which can't possibly have ever worked. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Container.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Container.pm index ec381abf02..537f35fba0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Container.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Container.pm @@ -131,29 +131,53 @@ __PACKAGE__->register_method( sub item_note_cud { my($self, $conn, $auth, $class, $note) = @_; + + return new OpenILS::Event("BAD_PARAMS") unless + $note->class_name =~ /bucket_item_note$/; + my $e = new_editor(authtoken => $auth, xact => 1); return $e->die_event unless $e->checkauth; - my $meth = 'retrieve_' . $ctypes{$class}; - my $nclass = $note->class_name; - (my $iclass = $nclass) =~ s/n$//og; + my $meat = $ctypes{$class} . "_item_note"; + my $meth = "retrieve_$meat"; - my $db_note = $e->$meth($note->id, { - flesh => 2, - flesh_fields => { - $nclass => ['item'], - $iclass => ['bucket'] - } - }); + my $item_meat = $ctypes{$class} . "_item"; + my $item_meth = "retrieve_$item_meat"; + + my $nhint = $Fieldmapper::fieldmap->{$note->class_name}->{hint}; + (my $ihint = $nhint) =~ s/n$//og; + + my ($db_note, $item); + + if ($note->isnew) { + $db_note = $note; + + $item = $e->$item_meth([ + $note->item, { + flesh => 1, flesh_fields => {$ihint => ["bucket"]} + } + ]) or return $e->die_event; + } else { + $db_note = $e->$meth([ + $note->id, { + flesh => 2, + flesh_fields => { + $nhint => ['item'], + $ihint => ['bucket'] + } + } + ]) or return $e->die_event; + + $item = $db_note->item; + } - if($db_note->item->bucket->owner ne $e->requestor->id) { - return $e->die_event unless - $e->allowed('UPDATE_CONTAINER', $db_note->item->bucket); + if($item->bucket->owner ne $e->requestor->id) { + return $e->die_event unless $e->allowed("UPDATE_CONTAINER"); } - $meth = 'create_' . $ctypes{$class} if $note->isnew; - $meth = 'update_' . $ctypes{$class} if $note->ischanged; - $meth = 'delete_' . $ctypes{$class} if $note->isdeleted; + $meth = 'create_' . $meat if $note->isnew; + $meth = 'update_' . $meat if $note->ischanged; + $meth = 'delete_' . $meat if $note->isdeleted; return $e->die_event unless $e->$meth($note); $e->commit; } 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 3cf6c41427..8090d29fd1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1120,7 +1120,7 @@ sub load_myopac_bookbags { my $e = $self->editor; my $ctx = $self->ctx; - my $sorter = $self->cgi->param("sort"); + my $sorter = $self->cgi->param("sort") || ""; my $modifier = ($sorter =~ /\.(.+$)/) ? $1 : undef; $e->xact_begin; # replication... @@ -1175,6 +1175,9 @@ sub load_myopac_bookbags { { "target_biblio_record_entry" => $record_id_list, "bucket" => $bookbag->id + }, { + flesh => 1, + flesh_fields => {"cbrebi" => ["notes"]} } ]) or do { $self->apache->log->warn( @@ -1214,7 +1217,11 @@ sub load_myopac_bookbag_update { my $e = $self->editor; my $cgi = $self->cgi; + # save_notes is effectively another action, but is passed in a separate + # CGI parameter for what are really just layout reasons. + $action = 'save_notes' if $cgi->param('save_notes'); $action ||= $cgi->param('action'); + $list_id ||= $cgi->param('list'); my @add_rec = $cgi->param('add_rec') || $cgi->param('record'); @@ -1225,10 +1232,16 @@ sub load_myopac_bookbag_update { my $success = 0; my $list; - if($action eq 'create') { + # This url intentionally leaves off the edit_notes parameter, but + # may need to add some back in for paging. + + my $url = "https://" . $self->apache->hostname . + $self->ctx->{opac_root} . "/myopac/lists"; + + if ($action eq 'create') { $list = Fieldmapper::container::biblio_record_entry_bucket->new; $list->name($name); - $list->name($description); + $list->description($description); $list->owner($e->requestor->id); $list->btype('bookbag'); $list->pub($shared ? 't' : 'f'); @@ -1286,13 +1299,99 @@ sub load_myopac_bookbag_update { ); last unless $success; } + } elsif ($action eq 'save_notes') { + $success = $self->update_bookbag_item_notes; } - return $self->generic_redirect if $success; + return $self->generic_redirect($url) if $success; + + # XXX FIXME Bucket failure doesn't have a page to show the user anything + # right now. User just sees a 404 currently. $self->ctx->{bucket_action} = $action; $self->ctx->{bucket_action_failed} = 1; return Apache2::Const::OK; } +sub update_bookbag_item_notes { + my ($self) = @_; + my $e = $self->editor; + + my @note_keys = grep /^note-\d+/, keys(%{$self->cgi->Vars}); + my @item_keys = grep /^item-\d+/, keys(%{$self->cgi->Vars}); + + # We're going to leverage an API call that's already been written to check + # permissions appropriately. + + my $a = create OpenSRF::AppSession("open-ils.actor"); + my $method = "open-ils.actor.container.item_note.cud"; + + for my $note_key (@note_keys) { + my $note; + + my $id = ($note_key =~ /(\d+)/)[0]; + + if (!($note = + $e->retrieve_container_biblio_record_entry_bucket_item_note($id))) { + my $event = $e->die_event; + $self->apache->log->warn( + "error retrieving cbrebin id $id, got event " . + $event->{textcode} + ); + $a->kill_me; + $self->ctx->{bucket_action_event} = $event; + return; + } + + if (length($self->cgi->param($note_key))) { + $note->ischanged(1); + $note->note($self->cgi->param($note_key)); + } else { + $note->isdeleted(1); + } + + my $r = $a->request($method, $e->authtoken, "biblio", $note)->gather(1); + + if (defined $U->event_code($r)) { + $self->apache->log->warn( + "attempt to modify cbrebin " . $note->id . + " returned event " . $r->{textcode} + ); + $e->rollback; + $a->kill_me; + $self->ctx->{bucket_action_event} = $r; + return; + } + } + + for my $item_key (@item_keys) { + my $id = int(($item_key =~ /(\d+)/)[0]); + my $text = $self->cgi->param($item_key); + + chomp $text; + next unless length $text; + + my $note = new Fieldmapper::container::biblio_record_entry_bucket_item_note; + $note->isnew(1); + $note->item($id); + $note->note($text); + + my $r = $a->request($method, $e->authtoken, "biblio", $note)->gather(1); + + if (defined $U->event_code($r)) { + $self->apache->log->warn( + "attempt to create cbrebin for item " . $note->item . + " returned event " . $r->{textcode} + ); + $e->rollback; + $a->kill_me; + $self->ctx->{bucket_action_event} = $r; + return; + } + } + + $a->kill_me; + return 1; # success +} + 1 diff --git a/Open-ILS/web/css/skin/default/opac/style.css b/Open-ILS/web/css/skin/default/opac/style.css index 7df710cc22..60647dd4f5 100644 --- a/Open-ILS/web/css/skin/default/opac/style.css +++ b/Open-ILS/web/css/skin/default/opac/style.css @@ -1021,3 +1021,4 @@ a.dash-link:hover { text-decoration: underline !important; } padding-bottom: 1ex; } .cn_browse_item { padding: 2ex; } +.bookbag-item-row td { vertical-align: top; } diff --git a/Open-ILS/web/templates/default/opac/myopac/lists.tt2 b/Open-ILS/web/templates/default/opac/myopac/lists.tt2 index c8053345d3..6ba2ac87fe 100644 --- a/Open-ILS/web/templates/default/opac/myopac/lists.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/lists.tt2 @@ -100,11 +100,12 @@ [% IF bbag.pub == 't' %] [% url = 'http://' _ ctx.hostname _ '/opac/extras/feed/bookbag/html-full/' _ bbag.id %] - [% bbag.name %] + [% bbag.name | html %] [% ELSE %] - [% bbag.name %] + [% bbag.name | html %] [% END %] + [% IF bbag.description %]
[% bbag.description | html %][% END %]
[% IF bbag.pub == 't'; %] @@ -128,12 +129,18 @@ inputs[i].checked = this.checked;}"/> - + [% l('Title') %] - + [% l('Author(s)') %] + + [% l('Notes') %] + [% IF CGI.param("edit_notes") != bbag.id %] + | [% l('Edit') %] + [% END %] + [% attrs.title %] [% attrs.author %] + [% IF CGI.param("edit_notes") == bbag.id %] + + [% FOR note IN item.notes %] + + [% END %] + + + [% ELSE %] + + [% FOR note IN item.notes %] +
[% note.note | html %]
+ [% END %] + + [% END %] + + [% END %] + [% IF CGI.param("edit_notes") == bbag.id %] + + + + + [% END %]