diff options
author | wreis <wreis@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-07-31 12:04:55 +0000 |
---|---|---|
committer | wreis <wreis@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-07-31 12:04:55 +0000 |
commit | 463e51d0379bb139a9d5de856756b21655e6a259 (patch) | |
tree | ed5d67efb1a34a4ed7f3dc5c6e81882d3aad5121 /lib/Reaction/UI/ViewPort/Collection | |
parent | 372fcc324af7c081194fe09ae72d4607d6a370ac (diff) | |
download | reaction-463e51d0379bb139a9d5de856756b21655e6a259.tar.gz reaction-463e51d0379bb139a9d5de856756b21655e6a259.zip |
factoring out for field args from Collection::Grid
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Collection')
-rw-r--r-- | lib/Reaction/UI/ViewPort/Collection/Grid.pm | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/lib/Reaction/UI/ViewPort/Collection/Grid.pm b/lib/Reaction/UI/ViewPort/Collection/Grid.pm index eb10d3d..d24b96e 100644 --- a/lib/Reaction/UI/ViewPort/Collection/Grid.pm +++ b/lib/Reaction/UI/ViewPort/Collection/Grid.pm @@ -9,24 +9,7 @@ use namespace::clean -except => [ qw(meta) ]; use MooseX::Types::Moose qw/ArrayRef HashRef Int/; extends 'Reaction::UI::ViewPort::Collection'; -has field_order => ( is => 'ro', isa => ArrayRef, lazy_build => 1); -has excluded_fields => ( is => 'ro', isa => ArrayRef, lazy_build => 1); -has included_fields => ( is => 'ro', isa => ArrayRef, lazy_build => 1); -has computed_field_order => (is => 'ro', isa => ArrayRef, lazy_build => 1); - -has _raw_field_labels => ( - is => 'rw', - isa => HashRef, - init_arg => 'field_labels', - default => sub { {} }, -); - -has field_labels => ( - is => 'ro', - isa => HashRef, - lazy_build => 1, - init_arg => undef, -); +with 'Reaction::UI::ViewPort::Role::FieldArgs'; has member_action_count => ( is => 'rw', @@ -43,65 +26,8 @@ has member_action_count => ( }, ); -#################################### sub _build_member_class { Member }; -sub _build_field_labels { - my $self = shift; - my %labels = %{$self->_raw_field_labels}; - for my $field ( @{$self->computed_field_order}) { - next if defined $labels{$field}; - $labels{$field} = join(' ', map{ ucfirst } split('_', $field)); - } - return \%labels; -} - -sub _build_field_order { []; } - -sub _build_excluded_fields { []; } - -sub _build_included_fields { [] } - -#this is a total clusterfuck and it sucks we should just eliminate it and have -# the grid members not render ArrayRef or Collection fields -sub _build_computed_field_order { - my ($self) = @_; - my %excluded = map { $_ => undef } @{ $self->excluded_fields }; - my %included = map { $_ => undef } @{ $self->included_fields }; - #treat _$field_name as private and exclude fields with no reader - my @names = grep { $_ !~ /^_/ && (!%included || exists( $included{$_}) ) - && !exists($excluded{$_})} map { $_->name } - grep { - !($_->has_type_constraint && - ($_->type_constraint->is_a_type_of('ArrayRef') || - eval {$_->type_constraint->name->isa('Reaction::InterfaceModel::Collection')} || - eval { $_->_isa_metadata->isa('Reaction::InterfaceModel::Collection') } - ) - ) } - grep { defined $_->get_read_method } - $self->current_collection->member_type->parameter_attributes; - - return $self->sort_by_spec($self->field_order, \@names); -} - -around _build_members => sub { - my $orig = shift; - my $self = shift; - $self->member_args->{computed_field_order} ||= $self->computed_field_order; - $self->member_args->{computed_action_order} ||= []; - my $members = $self->$orig(@_); - - # cache everything yo - for my $member (@$members){ - $member->clear_computed_action_order; - my $order = $member->computed_action_order; - @{ $self->member_args->{computed_action_order} } = @$order; - last; - } - - return $members; -}; - __PACKAGE__->meta->make_immutable; |