- Timestamp:
- 05/15/12 03:30:21 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm
r955 r959 216 216 217 217 sub attr_label { 218 my ($self, $attr) = @_; 219 my ($hint, $label) = ('', ''); 218 my ($self, $attr, $label, $hint) = @_; 219 $label ||= ''; 220 $hint ||= ''; 220 221 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)); 222 224 if (my $attr_config = LATMOS::Accounts::Web->config->{attrs}{$attr}) { 223 $label = $attr_config->{label} || '';225 $label ||= $attr_config->{label} || ''; 224 226 #utf8::is_utf8($label) && utf8::encode($label); 225 $hint = $attr_config->{hint} || '';227 $hint ||= $attr_config->{hint} || ''; 226 228 #utf8::is_utf8($hint) && utf8::encode($hint); 227 229 } … … 243 245 244 246 sub 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 } 248 259 } 249 260 … … 251 262 my ($self, $attr) = @_; 252 263 my $id = $self->{object} 253 ? $self->{object}->id . '_'264 ? ($self->{object}->id || '') 254 265 : ''; 266 $id .= '_' if ($id); 255 267 $id =~ s/\./_/g; 256 268 $id =~ s/-/_/g; … … 403 415 last; 404 416 }; 405 406 warn $_;407 417 } 408 418 return ''; … … 450 460 frequency => 1, 451 461 with => "'val='+element.value" . 452 ($self->{object} ? "+'&exclude=" . $self->{object}->id . "'" : 453 ''), 462 ($self->{object} ? 463 "+'&exclude=" . ($self->{object}->id || '') . "'" 464 : ''), 454 465 } 455 466 ) … … 463 474 my ($self, $attr, $type) = @_; 464 475 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 480 489 481 490 my $htmlname = $self->escape($self->attr_field_name($attr)); 482 491 483 492 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) { 488 504 489 505 my $html_id = $htmlname . … … 501 517 } 502 518 503 if ($attribute->{multiple} ) {519 if ($attribute->{multiple} && !$attribute->readonly) { 504 520 my $html_id = $htmlname . '_m_SUBID'; 505 521
Note: See TracChangeset
for help on using the changeset viewer.