Revision 4a663bf8
Von Tamino Steinert vor 3 Monaten hinzugefügt
| SL/ClientJS.pm | ||
|---|---|---|
|
use Rose::Object::MakeMethods::Generic
|
||
|
(
|
||
|
scalar => [ qw() ],
|
||
|
'scalar --get_set_init' => [ qw(controller _actions _flash _flash_detail _no_flash_clear _error) ],
|
||
|
'scalar --get_set_init' => [ qw(controller _actions _error) ],
|
||
|
);
|
||
|
|
||
|
my %supported_methods = (
|
||
| ... | ... | |
|
redirect_to => 1, # window.location.href = <TARGET>
|
||
|
save_file => 4, # kivi.save_file(<TARGET>, <ARGS>)
|
||
|
|
||
|
flash => 2, # kivi.display_flash(<TARGET>, <ARGS>)
|
||
|
flash_detail => 2, # kivi.display_flash_detail(<TARGET>, <ARGS>)
|
||
|
clear_flash => 2, # kivi.clear_flash(<TARGET>, <ARGS>)
|
||
|
# flash
|
||
|
flash => -2, # kivi.Flash.display_flash.apply({}, action.slice(1, action.length))
|
||
|
clear_flash => 0, # kivi.Flash.clear_flash()
|
||
|
show_flash => 0, # kivi.Flash.show()
|
||
|
hide_flash => 0, # kivi.Flash.hide()
|
||
|
|
||
|
reinit_widgets => 0, # kivi.reinit_widgets()
|
||
|
run => -1, # kivi.run(<TARGET>, <ARGS>)
|
||
|
run_once_for => 3, # kivi.run_once_for(<TARGET>, <ARGS>)
|
||
| ... | ... | |
|
return [];
|
||
|
}
|
||
|
|
||
|
sub init__flash {
|
||
|
return {};
|
||
|
}
|
||
|
|
||
|
sub init__flash_detail {
|
||
|
return {};
|
||
|
}
|
||
|
|
||
|
sub init__error {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
sub init__no_flash_clear {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
sub to_json {
|
||
|
my ($self) = @_;
|
||
|
|
||
|
return SL::JSON::to_json({ error => $self->_error }) if $self->_error;
|
||
|
return SL::JSON::to_json({ no_flash_clear => $self->_no_flash_clear, eval_actions => $self->_actions });
|
||
|
return SL::JSON::to_json({ eval_actions => $self->_actions });
|
||
|
}
|
||
|
|
||
|
sub to_array {
|
||
| ... | ... | |
|
return $self;
|
||
|
}
|
||
|
|
||
|
sub flash {
|
||
|
my ($self, $type, @messages) = @_;
|
||
|
|
||
|
my $message = join ' ', grep { $_ } @messages;
|
||
|
|
||
|
if (!$self->_flash->{$type}) {
|
||
|
$self->_flash->{$type} = [ 'flash', $type, $message ];
|
||
|
push @{ $self->_actions }, $self->_flash->{$type};
|
||
|
} else {
|
||
|
$self->_flash->{$type}->[-1] .= ' ' . $message;
|
||
|
}
|
||
|
|
||
|
return $self;
|
||
|
}
|
||
|
|
||
|
sub flash_detail {
|
||
|
my ($self, $type, @messages) = @_;
|
||
|
|
||
|
my $message = join '<br>', grep { $_ } @messages;
|
||
|
|
||
|
if (!$self->_flash_detail->{$type}) {
|
||
|
$self->_flash_detail->{$type} = [ 'flash_detail', $type, $message ];
|
||
|
push @{ $self->_actions }, $self->_flash_detail->{$type};
|
||
|
} else {
|
||
|
$self->_flash_detail->{$type}->[-1] .= ' ' . $message;
|
||
|
}
|
||
|
|
||
|
return $self;
|
||
|
}
|
||
|
|
||
|
sub no_flash_clear{
|
||
|
my ($self) = @_;
|
||
|
$self->_no_flash_clear('1');
|
||
|
return $self;
|
||
|
$_[0]; # noop for compatibility
|
||
|
}
|
||
|
|
||
|
sub error {
|
||
| ... | ... | |
|
|
||
|
=over 4
|
||
|
|
||
|
=item C<flash $type, $message>
|
||
|
|
||
|
Display a C<$message> in the flash of type C<$type>. Multiple calls of
|
||
|
C<flash> on the same C<$self> will be merged by type.
|
||
|
|
||
|
On the client side the flashes of all types will be cleared after each
|
||
|
successful ClientJS call that did not end with C<$js-E<gt>error(...)>.
|
||
|
This clearing can be switched of by the function C<no_flash_clear>
|
||
|
|
||
|
=item C<flash_detail $type, $message>
|
||
|
|
||
|
Display a detailed message C<$message> in the flash of type C<$type>. Multiple calls of
|
||
|
C<flash_detail> on the same C<$self> will be merged by type.
|
||
|
So the flash message can be hold short and the visibility of details can toggled by the user.
|
||
|
|
||
|
=item C<no_flash_clear>
|
||
|
=item C<flash $type, $message [, $details [, timestamp ]]>
|
||
|
|
||
|
No automatic clearing of flash after successful ClientJS call
|
||
|
Display a C<$message> in the flash of type C<$type> with optional
|
||
|
C<$details>.
|
||
|
|
||
|
=item C<error $message>
|
||
|
|
||
Auch abrufbar als: Unified diff
SL::Layout::Flash: fliegende Flash-Meldungen (portiert von Odyn)