aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm
diff options
context:
space:
mode:
authorphaylon <phaylon@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-03-27 02:40:02 +0000
committerphaylon <phaylon@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-03-27 02:40:02 +0000
commite653a48785a1942da650254c8fba30706ca18333 (patch)
treee0478436bd4a61b1d34af9cf1e770e7e02dba99f /lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm
parent0feb9d76b60db643a717dded5c19efb8f049f642 (diff)
downloadreaction-e653a48785a1942da650254c8fba30706ca18333.tar.gz
reaction-e653a48785a1942da650254c8fba30706ca18333.zip
search spec components factored out of T365
Diffstat (limited to 'lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm')
-rw-r--r--lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm b/lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm
new file mode 100644
index 0000000..b9f919d
--- /dev/null
+++ b/lib/Reaction/UI/ViewPort/SearchableListViewContainer.pm
@@ -0,0 +1,77 @@
+package Reaction::UI::ViewPort::SearchableListViewContainer;
+use Reaction::Class;
+
+#use aliased 'Reaction::InterfaceModel::Search::Spec', 'SearchSpec';
+use aliased 'Reaction::InterfaceModel::Action::Search::UpdateSpec', 'UpdateSearchSpec';
+use aliased 'Reaction::UI::ViewPort::ListViewWithSearch';
+use aliased 'Reaction::UI::ViewPort::Action' => 'ActionVP';
+use aliased 'Reaction::UI::ViewPort::Collection::Role::Pager', 'PagerRole';
+
+use Method::Signatures::Simple;
+
+use namespace::clean -except => 'meta';
+
+extends 'Reaction::UI::ViewPort';
+
+has 'listview' => (
+ isa => ListViewWithSearch,
+ is => 'ro',
+ required => 1,
+);
+
+has 'search_form' => (isa => ActionVP, is => 'ro', required => 1);
+
+override BUILDARGS => sub {
+ my $args = super;
+ my $spec_event_id = $args->{location}.':search-spec';
+ my $spec_class = $args->{spec_class}
+ or confess "Argument spec_class is required";
+ my $action_class = $args->{action_class}
+ or confess "Argument action_class is required";
+# TODO: how do we autodiscover spec classes?
+# $spec_class =~ s/^::/${\SearchSpec}::/;
+ Class::MOP::load_class($spec_class);
+ my $spec = do {
+ if (my $string = $args->{ctx}->req->query_params->{$spec_event_id}) {
+ $spec_class->from_string($string, $args->{spec}||{});
+ } else {
+ $spec_class->new($args->{spec}||{});
+ }
+ };
+ my $listview_location = $args->{location}.'-listview';
+ # should this maybe use the listview class in $args->{listview}?
+ my $listview = $args->{listview} = ListViewWithSearch->new(
+ %$args,
+ layout => 'list_view',
+ search_spec => $spec,
+ location => $listview_location,
+ );
+ # same as with listview wrt. class name
+ $args->{search_form} = ActionVP->new(
+ model => $action_class->new(target_model => $spec),
+ location => $args->{location}.'-search_form',
+ apply_label => 'search',
+ ctx => $args->{ctx},
+ on_apply_callback => sub {
+ my ($vp, $spec) = @_;
+ my $req = $vp->ctx->req;
+ my $new_uri = $req->uri->clone;
+ my %query = %{$req->query_parameters};
+ delete @query{grep /^\Q${listview_location}\E/, keys %query};
+ $query{$spec_event_id} = $spec->to_string;
+ $new_uri->query_form(\%query);
+ $req->uri($new_uri);
+ $listview->clear_page;
+ $listview->clear_order_by;
+ },
+ %{$args->{search}||{}}
+ );
+ $args;
+};
+
+override child_event_sinks => method () {
+ ((map $self->$_, 'listview', 'search_form'), super);
+};
+
+1;
+