added search spec sample to demo app
[catagits/Reaction.git] / lib / ComponentUI / Controller / TestModel / Foo.pm
1 package ComponentUI::Controller::TestModel::Foo;
2
3 use base 'Reaction::UI::Controller::Collection::CRUD';
4 use Reaction::Class;
5
6 use aliased 'Reaction::UI::ViewPort::SearchableListViewContainer';
7 use aliased 'ComponentUI::TestModel::Foo::SearchSpec';
8 use aliased 'ComponentUI::TestModel::Foo::Action::SearchSpec::Update';
9
10 __PACKAGE__->config(
11   model_name => 'TestModel',
12   collection_name => 'Foo',
13   action => {
14     base => { Chained => '/base', PathPart => 'testmodel/foo' },
15     list => {
16       ViewPort => {
17         action_prototypes => { delete_all => 'Delete all records' },
18         excluded_fields => [qw/id/],
19         action_order => [qw/delete_all create/],
20         enable_order_by => [qw/last_name/],
21         Member => {
22           action_order => [qw/view update delete/],
23         },
24       },
25     },
26     view => {
27       ViewPort => {
28         excluded_fields => [qw/id/],
29       },
30     },
31     delete => {
32       ViewPort => {message => 'Are you sure you want to delete this Foo?'}
33     },
34   },
35 );
36
37 for my $action (qw/view create update/){
38   __PACKAGE__->config(
39     action => {
40       $action => {
41         ViewPort => {
42           container_layouts => [
43             { name => 'primary', fields => [qw/first_name last_name/]},
44             {
45               name => 'secondary',
46               label => 'Optional Label',
47               fields => [qw/bars bazes/],
48             },
49           ],
50         },
51       },
52     }
53   );
54 }
55
56 override _build_action_viewport_map => sub {
57   my $map = super();
58   $map->{list} = SearchableListViewContainer;
59   $map;
60 };
61
62 sub _build_action_viewport_args {
63   my $self = shift;
64   my $args = $self->next::method(@_);
65   $args->{list}{action_prototypes}{delete_all}{label} = 'Delete All Records';
66   $args->{list}{spec_class} = SearchSpec;
67   $args->{list}{action_class} = Update;
68   return $args;
69 }
70
71 1;