Revision b5f4fac1
Von Moritz Bunkus vor fast 9 Jahren hinzugefügt
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 |
|
SL/Template/Plugin/L.pm | ||
---|---|---|
62 | 62 |
|
63 | 63 |
sub name_to_id { return _call_presenter('name_to_id', @_); } |
64 | 64 |
sub html_tag { return _call_presenter('html_tag', @_); } |
65 |
sub hidden_tag { return _call_presenter('hidden_tag', @_); } |
|
65 | 66 |
sub select_tag { return _call_presenter('select_tag', @_); } |
67 |
sub checkbox_tag { return _call_presenter('checkbox_tag', @_); } |
|
66 | 68 |
sub input_tag { return _call_presenter('input_tag', @_); } |
69 |
sub javascript { return _call_presenter('javascript', @_); } |
|
67 | 70 |
sub truncate { return _call_presenter('truncate', @_); } |
68 | 71 |
sub simple_format { return _call_presenter('simple_format', @_); } |
69 | 72 |
sub part_picker { return _call_presenter('part_picker', @_); } |
... | ... | |
95 | 98 |
return $self->html_tag('textarea', $content, %attributes, name => $name); |
96 | 99 |
} |
97 | 100 |
|
98 |
sub checkbox_tag { |
|
99 |
my ($self, $name, %attributes) = _hashify(2, @_); |
|
100 |
|
|
101 |
_set_id_attribute(\%attributes, $name); |
|
102 |
$attributes{value} = 1 unless defined $attributes{value}; |
|
103 |
my $label = delete $attributes{label}; |
|
104 |
my $checkall = delete $attributes{checkall}; |
|
105 |
my $for_submit = delete $attributes{for_submit}; |
|
106 |
|
|
107 |
if ($attributes{checked}) { |
|
108 |
$attributes{checked} = 'checked'; |
|
109 |
} else { |
|
110 |
delete $attributes{checked}; |
|
111 |
} |
|
112 |
|
|
113 |
my $code = ''; |
|
114 |
$code .= $self->hidden_tag($name, 0, %attributes, id => $attributes{id} . '_hidden') if $for_submit; |
|
115 |
$code .= $self->html_tag('input', undef, %attributes, name => $name, type => 'checkbox'); |
|
116 |
$code .= $self->html_tag('label', $label, for => $attributes{id}) if $label; |
|
117 |
$code .= $self->javascript(qq|\$('#$attributes{id}').checkall('$checkall');|) if $checkall; |
|
118 |
|
|
119 |
return $code; |
|
120 |
} |
|
121 |
|
|
122 | 101 |
sub radio_button_tag { |
123 | 102 |
my ($self, $name, %attributes) = _hashify(2, @_); |
124 | 103 |
|
... | ... | |
141 | 120 |
return $code; |
142 | 121 |
} |
143 | 122 |
|
144 |
sub hidden_tag { |
|
145 |
my ($self, $name, $value, %attributes) = _hashify(3, @_); |
|
146 |
return $self->input_tag($name, $value, %attributes, type => 'hidden'); |
|
147 |
} |
|
148 |
|
|
149 | 123 |
sub div_tag { |
150 | 124 |
my ($self, $content, @slurp) = @_; |
151 | 125 |
return $self->html_tag('div', $content, @slurp); |
... | ... | |
206 | 180 |
return $self->select_tag($name, [ [ 1 => $::locale->text('Yes') ], [ 0 => $::locale->text('No') ] ], default => $value ? 1 : 0, %attributes); |
207 | 181 |
} |
208 | 182 |
|
209 |
sub javascript { |
|
210 |
my ($self, $data) = @_; |
|
211 |
return $self->html_tag('script', $data, type => 'text/javascript'); |
|
212 |
} |
|
213 |
|
|
214 | 183 |
sub stylesheet_tag { |
215 | 184 |
my $self = shift; |
216 | 185 |
my $code = ''; |
Auch abrufbar als: Unified diff
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.