Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision da2fecb4

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID da2fecb453416b3731a896ab6d35e9992be3d9eb
  • Vorgänger 4118324a
  • Nachfolger 1c127236

L-Plugin und Presenter: Erzeugung "ID"-Attribute mittels "no_id => 1" unterdrückbar

Unterschiede anzeigen:

SL/Presenter/Tag.pm
45 45
sub input_tag {
46 46
  my ($self, $name, $value, %attributes) = @_;
47 47

  
48
  $attributes{id}   ||= $self->name_to_id($name);
48
  _set_id_attribute(\%attributes, $name);
49 49
  $attributes{type} ||= 'text';
50 50

  
51 51
  return $self->html_tag('input', undef, %attributes, name => $name, value => $value);
......
77 77
sub select_tag {
78 78
  my ($self, $name, $collection, %attributes) = @_;
79 79

  
80
  $attributes{id}   ||= $self->name_to_id($name);
80
  _set_id_attribute(\%attributes, $name);
81 81

  
82 82
  my $value_key       = delete($attributes{value_key})   || 'id';
83 83
  my $title_key       = delete($attributes{title_key})   || $value_key;
......
173 173
  return $self->html_tag('select', $code, %attributes, name => $name);
174 174
}
175 175

  
176
sub _set_id_attribute {
177
  my ($attributes, $name) = @_;
178

  
179
  $attributes->{id} = name_to_id(undef, $name) if !delete($attributes->{no_id}) && !$attributes->{id};
180

  
181
  return %{ $attributes };
182
}
183

  
176 184
1;
177 185
__END__
178 186

  
......
205 213
A module modeled a bit after Rails' ActionView helpers. Several small
206 214
functions that create HTML tags from various kinds of data sources.
207 215

  
216
The C<id> attribute is usually calculated automatically. This can be
217
overridden by either specifying an C<id> attribute or by setting
218
C<no_id> to trueish.
219

  
208 220
=head1 FUNCTIONS
209 221

  
210 222
=head2 LOW-LEVEL FUNCTIONS
SL/Template/Plugin/L.pm
69 69
sub truncate      { return _call_presenter('truncate',      @_); }
70 70
sub simple_format { return _call_presenter('simple_format', @_); }
71 71

  
72
sub _set_id_attribute {
73
  my ($attributes, $name) = @_;
74
  SL::Presenter::Tag::_set_id_attribute($attributes, $name);
75
}
76

  
72 77
sub img_tag {
73 78
  my ($self, @slurp) = @_;
74 79
  my %options = _hashify(@slurp);
......
82 87
  my ($self, $name, $content, @slurp) = @_;
83 88
  my %attributes      = _hashify(@slurp);
84 89

  
85
  $attributes{id}   ||= $self->name_to_id($name);
90
  _set_id_attribute(\%attributes, $name);
86 91
  $attributes{rows}  *= 1; # required by standard
87 92
  $attributes{cols}  *= 1; # required by standard
88 93
  $content            = $content ? _H($content) : '';
......
94 99
  my ($self, $name, @slurp) = @_;
95 100
  my %attributes       = _hashify(@slurp);
96 101

  
97
  $attributes{id}    ||= $self->name_to_id($name);
102
  _set_id_attribute(\%attributes, $name);
98 103
  $attributes{value}   = 1 unless defined $attributes{value};
99 104
  my $label            = delete $attributes{label};
100 105
  my $checkall         = delete $attributes{checkall};
......
117 122
  my $name             = shift;
118 123
  my %attributes       = _hashify(@_);
119 124

  
125
  _set_id_attribute(\%attributes, $name);
120 126
  $attributes{value}   = 1 unless defined $attributes{value};
121
  $attributes{id}    ||= $self->name_to_id($name . "_" . $attributes{value});
122 127
  my $label            = delete $attributes{label};
123 128

  
124 129
  if ($attributes{checked}) {
......
177 182
  my ($self, $onclick, $value, @slurp) = @_;
178 183
  my %attributes = _hashify(@slurp);
179 184

  
180
  $attributes{id}   ||= $self->name_to_id($attributes{name}) if $attributes{name};
185
  _set_id_attribute(\%attributes, $attributes{name}) if $attributes{name};
181 186
  $attributes{type} ||= 'button';
182 187

  
183 188
  $onclick = 'if (!confirm("'. _J(delete($attributes{confirm})) .'")) return false; ' . $onclick if $attributes{confirm};
......
226 231
  my ($self, $name, $value, @slurp) = @_;
227 232

  
228 233
  my %params   = _hashify(@slurp);
229
  my $id       = $self->name_to_id($name) . _tag_id();
234
  _set_id_attribute(\%params, $name);
230 235
  my @onchange = $params{onchange} ? (onChange => delete $params{onchange}) : ();
231 236
  my @class    = $params{no_cal} || $params{readonly} ? () : (class => 'datepicker');
232 237

  
233 238
  return $self->input_tag(
234 239
    $name, blessed($value) ? $value->to_lxoffice : $value,
235
    id     => $id,
236 240
    size   => 11,
237 241
    onblur => "check_right_date_format(this);",
238 242
    %params,
......
531 535
A module modeled a bit after Rails' ActionView helpers. Several small
532 536
functions that create HTML tags from various kinds of data sources.
533 537

  
538
The C<id> attribute is usually calculated automatically. This can be
539
overridden by either specifying an C<id> attribute or by setting
540
C<no_id> to trueish.
541

  
534 542
=head1 FUNCTIONS
535 543

  
536 544
=head2 LOW-LEVEL FUNCTIONS

Auch abrufbar als: Unified diff