X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FClientJS.pm;h=91ff14b18b4ae251013c522b15714248bbcd6f39;hb=8d06fb89311819177dbfe9fa50cd7bc87d87be85;hp=f1c949e5fef2b2226dd3229650430d7ebd650604;hpb=3a94c2e211df64dbcbd2b396a12e4bf1f3cf59aa;p=kivitendo-erp.git diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index f1c949e5f..91ff14b18 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -9,8 +9,8 @@ use SL::JSON (); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(controller) ], - 'scalar --get_set_init' => [ qw(_actions _flash _error) ], + scalar => [ qw() ], + 'scalar --get_set_init' => [ qw(controller _actions _flash _flash_detail _error) ], ); my %supported_methods = ( @@ -115,6 +115,8 @@ my %supported_methods = ( redirect_to => 1, # window.location.href = flash => 2, # kivi.display_flash(, ) + flash_detail => 2, # kivi.display_flash_detail(, ) + clear_flash => 2, # kivi.display_flash_detail(, ) reinit_widgets => 0, # kivi.reinit_widgets() run => -1, # kivi.run(, ) run_once_for => 3, # kivi.run_once_for(, ) @@ -122,6 +124,8 @@ my %supported_methods = ( scroll_into_view => 1, # $()[0].scrollIntoView() ); +my %trim_target_for = map { ($_ => 1) } qw(insertAfter insertBefore appendTo prependTo); + sub AUTOLOAD { our $AUTOLOAD; @@ -154,6 +158,11 @@ sub action { $args[$idx] = "" . $args[$idx] if ref($args[$idx]) eq 'SL::Presenter::EscapedText'; } + # Trim leading whitespaces for certain jQuery functions that operate + # on HTML code: $("

test

").appendTo('#some-id'). jQuery croaks + # on leading whitespaces, e.g. on $("

test

"). + $args[0] =~ s{^\s+}{} if $trim_target_for{$method}; + push @{ $self->_actions }, [ $method, @args ]; return $self; @@ -173,6 +182,10 @@ sub init__flash { return {}; } +sub init__flash_detail { + return {}; +} + sub init__error { return ''; } @@ -229,6 +242,21 @@ sub flash { return $self; } +sub flash_detail { + my ($self, $type, @messages) = @_; + + my $message = join '
', 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 error { my ($self, @messages) = @_; @@ -237,6 +265,12 @@ sub error { return $self; } +sub init_controller { + # fallback + require SL::Controller::Base; + SL::Controller::Base->new; +} + 1; __END__