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 = (
redirect_to => 1, # window.location.href = <TARGET>
flash => 2, # kivi.display_flash(<TARGET>, <ARGS>)
+ flash_detail => 2, # kivi.display_flash_detail(<TARGET>, <ARGS>)
reinit_widgets => 0, # kivi.reinit_widgets()
run => -1, # kivi.run(<TARGET>, <ARGS>)
run_once_for => 3, # kivi.run_once_for(<TARGET>, <ARGS>)
scroll_into_view => 1, # $(<TARGET>)[0].scrollIntoView()
);
+my %trim_target_for = map { ($_ => 1) } qw(insertAfter insertBefore appendTo prependTo);
+
sub AUTOLOAD {
our $AUTOLOAD;
$args[$idx] = "" . $args[$idx] if ref($args[$idx]) eq 'SL::Presenter::EscapedText';
}
+ # Trim leading whitespaces for certain jQuery functions that operate
+ # on HTML code: $("<p>test</p>").appendTo('#some-id'). jQuery croaks
+ # on leading whitespaces, e.g. on $(" <p>test</p>").
+ $args[0] =~ s{^\s+}{} if $trim_target_for{$method};
+
push @{ $self->_actions }, [ $method, @args ];
return $self;
return {};
}
+sub init__flash_detail {
+ return {};
+}
+
sub init__error {
return '';
}
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 error {
my ($self, @messages) = @_;
return $self;
}
+sub init_controller {
+ # fallback
+ require SL::Controller::Base;
+ SL::Controller::Base->new;
+}
+
1;
__END__