[Rt-commit] rt branch, 4.2/cf-input-name-sub, repushed

? sunnavy sunnavy at bestpractical.com
Sat Jan 4 21:05:55 EST 2014


The branch 4.2/cf-input-name-sub was deleted and repushed:
       was 573fbee7aeedf4edadbf82b9433418af951a5e65
       now 054d24f196b724b22af37becf333ade52bdf821f

1:  573fbee ! 1:  054d24f refactor cf input name and abstract a sub to get it
    @@ -43,39 +43,81 @@
     +        @_,
     +    );
     +
    -+    my $name = join '-', 'Object', ref( $args{Object} ) || $args{CustomField}->ObjectTypeFromLookupType,
    -+        ( $args{Object} && $args{Object}->id ? $args{Object}->id : '' ),
    -+        'CustomField' . ( $args{Grouping} ? ":$args{Grouping}" : '' ), $args{CustomField}->id;
    ++    my $name = GetCustomFieldInputNamePrefix(%args);
     +
     +    if ( $args{CustomField}->Type eq 'Select' ) {
     +        if ( $args{CustomField}->RenderType eq 'List' ) {
    -+            $name .= '-Value';
    ++            $name .= 'Value';
     +        }
     +        else {
    -+            $name .= '-Values';
    ++            $name .= 'Values';
     +        }
     +    }
     +    elsif ( $args{CustomField}->Type =~ /^(?:Binary|Image)$/ ) {
    -+        $name .= '-Upload';
    ++        $name .= 'Upload';
     +    }
     +    elsif ( $args{CustomField}->Type =~ /^(?:Date|DateTime|Text|Wikitext)$/ ) {
    -+        $name .= '-Values';
    ++        $name .= 'Values';
     +    }
     +    else {
     +        if ( $args{CustomField}->SingleValue ) {
    -+            $name .= '-Value';
    ++            $name .= 'Value';
     +        }
     +        else {
    -+            $name .= '-Values';
    ++            $name .= 'Values';
     +        }
     +    }
     +
     +    return $name;
     +}
     +
    ++=head2 GetCustomFieldInputNamePrefix(CustomField => $cf_object, Object => $object, Grouping => $grouping_name)
    ++
    ++Returns the standard custom field input name prefix(without "Value" or alike suffix)
    ++
    ++=cut
    ++
    ++sub GetCustomFieldInputNamePrefix {
    ++    my %args = (
    ++        CustomField => undef,
    ++        Object      => undef,
    ++        Grouping    => undef,
    ++        @_,
    ++    );
    ++
    ++    my $prefix = join '-', 'Object', ref( $args{Object} ) || $args{CustomField}->ObjectTypeFromLookupType,
    ++        ( $args{Object} && $args{Object}->id ? $args{Object}->id : '' ),
    ++        'CustomField' . ( $args{Grouping} ? ":$args{Grouping}" : '' ),
    ++        $args{CustomField}->id, '';
    ++
    ++    return $prefix;
    ++}
    ++
      package HTML::Mason::Commands;
      
      use vars qw/$r $m %session/;
    +@@
    +                 }
    +                 push @results,
    +                     _ProcessObjectCustomFieldUpdates(
    +-                    # XXX FIXME: Prefix is not quite right, as $id almost
    +-                    # certainly started as blank for new objects and is now 0.
    +-                    # Only Image/Binary CFs on new objects should be affected.
    +-                    Prefix      => "Object-$class-$id-CustomField-$cf-",
    +-                    Object      => $Object,
    +-                    CustomField => $CustomFieldObj,
    +-                    ARGS        => $custom_fields_to_mod{$class}{$id}{$cf}{$groupings[0]},
    ++                        Prefix => GetCustomFieldInputNamePrefix(
    ++                            Object      => $Object,
    ++                            CustomField => $CustomFieldObj,
    ++                            Grouping    => $groupings[0],
    ++                        ),
    ++                        Object      => $Object,
    ++                        CustomField => $CustomFieldObj,
    ++                        ARGS        => $custom_fields_to_mod{$class}{$id}{$cf}{ $groupings[0] },
    +                     );
    +             }
    +         }
     @@
          foreach my $arg ( keys %$ARGSRef ) {
      
    @@ -89,7 +131,7 @@
          if (   defined $args{'ARGS'}->{'Values'}
              && !length $args{'ARGS'}->{'Values'}
     -        && $args{'ARGS'}->{'Values-Magic'} )
    -+        && ($args{'ARGS'}->{'Values-Magic'} || $args{'ARGS'}->{'Value-Magic'}) || $args{'ARGS'}->{'Upload-Magic'})
    ++        && ($args{'ARGS'}->{'Values-Magic'}) )
          {
              delete $args{'ARGS'}->{'Values'};
          }
    @@ -103,20 +145,41 @@
                  # We don't care about the magic, if there's really a values element;
                  next if defined $args{'ARGS'}->{'Value'}  && length $args{'ARGS'}->{'Value'};
     @@
    +             }
    + 
    +             my @values;
    ++            my $name_prefix = GetCustomFieldInputNamePrefix(
    ++                CustomField => $cf,
    ++                Grouping    => $groupings[0],
    ++            );
                  while (my ($arg, $value) = each %{ $custom_fields{$class}{0}{$cfid}{$groupings[0]} }) {
                      # Values-Magic doesn't matter on create; no previous values are being removed
                      # Category is irrelevant for the actual value
     -                next if $arg eq "Values-Magic" or $arg eq "Category";
     +                next if $arg =~ /-Magic$/ or $arg eq "Category";
      
    -                 push @values, _NormalizeObjectCustomFieldValue(
    +-                push @values, _NormalizeObjectCustomFieldValue(
    ++                push @values,
    ++                    _NormalizeObjectCustomFieldValue(
                          CustomField => $cf,
    +-                    Param       => "Object-$class--CustomField-$cfid-$arg",
    ++                    Param       => $name_prefix . $arg,
    +                     Value       => $value,
    +-                );
    ++                    );
    +             }
    + 
    +             $parsed{"CustomField-$cfid"} = \@values if @values;
     @@
          return $value;
      }
      
     +sub GetCustomFieldInputName {
     +    RT::Interface::Web::GetCustomFieldInputName(@_);
    ++}
    ++
    ++sub GetCustomFieldInputNamePrefix {
    ++    RT::Interface::Web::GetCustomFieldInputNamePrefix(@_);
     +}
     +
      package RT::Interface::Web;



More information about the rt-commit mailing list