X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FClientJS.pm;h=4cdb2037e2770d66b2bfeb9d9f69a29f94378989;hb=7349649bae8d80eabfd253592d59f8455f9ef6b0;hp=0da0afd57a84ea93b7c59486e2cddac8ccb30b18;hpb=1e6fdf4876cf4b5ee1eedd4ca6ad2888fec8a152;p=kivitendo-erp.git diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 0da0afd57..4cdb2037e 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 = ( @@ -75,7 +75,8 @@ my %supported_methods = ( # ## jQuery UI dialog plugin ## pattern: $().dialog('') - # Closing and removing the popup + # Opening and closing and closing a popup + 'dialog:open' => 1, # kivi.popup_dialog() 'dialog:close' => 1, # ## jQuery Form plugin ## @@ -114,11 +115,16 @@ my %supported_methods = ( redirect_to => 1, # window.location.href = flash => 2, # kivi.display_flash(, ) + flash_detail => 2, # kivi.display_flash_detail(, ) reinit_widgets => 0, # kivi.reinit_widgets() run => -1, # kivi.run(, ) run_once_for => 3, # kivi.run_once_for(, ) + + scroll_into_view => 1, # $()[0].scrollIntoView() ); +my %trim_target_for = map { ($_ => 1) } qw(insertAfter insertBefore appendTo prependTo); + sub AUTOLOAD { our $AUTOLOAD; @@ -136,10 +142,10 @@ sub action { $method = (delete($self->{_prefix}) || '') . $method; my $num_args = $supported_methods{$method}; - croak "Unsupported jQuery action: $method" unless defined $num_args; + croak "Unsupported jQuery action: $method" unless defined $num_args; if ($num_args > 0) { - croak "Parameter count mismatch for $method(actual: " . scalar(@args) . " wanted: $num_args)" if scalar(@args) != $num_args; + croak "Parameter count mismatch for $method(actual: " . scalar(@args) . " wanted: $num_args)" if scalar(@args) != $num_args; } else { $num_args *= -1; croak "Parameter count mismatch for $method(actual: " . scalar(@args) . " wanted at least: $num_args)" if scalar(@args) < $num_args; @@ -147,11 +153,15 @@ sub action { } foreach my $idx (0..$num_args - 1) { - # Force flattening from SL::Presenter::EscapedText and trim leading whitespace for scalars - $args[$idx] = "" . $args[$idx] if ref($args[$idx]) eq 'SL::Presenter::EscapedText'; - $args[$idx] =~ s/^\s+// if !ref($args[$idx]); + # Force flattening from SL::Presenter::EscapedText. + $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; @@ -171,6 +181,10 @@ sub init__flash { return {}; } +sub init__flash_detail { + return {}; +} + sub init__error { return ''; } @@ -227,6 +241,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) = @_; @@ -235,6 +264,12 @@ sub error { return $self; } +sub init_controller { + # fallback + require SL::Controller::Base; + SL::Controller::Base->new; +} + 1; __END__