[Rt-commit] rt branch, admin_ui, updated. 45014cd2ab702f595edb4f7a1b4cfc7b8c9eb677

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Feb 1 01:56:18 EST 2010


The branch, admin_ui has been updated
       via  45014cd2ab702f595edb4f7a1b4cfc7b8c9eb677 (commit)
       via  e924adcf45721421a214967657973dd32c9c2763 (commit)
       via  fa8a205785440dc7e0b8ffdd1b5fb3d718d1c7a5 (commit)
      from  878c539ea4ccfd701ca5a1557f0f628690137611 (commit)

Summary of changes:
 lib/RT/Action/CreateGroup.pm      |    2 +-
 lib/RT/Action/CreateQueue.pm      |    2 +-
 lib/RT/Action/CreateUser.pm       |    2 +-
 lib/RT/Action/UpdateGroup.pm      |    2 +-
 lib/RT/Action/UpdateQueue.pm      |    2 +-
 lib/RT/Action/UpdateUser.pm       |    2 +-
 lib/RT/Action/WithCustomFields.pm |   39 ++++++++++++++++++++++++++++++++----
 lib/RT/Model/CustomField.pm       |   14 ++++++++++--
 8 files changed, 51 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit fa8a205785440dc7e0b8ffdd1b5fb3d718d1c7a5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Feb 1 14:38:38 2010 +0800

    cf type_map tweak

diff --git a/lib/RT/Model/CustomField.pm b/lib/RT/Model/CustomField.pm
index b0a5937..f194fd0 100755
--- a/lib/RT/Model/CustomField.pm
+++ b/lib/RT/Model/CustomField.pm
@@ -1152,13 +1152,21 @@ sub type_for_rendering {
 
     my %type_map = (
         Select       => 'Select',
-        Freeform     => 'Text',
         Text         => 'Textarea',
         Wikitext     => '',
-        Image        => '',
-        Binary       => 'Upload',
         Combobox     => '',
         Autocomplete => '',
+        $self->max_values && $self->max_values == 1
+          ? (
+            Image    => 'Upload',
+            Binary   => 'Upload',
+            Freeform => 'Text',
+          )
+          : (
+            Image    => 'Uploads',
+            Binary   => 'Uploads',
+            Freeform => 'Textarea',
+          ),
     );
 
     return $type_map{$type};

commit e924adcf45721421a214967657973dd32c9c2763
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Feb 1 14:46:34 2010 +0800

    tweak _add_custom_field_value

diff --git a/lib/RT/Action/WithCustomFields.pm b/lib/RT/Action/WithCustomFields.pm
index 9e2321a..3c796ca 100644
--- a/lib/RT/Action/WithCustomFields.pm
+++ b/lib/RT/Action/WithCustomFields.pm
@@ -59,8 +59,14 @@ sub _setup_custom_field {
                     $args{default_value} = $ocfvs->first->content;
                 }
                 else {
-                    $args{default_value} =
-                      [ map { $_->content } @{ $ocfvs->items_array_ref } ];
+                    if ( $cf->type eq 'Freeform' ) {
+                        $args{default_value} = join "\n",
+                          map { $_->content } @{ $ocfvs->items_array_ref };
+                    }
+                    else {
+                        $args{default_value} =
+                          [ map { $_->content } @{ $ocfvs->items_array_ref } ];
+                    }
                 }
 
             }
