aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/GridView/Role/Actions.pm
blob: 11143857f4fee311b1f5d0a6149d9e791c49ca13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package Reaction::UI::ViewPort::GridView::Role::Actions;

use strict;
use warnings;

use Reaction::Role;
use Reaction::UI::ViewPort::GridView::Action;

role Actions, which {

  has actions => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
  has action_prototypes => (is => 'ro', isa => 'ArrayRef', lazy_build => 1);
  implements build_action_prototypes => as { [] };

  implements build_actions => as {
    my ($self) = @_;
    my (@act, $i);
    my $ctx = $self->ctx;
    #if i could abstract this vs ->object for row we could eliminate the entity
    #version of this role and just use one for both things. that would be cool.
    my $obj = $self->current_collection;
    my $loc = $self->location;
    foreach my $proto (@{ $self->action_prototypes }) {
      my $action = Reaction::UI::ViewPort::GridView::Action->new
        (
         ctx      => $ctx,
         target   => $obj,
         location => join ('-', $loc, 'action', $i++),
         %$proto,
        );
      push(@act, $action);
    }
    return \@act;
  };

};

1;