[Rt-commit] rt branch, admin_ui, updated. cab4c4c0e6e270d14e80e6798edb903022d798e8

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Dec 2 21:37:25 EST 2009


The branch, admin_ui has been updated
       via  cab4c4c0e6e270d14e80e6798edb903022d798e8 (commit)
      from  4e2f89ce2861c33dfcdc79ccd05eb5e339788792 (commit)

Summary of changes:
 lib/RT/Action/EditUserRights.pm                    |    6 +-
 lib/RT/Action/EditWatchers.pm                      |    4 +-
 lib/RT/View/Form/Field/SelectUser.pm               |   69 +-------------
 lib/RT/{Shredder/Dependency.pm => View/Helpers.pm} |   98 +++++++++++--------
 4 files changed, 64 insertions(+), 113 deletions(-)
 copy lib/RT/{Shredder/Dependency.pm => View/Helpers.pm} (56%)

- Log -----------------------------------------------------------------
commit cab4c4c0e6e270d14e80e6798edb903022d798e8
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Dec 3 10:37:10 2009 +0800

    refactor render_user... stuff to RT::View::Helpers

diff --git a/lib/RT/Action/EditUserRights.pm b/lib/RT/Action/EditUserRights.pm
index 454b40f..701ef67 100644
--- a/lib/RT/Action/EditUserRights.pm
+++ b/lib/RT/Action/EditUserRights.pm
@@ -4,7 +4,7 @@ use warnings;
 
 package RT::Action::EditUserRights;
 use base qw/RT::Action::EditRights/;
-use RT::View::Form::Field::SelectUser;
+use RT::View::Helpers qw/render_user/;
 use Scalar::Defer;
 
 sub arguments {
@@ -30,9 +30,7 @@ sub arguments {
             available_values => defer { $self->available_values },
             render_as        => 'Checkboxes',
             multiple         => 1,
-            label => RT::View::Form::Field::SelectUser->_render_user(
-                $user->member->object
-            ),
+            label => render_user( $user->member->object ),
         };
     }
     return $args;
diff --git a/lib/RT/Action/EditWatchers.pm b/lib/RT/Action/EditWatchers.pm
index 58eb033..e4d3fd6 100644
--- a/lib/RT/Action/EditWatchers.pm
+++ b/lib/RT/Action/EditWatchers.pm
@@ -3,6 +3,7 @@ use warnings;
 
 package RT::Action::EditWatchers;
 use base qw/RT::Action Jifty::Action/;
+use RT::View::Helpers qw/render_user/;
 use Scalar::Defer;
 
 __PACKAGE__->mk_accessors('object');