@@ -111,7 +117,30 @@ sub _add_custom_field_value {
     my $field = $args{field};
     my $value = $args{value};
 
+    my $cf = RT::Model::CustomField->new;
+    my ( $status, $msg ) = $cf->load($field);
+    unless ( $status ) {
+        Jifty->log->error( $msg );
+        return;
+    }
+
     my @values = ref $value eq 'ARRAY' ? @$value : $value;
+    if ( $cf->type eq 'Freeform' ) {
+
+        @values = map { s!^\s+!!; s!\s+$!!; $_ } grep { /\S/ } split "\n",
+          join "\n",
+          @values;
+    }
+
+    my $ocfvs = $self->record->custom_field_values($field);
+    while ( my $v = $ocfvs->next ) {
+        my ( $status, $msg ) = $self->record->delete_custom_field_value(
+            field    => $field,
+            value_id => $v->id,
+        );
+        Jifty->log->error( $msg ) unless $status;
+    }
+
     for my $value (@values) {
         if ( UNIVERSAL::isa( $value, 'Jifty::Web::FileUpload' ) ) {
             $self->record->add_custom_field_value(

commit 45014cd2ab702f595edb4f7a1b4cfc7b8c9eb677
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Feb 1 14:51:55 2010 +0800

    name tweak

diff --git a/lib/RT/Action/CreateGroup.pm b/lib/RT/Action/CreateGroup.pm
index 4974226..40ab303 100644
--- a/lib/RT/Action/CreateGroup.pm
+++ b/lib/RT/Action/CreateGroup.pm
@@ -33,7 +33,7 @@ sub arguments {
 sub take_action {
     my $self = shift;
     $self->SUPER::take_action;
-    $self->_add_custom_field_values;
+    $self->_update_custom_field_values;
     if ( $self->has_argument('disabled') ) {
         my ( $status, $msg ) =
           $self->record->set_disabled( $self->argument_value('disabled') );
diff --git a/lib/RT/Action/CreateQueue.pm b/lib/RT/Action/CreateQueue.pm
index 92c1df9..781d5c6 100644
--- a/lib/RT/Action/CreateQueue.pm
+++ b/lib/RT/Action/CreateQueue.pm
@@ -35,7 +35,7 @@ sub arguments {
 sub take_action {
     my $self = shift;
     $self->SUPER::take_action;
-    $self->_add_custom_field_values;
+    $self->_update_custom_field_values;
     return 1;
 }
 
diff --git a/lib/RT/Action/CreateUser.pm b/lib/RT/Action/CreateUser.pm
index 441903b..78512c6 100644
--- a/lib/RT/Action/CreateUser.pm
+++ b/lib/RT/Action/CreateUser.pm
@@ -35,7 +35,7 @@ sub arguments {
 sub take_action {
     my $self = shift;
     $self->SUPER::take_action;
-    $self->_add_custom_field_values;
+    $self->_update_custom_field_values;
 
     for my $field (qw/disabled privileged/) {
         next
diff --git a/lib/RT/Action/UpdateGroup.pm b/lib/RT/Action/UpdateGroup.pm
index 17fb94c..a88f363 100644
--- a/lib/RT/Action/UpdateGroup.pm
+++ b/lib/RT/Action/UpdateGroup.pm
@@ -33,7 +33,7 @@ sub arguments {
 sub take_action {
     my $self = shift;
     $self->SUPER::take_action;
-    $self->_add_custom_field_values;
+    $self->_update_custom_field_values;
     if ( $self->has_argument('disabled') ) {
         my ( $status, $msg ) =
           $self->record->set_disabled( $self->argument_value('disabled') );
diff --git a/lib/RT/Action/UpdateQueue.pm b/lib/RT/Action/UpdateQueue.pm
index 827fe93..315a346 100644
--- a/lib/RT/Action/UpdateQueue.pm
+++ b/lib/RT/Action/UpdateQueue.pm
@@ -38,7 +38,7 @@ sub arguments {
 sub take_action {
     my $self = shift;
     $self->SUPER::take_action;
-    $self->_add_custom_field_values;
+    $self->_update_custom_field_values;
     return 1;
 }
 
diff --git a/lib/RT/Action/UpdateUser.pm b/lib/RT/Action/UpdateUser.pm
index 6b97b92..213e445 100644
--- a/lib/RT/Action/UpdateUser.pm
+++ b/lib/RT/Action/UpdateUser.pm
@@ -35,7 +35,7 @@ sub arguments {
 sub take_action {
     my $self = shift;
     $self->SUPER::take_action;
-    $self->_add_custom_field_values;
+    $self->_update_custom_field_values;
     for my $field (qw/disabled privileged/) {
         next
           if ( $self->record->$field && $self->argument_value($field) )
diff --git a/lib/RT/Action/WithCustomFields.pm b/lib/RT/Action/WithCustomFields.pm
index 3c796ca..0529ce4 100644
--- a/lib/RT/Action/WithCustomFields.pm
+++ b/lib/RT/Action/WithCustomFields.pm
@@ -96,14 +96,14 @@ sub _setup_custom_field {
     return \%args;
 }
 
-sub _add_custom_field_values {
+sub _update_custom_field_values {
     my $self = shift;
 
     my @args = grep { /^cf_\d+$/ } $self->argument_names;
     for my $arg (@args) {
         my $id;
         $id = $1 if $arg =~ /^cf_(\d+)$/;    # this always happens
-        $self->_add_custom_field_value(
+        $self->_update_custom_field_value(
             field => $1,
             value => $self->argument_value($arg),
         );
@@ -111,7 +111,7 @@ sub _add_custom_field_values {
     }
 }
 
-sub _add_custom_field_value {
+sub _update_custom_field_value {
     my $self  = shift;
     my %args  = @_;
     my $field = $args{field};

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


More information about the Rt-commit mailing list