From 59e408118671a114fe45ded6df15b1d6cbf21042 Mon Sep 17 00:00:00 2001 From: groditi Date: Sat, 1 Aug 2009 20:07:10 +0000 Subject: make "class" in the config for push_vieport work correctly --- lib/Reaction/UI/Controller.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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; -- cgit v1.2.3-54-g00ecf -- cgit v1.2.3-54-g00ecf From a6e66122c2a0528001eff1e3a3814699fb1e11e6 Mon Sep 17 00:00:00 2001 From: groditi Date: Sat, 1 Aug 2009 20:57:29 +0000 Subject: example of how to create forms that return users to the URI they came from --- lib/ComponentUI/Controller/TestModel/Bar.pm | 21 +++++++++++++++++++++ share/skin/componentui/layout/bar/create.tt | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 share/skin/componentui/layout/bar/create.tt diff --git a/lib/ComponentUI/Controller/TestModel/Bar.pm b/lib/ComponentUI/Controller/TestModel/Bar.pm index 4859b7d..95f0975 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/], @@ -29,7 +30,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/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 + + +[% call_next %] + +=cut -- cgit v1.2.3-54-g00ecf From 35dd77ad06c0e5b96684751183253e736e189f04 Mon Sep 17 00:00:00 2001 From: groditi Date: Mon, 3 Aug 2009 22:25:09 +0000 Subject: let delete have its own callback by default --- lib/Reaction/UI/Controller/Collection/CRUD.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3-54-g00ecf