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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Dec 14 00:28:14 EST 2009


The branch, admin_ui has been updated
       via  e27a55d6c642d4bbe97b27288dc0834405d17b00 (commit)
      from  eeb5ed05d85aaac63c8892df9567d00980cc8b94 (commit)

Summary of changes:
 lib/RT/Action/ConfigMyRT.pm |  138 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 138 insertions(+), 0 deletions(-)
 create mode 100644 lib/RT/Action/ConfigMyRT.pm

- Log -----------------------------------------------------------------
commit e27a55d6c642d4bbe97b27288dc0834405d17b00
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Dec 14 13:25:02 2009 +0800

    add ConfigMyRT action

diff --git a/lib/RT/Action/ConfigMyRT.pm b/lib/RT/Action/ConfigMyRT.pm
new file mode 100644
index 0000000..7d5765a
--- /dev/null
+++ b/lib/RT/Action/ConfigMyRT.pm
@@ -0,0 +1,138 @@
+use strict;
+use warnings;
+
+package RT::Action::ConfigMyRT;
+use base qw/RT::Action Jifty::Action/;
+use RT::View::Helpers qw/render_user/;
+use Scalar::Defer;
+
+__PACKAGE__->mk_accessors('object');
+
+
+sub arguments {
+    my $self = shift;
+    return {} unless $self->object;
+
+    my $args = {};
+    $args->{object_id} = {
+        render_as     => 'hidden',
+        default_value => $self->object->id,
+    };
+    $args->{object_type} = {
+        render_as     => 'hidden',
+        default_value => ref $self->object,
+    };
+
+    for my $type ( qw/body summary/ ) {
+        $args->{$type} = {
+            available_values => defer { $self->available_values },
+            default_value => defer { $self->default_value( $type ) },
+            render_as => 'Checkboxes',
+        }
+    }
+    return $args;
+}
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+    my $self = shift;
+    my $object_type = $self->argument_value('object_type');
+    return unless $object_type;
+    if ( $object_type eq 'RT::System' ) {
+        $self->object( RT->system );
+    }
+    elsif ( $RT::Model::ACE::OBJECT_TYPES{$object_type} ) {
+        my $object = $object_type->new;
+        my $object_id = $self->argument_value('object_id');
+        $object->load($object_id);
+        unless ( $object->id ) {
+            Jifty->log->error("couldn't load $object_type #$object_id");
+            return;
+        }
+
+        $self->object($object);
+    }
+    else {
+        Jifty->log->error("object type '$object_type' is incorrect");
+        return;
+    }
+
+    my $content = $self->default_value || {};
+    for my $arg ( $self->argument_names ) {
+        next unless ( $arg =~ /^body|summary$/ );
+        my $value = $self->argument_value($arg);
+
+        my @panes;
+        if ( UNIVERSAL::isa( $self->argument_value($arg), 'ARRAY' ) ) {
+            @panes = @$value;
+        }
+        else {
+            @panes = $value;
+        }
+
+        @panes =
+          map { /(\w+)-(.*)/ ? { type => $1, name => $2 } : () }
+          grep { $_ } @panes;
+        $content->{$arg} = \@panes;
+    }
+
+    my ( $settings ) = $self->object->attributes->named('HomepageSettings');
+	$settings->set_content( $content );
+    $self->report_success;
+    return 1;
+}
+
+sub available_values {
+    my $self = shift;
+
+    my @items =
+      map { { value => "component-$_", display => $_ } }
+      sort @{ RT->config->get('homepage_components') };
+    my $sys = RT->system;
+    for ( $sys->saved_searches ) {
+        my ( $desc, $search ) = @$_;
+        my $SearchType = $search->content->{'SearchType'} || 'Ticket';
+        if ( $SearchType eq 'Ticket' ) {
+            push @items, { value => "system-$desc", display => $desc };
+        }
+        else {
+            my $oid =
+              ref($sys) . '-' . $sys->id . '-SavedSearch-' . $search->id;
+            my $type =
+              ( $SearchType eq 'Ticket' ) ? _('Saved Search') : $SearchType;
+            push @items, { value => "saved-$oid", display => _($type) . ": $desc" };
+        }
+    }
+    return \@items;
+}
+
+sub default_value {
+    my $self     = shift;
+    my $type     = shift;
+    my ( $settings ) = $self->object->attributes->named('HomepageSettings');
+    my $content  = $settings->content;
+    return $content unless $type;
+
+    return unless $content && $content->{$type};
+
+    my $values = $content->{$type} || [];
+    return [ map { join '-', $_->{type}, $_->{name} } @$values ];
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+    my $self = shift;
+
+    # Your success message here
+    $self->result->message('Success');
+}
+
+
+1;
+

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


More information about the Rt-commit mailing list