@@ -139,8 +140,7 @@ sub available_values {
         while ( my $user = $users->next ) {
             push @users,
               {
-                display =>
-                  RT::View::Form::Field::SelectUser->_render_user($user),
+                display => render_user($user),
                 value => $user->principal_id
               };
         }
diff --git a/lib/RT/View/Form/Field/SelectUser.pm b/lib/RT/View/Form/Field/SelectUser.pm
index ebf67ba..fd26e37 100644
--- a/lib/RT/View/Form/Field/SelectUser.pm
+++ b/lib/RT/View/Form/Field/SelectUser.pm
@@ -3,70 +3,7 @@ use warnings;
 use strict;
 use base 'Jifty::Web::Form::Field::Select';
 use Email::Address;
-
-sub _render_user {
-    my $self = shift;
-    my $user = shift;
-
-    if (!ref($user)) {
-        my $user_object = RT::Model::User->new;
-        $user_object->load($user);
-        $user = $user_object;
-    }
-
-    my $style = RT->config->get('username_format', Jifty->web->current_user);
-    return $self->_render_user_concise($user)
-        if $style eq 'concise';
-    return $self->_render_user_verbose($user);
-}
-
-sub _render_user_concise {
-    my $self = shift;
-    my $user = shift;
-
-    if ($user->privileged) {
-        return $user->real_name
-            || $user->nickname
-            || $user->name
-            || $user->email;
-    }
-
-    return $user->email
-        || $user->name
-        || $user->real_name
-        || $user->nickname;
-}
-
-sub _render_user_verbose {
-    my $self = shift;
-    my $user = shift;
-
-    my ($phrase, $comment);
-    my $addr = $user->email;
-
-    $phrase = $user->real_name
-        if $user->real_name
-        && lc $user->real_name ne lc $addr;
-
-    $comment = $user->name
-        if lc $user->name ne lc $addr;
-
-    $comment = "($comment)"
-        if defined $comment and length $comment;
-
-    my $address = Email::Address->new($phrase, $addr, $comment);
-
-    $address->comment('')
-        if $comment && lc $address->user eq lc $comment;
-
-    if ( $phrase and my ($l, $r) = ($phrase =~ /^(\w+) (\w+)$/) ) {
-        $address->phrase('')
-            if $address->user =~ /^\Q$l\E.\Q$r\E$/
-            || $address->user =~ /^\Q$r\E.\Q$l\E$/;
-    }
-
-    return $address->format;
-}
+use RT::View::Helpers qw/render_user/;
 
 sub _render_select_values {
     my $self = shift;
@@ -85,7 +22,7 @@ sub _render_select_values {
                   : $current_value eq $value );
         $rendered .= qq!>!;
 
-        $rendered .= $self->_render_user($value);
+        $rendered .= render_user($value);
 
         $rendered .= qq!</option>\n!;
     }
@@ -100,7 +37,7 @@ sub render_value {
     my $value = $self->current_value;
     if(defined $value) {
         my @value = grep { $_->{value} eq $value } $self->available_values;
-        $value = $self->_render_user($value[0]->{value}) if scalar @value;
+        $value = render_user($value[0]->{value}) if scalar @value;
     }
     $field .= Jifty->web->escape(_($value)) if defined $value;
     $field .= qq!</span>\n!;
diff --git a/lib/RT/View/Helpers.pm b/lib/RT/View/Helpers.pm
new file mode 100644
index 0000000..28e53f3
--- /dev/null
+++ b/lib/RT/View/Helpers.pm
@@ -0,0 +1,118 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+#                                          <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/copyleft/gpl.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+use warnings;
+use strict;
+
+package RT::View::Helpers;
+use base qw/Exporter/;
+our @EXPORT    = ();
+our @EXPORT_OK = qw(render_user render_user_concise render_user_verbose);
+
+sub render_user {
+    my $user = shift;
+
+    if (!ref($user)) {
+        my $user_object = RT::Model::User->new;
+        $user_object->load($user);
+        $user = $user_object;
+    }
+
+    my $style = RT->config->get('username_format', Jifty->web->current_user);
+    return render_user_concise($user)
+        if $style eq 'concise';
+    return render_user_verbose($user);
+}
+
+sub render_user_concise {
+    my $user = shift;
+
+    if ($user->privileged) {
+        return $user->real_name
+            || $user->nickname
+            || $user->name
+            || $user->email;
+    }
+
+    return $user->email
+        || $user->name
+        || $user->real_name
+        || $user->nickname;
+}
+
+sub render_user_verbose {
+    my $user = shift;
+
+    my ($phrase, $comment);
+    my $addr = $user->email;
+
+    $phrase = $user->real_name
+        if $user->real_name
+        && lc $user->real_name ne lc $addr;
+
+    $comment = $user->name
+        if lc $user->name ne lc $addr;
+
+    $comment = "($comment)"
+        if defined $comment and length $comment;
+
+    my $address = Email::Address->new($phrase, $addr, $comment);
+
+    $address->comment('')
+        if $comment && lc $address->user eq lc $comment;
+
+    if ( $phrase and my ($l, $r) = ($phrase =~ /^(\w+) (\w+)$/) ) {
+        $address->phrase('')
+            if $address->user =~ /^\Q$l\E.\Q$r\E$/
+            || $address->user =~ /^\Q$r\E.\Q$l\E$/;
+    }
+
+    return $address->format;
+}
+
+1;
+

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


More information about the Rt-commit mailing list