[Rt-commit] rt branch, admin_ui, updated. 799eb8e818d9c8aba8ffce3651d9510a3f1de656

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Jan 4 03:09:24 EST 2010


The branch, admin_ui has been updated
       via  799eb8e818d9c8aba8ffce3651d9510a3f1de656 (commit)
      from  ac7129f851bc5bdf6fdbf81ec05d4352e3876ec4 (commit)

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

- Log -----------------------------------------------------------------
commit 799eb8e818d9c8aba8ffce3651d9510a3f1de656
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Jan 4 16:09:07 2010 +0800

    UpdateCustomField action

diff --git a/lib/RT/Action/UpdateCustomField.pm b/lib/RT/Action/UpdateCustomField.pm
new file mode 100644
index 0000000..fa03ca3
--- /dev/null
+++ b/lib/RT/Action/UpdateCustomField.pm
@@ -0,0 +1,96 @@
+package RT::Action::UpdateCustomField;
+use strict;
+use warnings;
+
+use base qw/Jifty::Action::Record::Update/;
+
+sub record_class { 'RT::Model::CustomField' }
+
+use constant report_detailed_messages => 1;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+    my $self = shift;
+    param 'link_value_to' => hints is _(
+q{RT can make this custom field's values into hyperlinks to another service.
+Fill in this field with a URL.
+RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record
+id and custom field value, respectively}
+    );
+    param 'include_content_for_value' => hints is _(
+q{RT can include content from another web service when showing this custom field.
+Fill in this field with a URL.
+RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively
+Some browsers may only load content from the same domain as your RT server.}
+    );
+
+};
+
+sub arguments {
+    my $self = shift;
+    my $args = $self->SUPER::arguments;
+
+    if ( $self->has_values_sources ) {
+        $args->{values_class} = {
+            render_as     => 'Select',
+            default_value => defer {
+                return $self->record->values_class;
+            },
+            available_values => defer {
+                my @values;
+                for my $class ( 'RT::Model::CustomFieldValueCollection',
+                    @{ RT->config->get('custom_field_values_sources') } )
+                {
+                    next unless $class;
+                    local $@;
+                    eval "require $class";
+                    if ($@) {
+                        Jifty->log->fatal("Couldn't load class '$class': $@");
+                        next;
+                    }
+                    my %res = ( value => $class );
+                    $res{'display'} = $class->source_description
+                      if $class->can('source_description');
+                    if ( $class eq 'RT::Model::CustomFieldValueCollection' ) {
+                        $res{'display'} = 'Provide list of values below';
+                    }
+                    else {
+                        $res{'display'} ||= $class;
+                    }
+                    push @values, \%res;
+                }
+                return \@values;
+            },
+        };
+    }
+    return $args;
+}
+
+sub take_action {
+    my $self = shift;
+    $self->SUPER::take_action;
+
+    my @attrs = qw/link_value_to include_content_for_value/;
+    push @attrs, 'values_class' if $self->has_values_sources;
+
+    for my $attr (@attrs) {
+        if ( $self->has_argument($attr) ) {
+            my $method = "set_$attr";
+            my ( $status, $msg ) =
+              $self->record->$method( $self->argument_value($attr) );
+            Jifty->log->error($msg) unless $status;
+        }
+    }
+    return 1;
+}
+
+sub has_values_sources {
+    my $self = shift;
+    return
+         $self->record->id
+      && $self->record->is_selection_type
+      && RT->config->get('custom_field_values_sources')
+      && ( scalar( @{ RT->config->get('custom_field_values_sources') } ) > 0 );
+}
+
+1;

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


More information about the Rt-commit mailing list