diff options
author | wreis <wreis@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-08-05 01:58:14 +0000 |
---|---|---|
committer | wreis <wreis@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-08-05 01:58:14 +0000 |
commit | b210789fed64cda65459e48b7f68b88733c04dd7 (patch) | |
tree | c8ca8ef75b411cd4e9b02a38f670db09eeb24760 | |
parent | 2f4c7285eeda79854ef6fc2ebbd878e89d1d19e3 (diff) | |
parent | 4b70129e4e977a51616faaaeefd61a39367861f0 (diff) | |
download | reaction-b210789fed64cda65459e48b7f68b88733c04dd7.tar.gz reaction-b210789fed64cda65459e48b7f68b88733c04dd7.zip |
r4466@www43 (orig r1196): groditi | 2009-08-01 15:07:10 -0500
make "class" in the config for push_vieport work correctly
r4488@www43 (orig r1199): groditi | 2009-08-03 17:25:09 -0500
let delete have its own callback by default
r4499@www43 (orig r1207): groditi | 2009-08-04 11:01:28 -0500
r30359@martha (orig r1198): groditi | 2009-08-01 16:57:29 -0400
example of how to create forms that return users to the URI they came from
-rw-r--r-- | lib/ComponentUI/Controller/TestModel/Bar.pm | 21 | ||||
-rw-r--r-- | lib/Reaction/UI/Controller.pm | 4 | ||||
-rw-r--r-- | lib/Reaction/UI/Controller/Collection/CRUD.pm | 10 | ||||
-rw-r--r-- | share/skin/componentui/layout/bar/create.tt | 10 |
4 files changed, 41 insertions, 4 deletions
diff --git a/lib/ComponentUI/Controller/TestModel/Bar.pm b/lib/ComponentUI/Controller/TestModel/Bar.pm index c649d78..4701fff 100644 --- a/lib/ComponentUI/Controller/TestModel/Bar.pm +++ b/lib/ComponentUI/Controller/TestModel/Bar.pm @@ -8,6 +8,7 @@ __PACKAGE__->config( collection_name => 'Bar', action => { base => { Chained => '/base', PathPart => 'testmodel/bar' }, + create => { ViewPort => { layout => 'bar/create' } }, list => { ViewPort => { enable_order_by => [qw/name foo published_at/], @@ -32,7 +33,27 @@ sub create :Chained('base') { my $action_vp = $self->next::method(@_); my $self_uri = $c->uri_for($self->action_for('create')); $action_vp->action($self_uri); + + my $params = $c->request->parameters; + if ( defined $params->{return_to_uri} && $params->{return_to_uri} ){ + if( $params->{return_to_uri} ne $c->request->uri ){ + $action_vp->layout_args->{return_to_uri} = $params->{return_to_uri}; + } + } elsif( $c->request->referer ne $c->request->uri) { + $action_vp->layout_args->{return_to_uri} = $c->request->referer; + } + return $action_vp; } +sub on_create_close_callback { + my($self, $c, $vp) = @_; + if ( my $return_to_uri = delete $c->request->parameters->{return_to_uri} ){ + $c->response->redirect( $return_to_uri ); + } else { + $self->redirect_to( $c, 'list' ); + } + $c->detach; +} + 1; diff --git a/lib/Reaction/UI/Controller.pm b/lib/Reaction/UI/Controller.pm index 46456bd..8ed781f 100644 --- a/lib/Reaction/UI/Controller.pm +++ b/lib/Reaction/UI/Controller.pm @@ -26,9 +26,7 @@ sub push_viewport { $vp_attr = $vp_attr->[0]; } if (ref($vp_attr) eq 'HASH') { - if (my $conf_class = delete $vp_attr->{class}) { - $class = $conf_class; - } + $class = $vp_attr->{class} if defined $vp_attr->{class}; %args = %{ $self->merge_config_hashes($vp_attr, {@proto_args}) }; } else { $class = $vp_attr; diff --git a/lib/Reaction/UI/Controller/Collection/CRUD.pm b/lib/Reaction/UI/Controller/Collection/CRUD.pm index 6dfed13..11a29f9 100644 --- a/lib/Reaction/UI/Controller/Collection/CRUD.pm +++ b/lib/Reaction/UI/Controller/Collection/CRUD.pm @@ -90,13 +90,21 @@ sub on_update_close_callback { sub delete :Chained('object') :Args(0) { my ($self, $c) = @_; - my $close = sub { $self->on_update_close_callback( @_) }; + my $close = sub { $self->on_delete_close_callback( @_) }; my $vp_args = { on_close_callback => $self->make_context_closure($close), }; $self->basic_model_action( $c, $vp_args); } +sub on_delete_close_callback { + my($self, $c) = @_; + #this needs a better solution. currently thinking about it + my @cap = @{$c->req->captures}; + pop(@cap); # object id + $self->redirect_to($c, 'list', \@cap); +} + sub basic_model_action { my ($self, $c, $vp_args) = @_; my $stash = $c->stash; diff --git a/share/skin/componentui/layout/bar/create.tt b/share/skin/componentui/layout/bar/create.tt new file mode 100644 index 0000000..e59fbba --- /dev/null +++ b/share/skin/componentui/layout/bar/create.tt @@ -0,0 +1,10 @@ +=widget Action + +=extends action + +=for layout container_list + +<input type="hidden" name="return_to_uri" value="[% return_to_uri %]"> +[% call_next %] + +=cut |