[Rt-commit] rt branch, 4.2/bookmarks-in-lib, updated. rt-4.0.0rc6-157-g93ff228

Shawn Moore sartak at bestpractical.com
Tue Mar 8 12:46:06 EST 2011


The branch, 4.2/bookmarks-in-lib has been updated
       via  93ff22864bca07ad2aae6ccc87faf60c38d8b5a3 (commit)
      from  c1d9ee3afbaed6d17820868a02e5e9863420bfd3 (commit)

Summary of changes:
 lib/RT/Ticket.pm                    |   34 ++++++++++++++++++++++++++++++++++
 share/html/Ticket/Elements/Bookmark |   34 +++++++---------------------------
 2 files changed, 41 insertions(+), 27 deletions(-)

- Log -----------------------------------------------------------------
commit 93ff22864bca07ad2aae6ccc87faf60c38d8b5a3
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 12:45:57 2011 -0500

    First pass at Ticket->ToggleBookmark

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index c4e5a13..28a2611 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3698,6 +3698,40 @@ sub IsBookmarked {
     return $bookmarks->{ $self->id } ? 1 : 0;
 }
 
+=head2 ToggleBookmark
+
+Toggles whether the ticket is bookmarked by the CurrentUser.
+
+=cut
+
+sub ToggleBookmark {
+    my $self = shift;
+    my $id   = $self->id;
+
+    my @ids = $id;
+
+    if ($self->id != $self->EffectiveId) {
+        push @ids, $ticket->Merged;
+    }
+
+    my $bookmarked;
+
+    if ( grep $bookmarks->{ $_ }, @ids ) {
+        delete $bookmarks->{ $_ } foreach @ids;
+        $bookmarked = 0;
+    } else {
+        $bookmarks->{ $id } = 1;
+        $bookmarked = 1;
+    }
+
+    $self->CurrentUser->UserObj->SetAttribute(
+        Name    => 'Bookmarks',
+        Content => $bookmarks,
+    );
+
+    return $bookmarked;
+}
+
 1;
 
 =head1 AUTHOR
diff --git a/share/html/Ticket/Elements/Bookmark b/share/html/Ticket/Elements/Bookmark
index 414d79b..665dbc5 100644
--- a/share/html/Ticket/Elements/Bookmark
+++ b/share/html/Ticket/Elements/Bookmark
@@ -46,35 +46,15 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-my $bookmarks = $session{'CurrentUser'}->UserObj->FirstAttribute('Bookmarks');
-$bookmarks = $bookmarks->Content if $bookmarks;
-$bookmarks ||= {};
+my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
+$ticket->Load( $id );
 
-my $bookmarked = $bookmarks->{ $id }; # we still not sure if it's undef
-
-my @ids;
-if ( $Toggle || !$bookmarked ) {
-    my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
-    $ticket->Load( $id );
-    return unless $id = $ticket->id;
-
-    @ids = ($id, $ticket->Merged);
+my $bookmarked;
+if ($Toggle) {
+    $bookmarked = $ticket->ToggleBookmark;
 }
-
-if ( $Toggle ) {
-    if ( grep $bookmarks->{ $_ }, @ids ) {
-        delete $bookmarks->{ $_ } foreach @ids;
-        $bookmarked = 0;
-    } else {
-        $bookmarks->{ $id } = 1;
-        $bookmarked = 1;
-    }
-    $session{'CurrentUser'}->UserObj->SetAttribute(
-        Name    => 'Bookmarks',
-        Content => $bookmarks,
-    );
-} elsif ( !$bookmarked ) {
-    $bookmarked = grep $bookmarks->{ $_ }, @ids;
+else {
+    $bookmarked = $ticket->IsBookmarked;
 }
 </%INIT>
 <%ARGS>

-----------------------------------------------------------------------


More information about the Rt-commit mailing list