aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-10-11 21:15:47 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2008-10-11 21:15:47 +0000
commit37728bbad6840485e4d0e3a504dfdc851e7378c3 (patch)
tree0b971b7451c5fff6e554090f22ff881005729d5f /lib/Reaction/UI/ViewPort
parent487c32080762a25ad34c785dc39753cbc941d355 (diff)
downloadreaction-37728bbad6840485e4d0e3a504dfdc851e7378c3.tar.gz
reaction-37728bbad6840485e4d0e3a504dfdc851e7378c3.zip
completely new way of handling action prototypes for actions in CRUD that is much saner and less reliant on $ctx. also more flexible and configurable
Diffstat (limited to 'lib/Reaction/UI/ViewPort')
-rw-r--r--lib/Reaction/UI/ViewPort/Collection/Grid.pm17
-rw-r--r--lib/Reaction/UI/ViewPort/Role/Actions.pm61
2 files changed, 54 insertions, 24 deletions
diff --git a/lib/Reaction/UI/ViewPort/Collection/Grid.pm b/lib/Reaction/UI/ViewPort/Collection/Grid.pm
index 95e341e..6d8e0a1 100644
--- a/lib/Reaction/UI/ViewPort/Collection/Grid.pm
+++ b/lib/Reaction/UI/ViewPort/Collection/Grid.pm
@@ -35,8 +35,7 @@ has member_action_count => (
my $self = shift;
for (@{ $self->members }) {
my $protos = $_->action_prototypes;
- return scalar(@$protos);
- #return scalar(keys(%$protos));
+ return scalar(keys(%$protos));
}
return 1;
},
@@ -83,16 +82,16 @@ 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} ||= [];
+ $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;
-# }
+ 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;
};
diff --git a/lib/Reaction/UI/ViewPort/Role/Actions.pm b/lib/Reaction/UI/ViewPort/Role/Actions.pm
index 7da0072..a8e6e28 100644
--- a/lib/Reaction/UI/ViewPort/Role/Actions.pm
+++ b/lib/Reaction/UI/ViewPort/Role/Actions.pm
@@ -1,33 +1,64 @@
package Reaction::UI::ViewPort::Role::Actions;
use Reaction::Role;
-use Reaction::UI::ViewPort::Action::Link;
+use Reaction::UI::ViewPort::URI;
use namespace::clean -except => [ qw(meta) ];
+has actions => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ lazy_build => 1
+);
+
+has action_order => (
+ is => 'ro',
+ isa => 'ArrayRef'
+);
+
+has action_prototypes => (
+ is => 'ro',
+ isa => 'HashRef',
+ required => 1,
+ default => sub{ {} }
+);
+
+has computed_action_order => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ lazy_build => 1
+);
+
+sub _build_computed_action_order {
+ my $self = shift;
+ my $ordered = $self->sort_by_spec(
+ ($self->has_action_order ? $self->action_order : []),
+ [ keys %{ $self->action_prototypes } ]
+ );
+ return $ordered ;
+}
-has actions => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
-has action_prototypes => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
-sub _build_action_prototypes { [] };
sub _build_actions {
my ($self) = @_;
my (@act, $i);
my $ctx = $self->ctx;
my $loc = $self->location;
- foreach my $proto (@{ $self->action_prototypes }) {
- my $action = Reaction::UI::ViewPort::Action::Link->new
- (
- ctx => $ctx,
- target => $self->model,
- location => join ('-', $loc, 'action', $i++),
- %$proto,
- );
+ my $target = $self->model;
+
+ foreach my $proto_name ( @{ $self->computed_action_order } ) {
+ my $proto = $self->action_prototypes->{$proto_name};
+ my $uri = $proto->{uri} or confess('uri is required in prototype action');
+ my $label = exists $proto->{label} ? $proto->{label} : $proto_name;
+
+ my $action = Reaction::UI::ViewPort::URI->new(
+ location => join ('-', $loc, 'action', $i++),
+ uri => ( ref($uri) eq 'CODE' ? $uri->($target, $ctx) : $uri ),
+ display => ( ref($label) eq 'CODE' ? $label->($target, $ctx) : $label ),
+ );
push(@act, $action);
}
return \@act;
-};
-
-
+}
1;