fixup widgets to use fragment
[catagits/Reaction.git] / lib / Reaction / UI / Widget / ListView.pm
CommitLineData
7adfd53f 1package Reaction::UI::Widget::ListView;
2
3use Reaction::UI::WidgetClass;
7adfd53f 4
e22de101 5class ListView is 'Reaction::UI::Widget::GridView', which {
6bc27bd3 6 fragment widget [ qw/pager header body footer actions/,
b8faba69 7 {
8 pager => sub{ $_{viewport}->pager },
9 object_action_count => sub{ $_{viewport}->object_action_count },
10 #^^ it's ugly, i know, but i gotsto
11 }
12 ];
7adfd53f 13
6bc27bd3 14 fragment pager
b8faba69 15 [ qw/first_page previous_page current_page next_page last_page page_list/,
16 {
17 first_page => sub{ $_{pager}->first_page },
5753475a 18 previous_page => sub{ $_{pager}->previous_page || $_{pager}->last_page },
b8faba69 19 current_page => sub{ $_{pager}->current_page },
5753475a 20 next_page => sub{ $_{pager}->next_page || $_{pager}->first_page },
b8faba69 21 last_page => sub{ $_{pager}->last_page },
22 page_list => sub{ [$_{pager}->first_page .. $_{pager}->last_page] },
23 }
24 ];
25
6bc27bd3 26 fragment first_page [ string{ "First" } ],
b8faba69 27 { uri => sub{ $_{self}->connect_uri( {page => $_{first_page} } ) } };
28
6bc27bd3 29 fragment previous_page [ string{ "Previous" } ],
b8faba69 30 { uri => sub{ $_{self}->connect_uri( {page => $_{previous_page} } ) } };
31
6bc27bd3 32 fragment current_page [ string{ "Current" } ],
b8faba69 33 { uri => sub{ $_{self}->connect_uri( {page => $_{current_page} } ) } };
34
6bc27bd3 35 fragment next_page [ string{ "Next" } ],
b8faba69 36 { uri => sub{ $_{self}->connect_uri( {page => $_{next_page} } ) } };
37
6bc27bd3 38 fragment last_page [ string{ "Last" } ],
b8faba69 39 { uri => sub{ $_{self}->connect_uri( {page => $_{last_page} } ) } };
40
6bc27bd3 41 fragment page_list [ page over $_{page_list} ];
42 fragment page [ string{ $_ } ],
b8faba69 43 { uri => sub{ $_{self}->connect_uri( {page => $_ } ) } };
44
6bc27bd3 45 fragment actions [ action over func(viewport => 'actions') ];
46 fragment action [ 'viewport' ];
b8faba69 47
6bc27bd3 48 fragment header_cell [ string { $_{labels}->{$_} } ],
b8faba69 49 { uri => sub{
50 my $ev = {order_by => $_, order_by_desc => $_{viewport}->order_by_desc ? 0 : 1 };
51 return $_{self}->connect_uri($ev);
52 }
53 };
54
6bc27bd3 55 fragment footer_cell [ string { $_{labels}->{$_} } ],
b8faba69 56 { uri => sub{
57 my $ev = {order_by => $_, order_by_desc => $_{viewport}->order_by_desc ? 0 : 1 };
58 return $_{self}->connect_uri($ev);
59 }
60 };
61
62 #this needs to be cleaned up and moved out
63 implements connect_uri => as{
64 my ($self, $events) = @_;
65 my $vp = $self->viewport;
66 my $ctx = $self->viewport->ctx;
67 my %args = map{ $vp->event_id_for($_) => $events->{$_} } keys %$events;
68 return $ctx->req->uri_with(\%args);
69 };
7adfd53f 70
71};
72
731;