renaming widget packages to match new viewports
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Collection / Grid.pm
CommitLineData
ddccc6a2 1package Reaction::UI::ViewPort::Collection::Grid;
2
3use Reaction::Class;
4
5use aliased 'Reaction::InterfaceModel::Collection' => 'IM_Collection';
6use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member';
7
8class Grid is 'Reaction::UI::ViewPort::Collection', which {
9
10 has field_order => ( isa => 'ArrayRef', is => 'ro', lazy_build => 1);
11 has field_labels => ( isa => 'HashRef', is => 'ro', lazy_build => 1);
12
13 has ordered_fields => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
14 has excluded_fields => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
15
16 ####################################
17 implements _build_member_class => as { };
18
19 implements _build_field_labels => as {
20 my $self = shift;
21 my %labels;
22 for my $field ( @{$self->field_order}){
23 $labels{$field} = join(' ', map{ ucfirst } split('_', $field));
24 }
25 return \%labels;
26 };
27
28 implements _build_ordered_fields => as {
29 my ($self) = @_;
30 confess("current_collection lacks a value for 'member_type' attribute")
31 unless $self->current_collection->has_member_type;
32 my %excluded = map { $_ => undef } @{ $self->excluded_fields };
33 #treat _$field_name as private and exclude fields with no reader
34 my @names = grep { $_ !~ /^_/ && !exists($exclude{$_})} map { $_->name }
35 grep { defined $_->get_read_method }
36 $self->current_collection->member_type->meta->parameter_attributes;
37 return $self->sort_by_spec($self->field_order, \@names);
38 };
39
40 before _build_members => sub {
41 my ($self) = @_;
42 $self->member_args->{ordered_fields} ||= $self->ordered_fields;
43 };
44
45};
46
47
48
491;