Changeset 1002 for trunk


Ignore:
Timestamp:
05/19/12 11:38:41 (12 years ago)
Author:
nanardon
Message:
  • fix attributes object return in some, simplify code
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm

    r959 r1002  
    474474    my ($self, $attr, $type) = @_; 
    475475 
    476     my $attribute = ($type 
    477         ? ref $type 
    478             ? $self->base->attribute( 
     476    my $attribute; 
     477    if ($type) { 
     478        if (ref $type) { 
     479            $attribute = $self->base->attribute( 
    479480                $self->otype, 
    480                 { %$type, name => $attr },) 
    481             : $self->base->attribute( 
     481                { %$type, name => $attr }, 
     482            ); 
     483        } else { 
     484            $attribute =  $self->base->attribute( 
    482485                $self->otype, 
    483                 { formtype => $type , name => $attr },) 
    484         : ($self->{object} 
    485             ? $self->{object}->attribute($attr) 
    486             : $self->base->attribute($self->otype, $attr, { formtype => $type }))) 
    487         || $self->base->attribute($self->otype, { name => $attr }); 
     486                { formtype => $type , name => $attr }, 
     487            ); 
     488        } 
     489    } else { 
     490        if ($self->{object}) { 
     491            $attribute = $self->{object}->attribute($attr); 
     492        } else { 
     493            $attribute = $self->base->attribute( 
     494                $self->otype, $attr, 
     495                { formtype => $type } 
     496            ); 
     497        } 
     498    } 
     499    $attribute ||= $self->base->attribute($self->otype, { name => $attr }); 
    488500 
    489501 
     
    494506    # Force Array context: 
    495507    my @attr_raw_value = (); 
     508 
    496509    if ($attribute->multiple) { 
    497510        @attr_raw_value = grep { $_ } $self->attr_raw_value($attribute); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r959 r1002  
    418418sub attribute { 
    419419    my ($self, $otype, $attribute) = @_; 
     420 
     421    my $attrinfo; 
     422    if (!ref $attribute) { 
     423       $attrinfo = $self->get_attr_schema($otype, $attribute) 
     424            or return; 
     425        $attrinfo->{name} = $attribute; 
     426    } else { 
     427        $attrinfo = $attribute; 
     428    } 
     429 
    420430    return LATMOS::Accounts::Bases::Attributes->new( 
    421         $attribute, 
     431        $attrinfo, 
    422432        $self, 
    423433        $otype, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r965 r1002  
    132132sub attribute { 
    133133    my ($self, $attribute) = @_; 
     134 
     135    my $attrinfo; 
     136    if (! ref $attribute) { 
     137        $attrinfo = $self->base->get_attr_schema( 
     138            $self->type, $attribute 
     139        ) or return; 
     140        $attrinfo->{name} = $attribute; 
     141    } else { 
     142        $attrinfo = $attribute; 
     143    } 
     144 
    134145    return LATMOS::Accounts::Bases::Attributes->new( 
    135         $attribute, 
     146        $attrinfo, 
    136147        $self, 
    137148    ); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/DataRequest.pm

    r990 r1002  
    505505    } else { 
    506506        my $obj = $self->oobject; 
    507         return $obj 
     507        my $oo = $obj 
    508508            ? $obj->attribute($attrname) 
    509509            : $self->base->attribute($self->otype, $attrname); 
     510        return $oo || $self->base->attribute($self->otype, { name => $attrname }); 
    510511    } 
    511512} 
Note: See TracChangeset for help on using the changeset viewer.