Commit | Line | Data |
7adfd53f |
1 | package ComponentUI::Controller::TestModel::Bar; |
2 | |
26fa3b8a |
3 | use Moose; |
90bcd4d7 |
4 | BEGIN { extends 'Reaction::UI::Controller::Collection::CRUD'; } |
7adfd53f |
5 | |
6 | __PACKAGE__->config( |
a4f82080 |
7 | model_name => 'TestModel', |
8 | collection_name => 'Bar', |
599c1172 |
9 | action => { |
10 | base => { Chained => '/base', PathPart => 'testmodel/bar' }, |
a6e66122 |
11 | create => { ViewPort => { layout => 'bar/create' } }, |
c1b16a7d |
12 | list => { |
13 | ViewPort => { |
14 | enable_order_by => [qw/name foo published_at/], |
15 | coerce_order_by => { foo => ['foo.last_name', 'foo.first_name'] }, |
fff7579c |
16 | layout => 'bar/collection', |
17 | member_class => 'Reaction::UI::ViewPort::Object', |
18 | Member => { layout => 'bar/member' } |
931cbc8d |
19 | }, |
20 | }, |
599c1172 |
21 | }, |
7adfd53f |
22 | ); |
23 | |
931cbc8d |
24 | around get_collection => sub { |
25 | my ($orig, $self, $c) = @_; |
26 | my $collection = $self->$orig($c); |
c1b16a7d |
27 | return $collection->where({}, { prefetch => 'foo' }); |
931cbc8d |
28 | }; |
29 | |
30 | 1; |
31 | |
32 | __END__; |
c1b16a7d |
33 | |
931cbc8d |
34 | #put this aside for now |
7b5e71ad |
35 | sub create :Chained('base') { |
36 | my $self = shift; |
37 | my ($c) = @_; |
38 | my $action_vp = $self->next::method(@_); |
39 | my $self_uri = $c->uri_for($self->action_for('create')); |
40 | $action_vp->action($self_uri); |
a6e66122 |
41 | |
42 | my $params = $c->request->parameters; |
43 | if ( defined $params->{return_to_uri} && $params->{return_to_uri} ){ |
44 | if( $params->{return_to_uri} ne $c->request->uri ){ |
45 | $action_vp->layout_args->{return_to_uri} = $params->{return_to_uri}; |
46 | } |
47 | } elsif( $c->request->referer ne $c->request->uri) { |
48 | $action_vp->layout_args->{return_to_uri} = $c->request->referer; |
49 | } |
50 | |
7b5e71ad |
51 | return $action_vp; |
52 | } |
53 | |
a6e66122 |
54 | sub on_create_close_callback { |
55 | my($self, $c, $vp) = @_; |
56 | if ( my $return_to_uri = delete $c->request->parameters->{return_to_uri} ){ |
57 | $c->response->redirect( $return_to_uri ); |
58 | } else { |
59 | $self->redirect_to( $c, 'list' ); |
60 | } |
61 | $c->detach; |
62 | } |
63 | |
7adfd53f |
64 | 1; |