ObjectView converted
[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" } ],
097e8442 27 { uri => sub{ $_{self}->connect_uri( {page => $_{first_page} }, $_{viewport} ) } };
b8faba69 28
6bc27bd3 29 fragment previous_page [ string{ "Previous" } ],
097e8442 30 { uri => sub{ $_{self}->connect_uri( {page => $_{previous_page} }, $_{viewport} ) } };
b8faba69 31
6bc27bd3 32 fragment current_page [ string{ "Current" } ],
097e8442 33 { uri => sub{ $_{self}->connect_uri( {page => $_{current_page} }, $_{viewport} ) } };
b8faba69 34
6bc27bd3 35 fragment next_page [ string{ "Next" } ],
097e8442 36 { uri => sub{ $_{self}->connect_uri( {page => $_{next_page} }, $_{viewport} ) } };
b8faba69 37
6bc27bd3 38 fragment last_page [ string{ "Last" } ],
097e8442 39 { uri => sub{ $_{self}->connect_uri( {page => $_{last_page} }, $_{viewport} ) } };
b8faba69 40
27ebb686 41 fragment page_list [ page => over $_{page_list} ];
6bc27bd3 42 fragment page [ string{ $_ } ],
097e8442 43 { uri => sub{ $_{self}->connect_uri( {page => $_ }, $_{viewport} ) } };
b8faba69 44
27ebb686 45 fragment actions [ action => over func(viewport => 'actions') ];
6bc27bd3 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 };
097e8442 51 return $_{self}->connect_uri($ev, $_{viewport});
b8faba69 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 };
097e8442 58 return $_{self}->connect_uri($ev, $_{viewport});
b8faba69 59 }
60 };
61
62 #this needs to be cleaned up and moved out
63 implements connect_uri => as{
097e8442 64 my ($self, $events, $vp) = @_;
65 my $ctx = $vp->ctx;
b8faba69 66 my %args = map{ $vp->event_id_for($_) => $events->{$_} } keys %$events;
67 return $ctx->req->uri_with(\%args);
68 };
7adfd53f 69
70};
71
721;