[Rt-commit] r20060 - rtir/2.5/trunk/html/RTIR/Elements

ruz at bestpractical.com ruz at bestpractical.com
Fri Jun 26 14:25:42 EDT 2009


Author: ruz
Date: Fri Jun 26 14:25:42 2009
New Revision: 20060

Modified:
   rtir/2.5/trunk/html/RTIR/Elements/EditCustomFields

Log:
* refactor defaults for custom fields
** implement defaulting for all CFs on create with linking
** behave more consisten and describable

Modified: rtir/2.5/trunk/html/RTIR/Elements/EditCustomFields
==============================================================================
--- rtir/2.5/trunk/html/RTIR/Elements/EditCustomFields	(original)
+++ rtir/2.5/trunk/html/RTIR/Elements/EditCustomFields	Fri Jun 26 14:25:42 2009
@@ -35,38 +35,35 @@
     my $CustomFields = $QueueObj->TicketCustomFields();
     my %Defaults = RT->Config->Get('RTIR_CustomFieldsDefaults');
     while ( my $CustomField = $CustomFields->Next ) {
-        if ( $CustomField->Name eq 'SLA' ) {
-            $ARGS{"CustomField-".$CustomField->Id} = RT::IR::DefaultSLA();
-        }
-        elsif ( $CustomField->Name eq 'IP' ) {
-            if ( $ARGS{"IP-Value"} ) {
-                $ARGS{"CustomField-".$CustomField->Id} = $ARGS{"IP-Value"};
-            }
-            elsif ( $ChildObj || $IncidentObj ) {
-                my $Obj = $ChildObj || $IncidentObj;
+        my $name = $CustomField->Name;
+
+        if ( $ChildObj || $IncidentObj ) {
+            my $linking_to = $ChildObj || $IncidentObj;
+            my ($link_cf) = RT::IR->CustomFields( Field => $name, Ticket => $linking_to );
+            if ( $link_cf ) {
+# XXX: if CF can have only one value then we should use only first value
                 $ARGS{"CustomField-".$CustomField->Id} = join "\n",
-                    grep $_, map $_->Content,
-                    @{ $Obj->CustomFieldValues( 'IP' )->ItemsArrayRef };
-            }
-            elsif ( $Defaults{IP} ) {
-                if ( ref $Defaults{IP} eq 'ARRAY' ) {
-                    $ARGS{"CustomField-".$CustomField->Id} =
-                        join "\n", @{$Defaults{IP}};
-                }
-                else {
-                    $ARGS{"CustomField-".$CustomField->Id} = $Defaults{IP};
-                }
+                    grep defined && length, map $_->Content,
+                    @{ $linking_to->CustomFieldValues( $link_cf->id )->ItemsArrayRef };
+                next;
             }
         }
-        else {
-            my $Name = $CustomField->Name;
-            if ( $ARGS{"$Name-Value"} ) {
-                $ARGS{"CustomField-".$CustomField->Id} = $ARGS{"$Name-Value"};
-            }
-            elsif ( $Defaults{$Name} && !ref $Defaults{$Name} ) {
-# if $Defaults{$Name} is ref, it should be treated carefully, like the 'SLA'
+        
+        if ( $ARGS{"$name-Value"} ) {
+            $ARGS{"CustomField-".$CustomField->Id} = $ARGS{"$name-Value"};
+        }
+        elsif ( $name eq 'SLA' ) {
+            $ARGS{"CustomField-".$CustomField->Id} = RT::IR::DefaultSLA();
+        }
+        elsif ( defined $Defaults{ $name } ) {
+# if $Defaults{$name} is ref, it should be treated carefully, like the 'SLA'
 # above
-                $ARGS{"CustomField-".$CustomField->Id} = $Defaults{$Name};
+            unless ( ref $Defaults{ $name } ) {
+                $ARGS{"CustomField-".$CustomField->Id} = $Defaults{ $name };
+            }
+            elsif ( ref $Defaults{ $name } eq 'ARRAY' ) {
+                $ARGS{"CustomField-".$CustomField->id} =
+                    join "\n", @{$Defaults{ $name }};
             }
         }
     }


More information about the Rt-commit mailing list