Revision de968328
Von Tamino Steinert vor 8 Monaten hinzugefügt
SL/ClientJS.pm | ||
---|---|---|
10 | 10 |
use Rose::Object::MakeMethods::Generic |
11 | 11 |
( |
12 | 12 |
scalar => [ qw() ], |
13 |
'scalar --get_set_init' => [ qw(controller _actions _flash _flash_detail _no_flash_clear _error) ],
|
|
13 |
'scalar --get_set_init' => [ qw(controller _actions _error) ], |
|
14 | 14 |
); |
15 | 15 |
|
16 | 16 |
my %supported_methods = ( |
... | ... | |
115 | 115 |
redirect_to => 1, # window.location.href = <TARGET> |
116 | 116 |
save_file => 4, # kivi.save_file(<TARGET>, <ARGS>) |
117 | 117 |
|
118 |
flash => 2, # kivi.display_flash(<TARGET>, <ARGS>) |
|
119 |
flash_detail => 2, # kivi.display_flash_detail(<TARGET>, <ARGS>) |
|
120 |
clear_flash => 2, # kivi.clear_flash(<TARGET>, <ARGS>) |
|
118 |
# flash |
|
119 |
flash => -2, # kivi.Flash.display_flash.apply({}, action.slice(1, action.length)) |
|
120 |
clear_flash => 0, # kivi.Flash.clear_flash() |
|
121 |
show_flash => 0, # kivi.Flash.show() |
|
122 |
hide_flash => 0, # kivi.Flash.hide() |
|
123 |
|
|
121 | 124 |
reinit_widgets => 0, # kivi.reinit_widgets() |
122 | 125 |
run => -1, # kivi.run(<TARGET>, <ARGS>) |
123 | 126 |
run_once_for => 3, # kivi.run_once_for(<TARGET>, <ARGS>) |
... | ... | |
181 | 184 |
return []; |
182 | 185 |
} |
183 | 186 |
|
184 |
sub init__flash { |
|
185 |
return {}; |
|
186 |
} |
|
187 |
|
|
188 |
sub init__flash_detail { |
|
189 |
return {}; |
|
190 |
} |
|
191 |
|
|
192 |
sub init__error { |
|
193 |
return ''; |
|
194 |
} |
|
195 |
|
|
196 |
sub init__no_flash_clear { |
|
197 |
return ''; |
|
198 |
} |
|
199 |
|
|
200 | 187 |
sub to_json { |
201 | 188 |
my ($self) = @_; |
202 | 189 |
|
203 | 190 |
return SL::JSON::to_json({ error => $self->_error }) if $self->_error; |
204 |
return SL::JSON::to_json({ no_flash_clear => $self->_no_flash_clear, eval_actions => $self->_actions });
|
|
191 |
return SL::JSON::to_json({ eval_actions => $self->_actions }); |
|
205 | 192 |
} |
206 | 193 |
|
207 | 194 |
sub to_array { |
... | ... | |
234 | 221 |
return $self; |
235 | 222 |
} |
236 | 223 |
|
237 |
sub flash { |
|
238 |
my ($self, $type, @messages) = @_; |
|
239 |
|
|
240 |
my $message = join ' ', grep { $_ } @messages; |
|
241 |
|
|
242 |
if (!$self->_flash->{$type}) { |
|
243 |
$self->_flash->{$type} = [ 'flash', $type, $message ]; |
|
244 |
push @{ $self->_actions }, $self->_flash->{$type}; |
|
245 |
} else { |
|
246 |
$self->_flash->{$type}->[-1] .= ' ' . $message; |
|
247 |
} |
|
248 |
|
|
249 |
return $self; |
|
250 |
} |
|
251 |
|
|
252 |
sub flash_detail { |
|
253 |
my ($self, $type, @messages) = @_; |
|
254 |
|
|
255 |
my $message = join '<br>', grep { $_ } @messages; |
|
256 |
|
|
257 |
if (!$self->_flash_detail->{$type}) { |
|
258 |
$self->_flash_detail->{$type} = [ 'flash_detail', $type, $message ]; |
|
259 |
push @{ $self->_actions }, $self->_flash_detail->{$type}; |
|
260 |
} else { |
|
261 |
$self->_flash_detail->{$type}->[-1] .= ' ' . $message; |
|
262 |
} |
|
263 |
|
|
264 |
return $self; |
|
265 |
} |
|
266 |
|
|
267 | 224 |
sub no_flash_clear{ |
268 |
my ($self) = @_; |
|
269 |
$self->_no_flash_clear('1'); |
|
270 |
return $self; |
|
225 |
$_[0]; # noop for compatibility |
|
271 | 226 |
} |
272 | 227 |
|
273 | 228 |
sub error { |
... | ... | |
485 | 440 |
|
486 | 441 |
=over 4 |
487 | 442 |
|
488 |
=item C<flash $type, $message> |
|
489 |
|
|
490 |
Display a C<$message> in the flash of type C<$type>. Multiple calls of |
|
491 |
C<flash> on the same C<$self> will be merged by type. |
|
492 |
|
|
493 |
On the client side the flashes of all types will be cleared after each |
|
494 |
successful ClientJS call that did not end with C<$js-E<gt>error(...)>. |
|
495 |
This clearing can be switched of by the function C<no_flash_clear> |
|
496 |
|
|
497 |
=item C<flash_detail $type, $message> |
|
498 |
|
|
499 |
Display a detailed message C<$message> in the flash of type C<$type>. Multiple calls of |
|
500 |
C<flash_detail> on the same C<$self> will be merged by type. |
|
501 |
So the flash message can be hold short and the visibility of details can toggled by the user. |
|
502 |
|
|
503 |
=item C<no_flash_clear> |
|
443 |
=item C<flash $type, $message [, $details [, timestamp ]]> |
|
504 | 444 |
|
505 |
No automatic clearing of flash after successful ClientJS call |
|
445 |
Display a C<$message> in the flash of type C<$type> with optional |
|
446 |
C<$details>. |
|
506 | 447 |
|
507 | 448 |
=item C<error $message> |
508 | 449 |
|
Auch abrufbar als: Unified diff
SL::Layout::Flash: fliegende Flash-Meldungen (portiert von Odyn)