Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b5f4fac1

Von Moritz Bunkus vor etwa 8 Jahren hinzugefügt

  • ID b5f4fac196509681df791bc5e4ee3d8c7d2a4a41
  • Vorgänger c44615e9
  • Nachfolger d6838f77

Presenter: hidden_tag, javascript, checkbox_tag von L → Presenter::Tag verschoben

Damit sind diese Funktionen auch direkt aus Perl-Code verfügbar, und man
muss nicht mehr das unsägliche CGI benutzen, um Checkboxen zu rendern.

Unterschiede anzeigen:

SL/Presenter/Tag.pm
7 7
use parent qw(Exporter);
8 8

  
9 9
use Exporter qw(import);
10
our @EXPORT = qw(html_tag input_tag man_days_tag name_to_id select_tag stringify_attributes restricted_html);
10
our @EXPORT = qw(html_tag input_tag hidden_tag javascript man_days_tag name_to_id select_tag checkbox_tag stringify_attributes restricted_html);
11 11

  
12 12
use Carp;
13 13

  
......
62 62
  return $self->html_tag('input', undef, %attributes, name => $name, value => $value);
63 63
}
64 64

  
65
sub hidden_tag {
66
  my ($self, $name, $value, %attributes) = @_;
67
  return $self->input_tag($name, $value, %attributes, type => 'hidden');
68
}
69

  
65 70
sub man_days_tag {
66 71
  my ($self, $name, $object, %attributes) = @_;
67 72

  
......
189 194
  return $self->html_tag('select', $code, %attributes, name => $name);
190 195
}
191 196

  
197
sub checkbox_tag {
198
  my ($self, $name, %attributes) = @_;
199

  
200
  _set_id_attribute(\%attributes, $name);
201

  
202
  $attributes{value}   = 1 unless defined $attributes{value};
203
  my $label            = delete $attributes{label};
204
  my $checkall         = delete $attributes{checkall};
205
  my $for_submit       = delete $attributes{for_submit};
206

  
207
  if ($attributes{checked}) {
208
    $attributes{checked} = 'checked';
209
  } else {
210
    delete $attributes{checked};
211
  }
212

  
213
  my $code  = '';
214
  $code    .= $self->hidden_tag($name, 0, %attributes, id => $attributes{id} . '_hidden') if $for_submit;
215
  $code    .= $self->html_tag('input', undef,  %attributes, name => $name, type => 'checkbox');
216
  $code    .= $self->html_tag('label', $label, for => $attributes{id}) if $label;
217
  $code    .= $self->javascript(qq|\$('#$attributes{id}').checkall('$checkall');|) if $checkall;
218

  
219
  return $code;
220
}
221

  
222
sub javascript {
223
  my ($self, $data) = @_;
224
  return $self->html_tag('script', $data, type => 'text/javascript');
225
}
226

  
192 227
sub _set_id_attribute {
193 228
  my ($attributes, $name, $unique) = @_;
194 229

  

Auch abrufbar als: Unified diff