aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Field
diff options
context:
space:
mode:
authormatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-02-02 16:18:31 +0000
committermatthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-02-02 16:18:31 +0000
commit11f21507776ad9c679045061bb82c9134244080e (patch)
tree17c81ad006ebd2f85470ff2944ec396e2257563f /lib/Reaction/UI/ViewPort/Field
parente1ca874ae8775187e9cb2bfa5714da872464eb51 (diff)
downloadreaction-11f21507776ad9c679045061bb82c9134244080e.tar.gz
reaction-11f21507776ad9c679045061bb82c9134244080e.zip
vestigial classes, nuked
Diffstat (limited to 'lib/Reaction/UI/ViewPort/Field')
-rw-r--r--lib/Reaction/UI/ViewPort/Field/ChooseMany.pm110
-rw-r--r--lib/Reaction/UI/ViewPort/Field/ChooseOne.pm122
2 files changed, 0 insertions, 232 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field/ChooseMany.pm b/lib/Reaction/UI/ViewPort/Field/ChooseMany.pm
deleted file mode 100644
index 8074fd8..0000000
--- a/lib/Reaction/UI/ViewPort/Field/ChooseMany.pm
+++ /dev/null
@@ -1,110 +0,0 @@
-package Reaction::UI::ViewPort::Field::ChooseMany;
-
-use Reaction::Class;
-
-class ChooseMany is 'Reaction::UI::ViewPort::Field::ChooseOne', which {
-
- #has '+layout' => (default => 'dual_select_group');
- has '+value' => (isa => 'ArrayRef');
-
- my $listify = sub { # quick utility function, $listify->($arg)
- return (defined($_[0])
- ? (ref($_[0]) eq 'ARRAY'
- ? $_[0] # \@arr => \@arr
- : [$_[0]]) # $scalar => [$scalar]
- : []); # undef => []
- };
-
- around value => sub {
- my $orig = shift;
- my $self = shift;
- if (@_) {
- my $value = $listify->(shift);
- if (defined $value) {
- $_ = $self->str_to_ident($_) for @$value;
- my $checked = $self->attribute->check_valid_value($self->action, $value);
- # i.e. fail if any of the values fail
- confess "Not a valid set of values"
- if (@$checked < @$value || grep { !defined($_) } @$checked);
-
- $value = $checked;
- }
- $orig->($self, $value);
- } else {
- $orig->($self);
- }
- };
-
- implements _empty_value => as { [] };
-
- implements is_current_value => as {
- my ($self, $check_value) = @_;
- my @our_values = @{$self->value||[]};
- $check_value = $self->obj_to_str($check_value) if ref($check_value);
- return grep { $self->obj_to_str($_) eq $check_value } @our_values;
- };
-
- implements current_value_choices => as {
- my $self = shift;
- my @all = grep { $self->is_current_value($_->{value}) } @{$self->value_choices};
- return [ @all ];
- };
-
- implements available_value_choices => as {
- my $self = shift;
- my @all = grep { !$self->is_current_value($_->{value}) } @{$self->value_choices};
- return [ @all ];
- };
-
- around handle_events => sub {
- my $orig = shift;
- my ($self, $events) = @_;
- my $ev_value = $listify->($events->{value});
- if (delete $events->{add_all_values}) {
- $events->{value} = [map {$self->obj_to_str($_)} @{$self->valid_values}];
- } elsif (exists $events->{add_values} && delete $events->{do_add_values}) {
- my $add = $listify->(delete $events->{add_values});
- $events->{value} = [ @{$ev_value}, @$add ];
- } elsif (delete $events->{remove_all_values}) {
- $events->{value} = [];
- }elsif (exists $events->{remove_values} && delete $events->{do_remove_values}) {
- my $remove = $listify->(delete $events->{remove_values});
- my %r = map { ($_ => 1) } @$remove;
- $events->{value} = [ grep { !$r{$_} } @{$ev_value} ];
- }
- return $orig->(@_);
- };
-
-};
-
-1;
-
-=head1 NAME
-
-Reaction::UI::ViewPort::Field::ChooseMany
-
-=head1 DESCRIPTION
-
-=head1 METHODS
-
-=head2 is_current_value
-
-=head2 current_values
-
-=head2 available_values
-
-=head2 available_value_names
-
-=head1 SEE ALSO
-
-=head2 L<Reaction::UI::ViewPort::Field>
-
-=head1 AUTHORS
-
-See L<Reaction::Class> for authors.
-
-=head1 LICENSE
-
-See L<Reaction::Class> for the license.
-
-=cut
diff --git a/lib/Reaction/UI/ViewPort/Field/ChooseOne.pm b/lib/Reaction/UI/ViewPort/Field/ChooseOne.pm
deleted file mode 100644
index a44314e..0000000
--- a/lib/Reaction/UI/ViewPort/Field/ChooseOne.pm
+++ /dev/null
@@ -1,122 +0,0 @@
-package Reaction::UI::ViewPort::Field::ChooseOne;
-
-use Reaction::Class;
-use URI;
-use Scalar::Util 'blessed';
-
-class ChooseOne is 'Reaction::UI::ViewPort::Field', which {
-
- #has '+layout' => (default => 'select');
-
- has valid_values => (isa => 'ArrayRef', is => 'ro', lazy_build => 1);
- has value_choices => (isa => 'ArrayRef', is => 'ro', lazy_build => 1);
-
- has value_map_method => (
- isa => 'Str', is => 'ro', required => 1, default => sub { 'display_name' },
- );
-
- around value => sub {
- my $orig = shift;
- my $self = shift;
- if (@_) {
- my $value = shift;
- if (defined $value) {
- if (!ref $value) {
- $value = $self->str_to_ident($value);
- }
- my $checked = $self->attribute->check_valid_value($self->action, $value);
- confess "${value} is not a valid value" unless defined($checked);
- $value = $checked;
- }
- $orig->($self, $value);
- } else {
- $orig->($self);
- }
- };
-
- implements _build_valid_values => as {
- my $self = shift;
- return [ $self->attribute->all_valid_values($self->action) ];
- };
-
- implements _build_value_choices => sub{
- my $self = shift;
- my @pairs = map{{value => $self->obj_to_str($_), name => $self->obj_to_name($_)}}
- @{ $self->valid_values };
- return [ sort { $a->{name} cmp $b->{name} } @pairs ];
- };
-
- implements is_current_value => as {
- my ($self, $check_value) = @_;
- my $our_value = $self->value;
- return unless ref($our_value);
- $check_value = $self->obj_to_str($check_value) if ref($check_value);
- return $self->obj_to_str($our_value) eq $check_value;
- };
-
- implements str_to_ident => as {
- my ($self, $str) = @_;
- my $u = URI->new('','http');
- $u->query($str);
- return { $u->query_form };
- };
-
- implements obj_to_str => as {
- my ($self, $obj) = @_;
- return $obj unless ref($obj);
- confess "${obj} not an object" unless blessed($obj);
- my $ident = $obj->ident_condition;
- my $u = URI->new('', 'http');
- $u->query_form(%$ident);
- return $u->query;
- };
-
- implements obj_to_name => as {
- my ($self, $obj) = @_;
- return $obj unless ref($obj);
- confess "${obj} not an object" unless blessed($obj);
- my $meth = $self->value_map_method;
- return $obj->$meth;
- };
-
-};
-
-1;
-
-=head1 NAME
-
-Reaction::UI::ViewPort::Field::ChooseOne
-
-=head1 DESCRIPTION
-
-=head1 METHODS
-
-=head2 is_current_value
-
-=head2 value
-
-=head2 valid_values
-
-=head2 valid_value_names
-
-=head2 value_to_name_map
-
-=head2 name_to_value_map
-
-=head2 str_to_ident
-
-=head2 obj_to_str
-
-=head1 SEE ALSO
-
-=head2 L<Reaction::UI::ViewPort::Field>
-
-=head1 AUTHORS
-
-See L<Reaction::Class> for authors.
-
-=head1 LICENSE
-
-See L<Reaction::Class> for the license.
-
-=cut