Ignore:
Timestamp:
05/15/12 03:30:21 (12 years ago)
Author:
nanardon
Message:
  • merge all work around forms
File:
1 edited

Legend:

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

    r955 r959  
    216216 
    217217sub attr_label { 
    218     my ($self, $attr) = @_; 
    219     my ($hint, $label) = ('', ''); 
     218    my ($self, $attr, $label, $hint) = @_; 
     219    $label ||= ''; 
     220    $hint ||= ''; 
    220221    LATMOS::Accounts::Web->config->{attrs} ||= {}; 
    221     my $htmlname = ($self->{object} ? $self->{object}->id . '_' : '') . $attr; 
     222    my $attribute = $self->base->attribute($self->otype, $attr); 
     223    my $htmlname = $self->escape($self->attr_field_name($attr)); 
    222224    if (my $attr_config = LATMOS::Accounts::Web->config->{attrs}{$attr}) { 
    223         $label = $attr_config->{label} || ''; 
     225        $label ||= $attr_config->{label} || ''; 
    224226        #utf8::is_utf8($label) && utf8::encode($label); 
    225         $hint = $attr_config->{hint} || ''; 
     227        $hint ||= $attr_config->{hint} || ''; 
    226228        #utf8::is_utf8($hint) && utf8::encode($hint); 
    227229    } 
     
    243245 
    244246sub attr_raw_value { 
    245     my ($self, $attr) = @_; 
    246     return $self->{c}->req->param($attr) || 
    247         ($self->{object} ? $self->{object}->get_attributes($attr) : '') 
     247    my ($self, $attribute) = @_; 
     248    my @val = grep { $_ }   
     249        ($self->{c}->req->param($attribute->name)) 
     250        || ($self->{object} 
     251            ? ($self->{object}->get_attributes($attribute->name)) 
     252            : ()); 
     253 
     254    if (@val) { 
     255        return @val; 
     256    } else { 
     257        return (grep { $_ } ($attribute->default_value)) 
     258    } 
    248259} 
    249260 
     
    251262    my ($self, $attr) = @_; 
    252263    my $id = $self->{object} 
    253         ? $self->{object}->id . '_' 
     264        ? ($self->{object}->id || '') 
    254265        : ''; 
     266    $id .= '_' if ($id); 
    255267    $id =~ s/\./_/g; 
    256268    $id =~ s/-/_/g; 
     
    403415                last; 
    404416            }; 
    405  
    406             warn $_; 
    407417        } 
    408418    return ''; 
     
    450460                    frequency => 1, 
    451461                    with => "'val='+element.value" . 
    452                     ($self->{object} ? "+'&exclude=" . $self->{object}->id . "'" : 
    453                         ''), 
     462                    ($self->{object} ? 
     463                        "+'&exclude=" . ($self->{object}->id || '') . "'"  
     464                        : ''), 
    454465                } 
    455466            ) 
     
    463474    my ($self, $attr, $type) = @_; 
    464475 
    465     my $attr_info = $type 
    466         ? { formtype => $type } 
    467         : undef; 
    468  
    469     my $attribute = ($self->{object} 
    470         ? $self->{object}->attribute($attr) 
    471         : $self->base->attribute($self->otype, $attr)); 
    472  
    473     $attribute ||= $self->base->attribute( 
    474         $self->otype, 
    475         {  
    476             name => $attr, 
    477             formtype => $type 
    478         }, 
    479     ); 
     476    my $attribute = ($type 
     477        ? ref $type 
     478            ? $self->base->attribute( 
     479                $self->otype, 
     480                { %$type, name => $attr },) 
     481            : $self->base->attribute( 
     482                $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 }); 
     488 
    480489 
    481490    my $htmlname = $self->escape($self->attr_field_name($attr)); 
    482491 
    483492    my @html_fields; 
    484     foreach my $attr_raw_value ( 
    485         $attribute->multiple 
    486             ? (grep { $_ } $self->attr_raw_value($attr)) 
    487             : $self->attr_raw_value($attr) || '') { 
     493 
     494    # Force Array context: 
     495    my @attr_raw_value = (); 
     496    if ($attribute->multiple) { 
     497        @attr_raw_value = grep { $_ } $self->attr_raw_value($attribute); 
     498    } else { 
     499        my ($val) = $self->attr_raw_value($attribute); 
     500        @attr_raw_value = ($val || ''); 
     501    } 
     502 
     503    foreach my $attr_raw_value (@attr_raw_value) { 
    488504 
    489505        my $html_id = $htmlname . 
     
    501517    } 
    502518 
    503     if ($attribute->{multiple}) { 
     519    if ($attribute->{multiple} && !$attribute->readonly) { 
    504520        my $html_id = $htmlname . '_m_SUBID'; 
    505521 
Note: See TracChangeset for help on using the changeset viewer.