sub create :Chained('base') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $vp_args = {
- next_action => 'list',
- on_apply_callback => sub { $self->after_create_callback($c => @_); },
- };
+ on_apply_callback => sub { $self->after_create_callback($c => @_); },
+ on_close_callback => sub { $self->on_create_close_callback($c => @_) }
+ };
$self->basic_model_action( $c, $vp_args);
}
sub delete_all :Chained('base') :PathPart('delete_all') :Args(0) {
my ($self, $c) = @_;
- $self->basic_model_action( $c, { next_action => 'list'});
+ $self->basic_model_action( $c, {
+ on_close_callback => sub { $self->on_delete_all_close_callback($c => @_) }
+ });
+}
+
+sub on_delete_all_close_callback {
+ my($self, $c) = @_;
+ $self->redirect_to($c, 'list');
}
sub after_create_callback {
( $c, 'update', [ @{$c->req->captures}, $result->id ] );
}
+sub on_create_close_callback {
+ my($self, $c, $vp) = @_;
+ $self->redirect_to( $c, 'list' );
+}
+
sub update :Chained('object') :Args(0) {
my ($self, $c) = @_;
+ my $vp_args = {
+ on_close_callback => sub { $self->on_update_close_callback($c => @_ ) }
+ };
+ $self->basic_model_action( $c, $vp_args);
+}
+
+sub on_update_close_callback {
+ my($self, $c) = @_;
#this needs a better solution. currently thinking about it
my @cap = @{$c->req->captures};
pop(@cap); # object id
- my $vp_args = { next_action => [ $self, 'redirect_to', 'list', \@cap ]};
- $self->basic_model_action( $c, $vp_args);
+ $self->redirect_to($c, 'list', \@cap);
}
sub delete :Chained('object') :Args(0) {
my ($self, $c) = @_;
- #this needs a better solution. currently thinking about it
- my @cap = @{$c->req->captures};
- pop(@cap); # object id
- my $vp_args = { next_action => [ $self, 'redirect_to', 'list', \@cap ]};
+ my $vp_args = {
+ on_close_callback => sub { $self->on_update_close_callback($c => @_) }
+ };
$self->basic_model_action( $c, $vp_args);
}
return values %{$self->_tangent_stacks};
};
sub apply_events {
- my ($self, $ctx, $events) = @_;
+ my ($self, $events) = @_;
return unless keys %$events;
- $self->apply_child_events($ctx, $events);
- $self->apply_our_events($ctx, $events);
+ $self->apply_child_events($events);
+ $self->apply_our_events($events);
};
sub apply_child_events {
- my ($self, $ctx, $events) = @_;
+ my ($self, $events) = @_;
return unless keys %$events;
foreach my $child ($self->child_event_sinks) {
confess blessed($child) ."($child) is not a valid object"
unless blessed($child) && $child->can('apply_events');
- $child->apply_events($ctx, $events);
+ $child->apply_events($events);
}
};
sub apply_our_events {
- my ($self, $ctx, $events) = @_;
+ my ($self, $events) = @_;
my @keys = keys %$events;
return unless @keys;
my $loc = $self->location;
if (exists $events->{$event}) {
if (DEBUG_EVENTS) {
my $name = join(' at ', $self, $self->location);
- $self->ctx->log->debug(
+ print STDERR
"Applying Event: $event on $name with value: "
- .(defined $events->{$event} ? $events->{$event} : '<undef>')
- );
+ .(defined $events->{$event} ? $events->{$event} : '<undef>');
}
$self->$event($events->{$event});
}
#has '+model' => (isa => 'Reaction::InterfaceModel::Action');
has method => ( isa => NonEmptySimpleStr, is => 'rw', default => sub { 'post' } );
-has next_action => (is => 'rw', isa => 'ArrayRef');
has on_apply_callback => (is => 'rw', isa => 'CodeRef');
+has on_close_callback => (is => 'rw', isa => 'CodeRef');
has ok_label => (is => 'rw', isa => 'Str', lazy_build => 1);
has apply_label => (is => 'rw', isa => 'Str', lazy_build => 1);
};
sub close {
my $self = shift;
- my ($controller, $name, @args) = @{$self->next_action};
- $controller->pop_viewport;
- $controller->$name($self->ctx, @args);
+ return unless $self->has_on_close_callback;
+ $self->on_close_callback->($self);
};
sub can_close { 1 };
override accept_events => sub {
- (($_[0]->has_next_action ? ('ok', 'close') : ()), 'apply', super());
+ (($_[0]->has_on_close_callback ? ('ok', 'close') : ()), 'apply', super());
}; # can't do a close-type operation if there's nowhere to go afterwards
after apply_child_events => sub {
foreach my $type (qw/query body/) {
my $meth = "${type}_parameters";
my $param_hash = $ctx->req->$meth;
- $self->focus_stack->apply_events($ctx, $param_hash)
+ $self->focus_stack->apply_events($param_hash)
if keys %$param_hash;
}
};