From 13070d3447af4f02bee3e139744440c433755f6f Mon Sep 17 00:00:00 2001 From: edenc Date: Tue, 15 Sep 2009 03:51:37 +0000 Subject: added search spec sample to demo app --- lib/ComponentUI/Controller/TestModel/Foo.pm | 12 +++++++++++ .../TestModel/Foo/Action/SearchSpec/Update.pm | 15 ++++++++++++++ lib/ComponentUI/TestModel/Foo/SearchSpec.pm | 24 ++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/ComponentUI/TestModel/Foo/Action/SearchSpec/Update.pm create mode 100644 lib/ComponentUI/TestModel/Foo/SearchSpec.pm (limited to 'lib') diff --git a/lib/ComponentUI/Controller/TestModel/Foo.pm b/lib/ComponentUI/Controller/TestModel/Foo.pm index 917ea17..d636c6c 100644 --- a/lib/ComponentUI/Controller/TestModel/Foo.pm +++ b/lib/ComponentUI/Controller/TestModel/Foo.pm @@ -3,6 +3,10 @@ package ComponentUI::Controller::TestModel::Foo; use base 'Reaction::UI::Controller::Collection::CRUD'; use Reaction::Class; +use aliased 'Reaction::UI::ViewPort::SearchableListViewContainer'; +use aliased 'ComponentUI::TestModel::Foo::SearchSpec'; +use aliased 'ComponentUI::TestModel::Foo::Action::SearchSpec::Update'; + __PACKAGE__->config( model_name => 'TestModel', collection_name => 'Foo', @@ -49,10 +53,18 @@ for my $action (qw/view create update/){ ); } +override _build_action_viewport_map => sub { + my $map = super(); + $map->{list} = SearchableListViewContainer; + $map; +}; + sub _build_action_viewport_args { my $self = shift; my $args = $self->next::method(@_); $args->{list}{action_prototypes}{delete_all}{label} = 'Delete All Records'; + $args->{list}{spec_class} = SearchSpec; + $args->{list}{action_class} = Update; return $args; } diff --git a/lib/ComponentUI/TestModel/Foo/Action/SearchSpec/Update.pm b/lib/ComponentUI/TestModel/Foo/Action/SearchSpec/Update.pm new file mode 100644 index 0000000..97d2feb --- /dev/null +++ b/lib/ComponentUI/TestModel/Foo/Action/SearchSpec/Update.pm @@ -0,0 +1,15 @@ +package ComponentUI::TestModel::Foo::Action::SearchSpec::Update; +use Reaction::Class; +use namespace::autoclean; + +use MooseX::Types::Common::String qw/NonEmptySimpleStr/; + +extends 'Reaction::InterfaceModel::Action'; +with 'Reaction::InterfaceModel::Search::UpdateSpec'; + +has 'first_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 0); +has 'last_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 0); + +sub _reflection_info {{ normal => [qw/first_name last_name/] }} + +1; diff --git a/lib/ComponentUI/TestModel/Foo/SearchSpec.pm b/lib/ComponentUI/TestModel/Foo/SearchSpec.pm new file mode 100644 index 0000000..4664ec6 --- /dev/null +++ b/lib/ComponentUI/TestModel/Foo/SearchSpec.pm @@ -0,0 +1,24 @@ +package ComponentUI::TestModel::Foo::SearchSpec; +use Reaction::Class; +use namespace::autoclean; + +use MooseX::Types::Common::String qw/NonEmptySimpleStr/; + +with 'Reaction::InterfaceModel::Search::Spec'; + +has 'first_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 0); +has 'last_name' => (isa => NonEmptySimpleStr, is => 'rw', required => 0); + +sub _build__search_spec { + my($self) = @_; + my %search; + $search{first_name} = $self->first_name if $self->has_first_name; + $search{last_name} = $self->last_name if $self->has_last_name; + return [\%search]; +} + +# no special packing/unpacking required for Foo +sub _to_string_pack_value { $_[1] } +sub _from_string_unpack_value { $_[1] } + +1; -- cgit v1.2.3-54-g00ecf