Reaction::UI::Controller::Collection::CRUD - Basic CRUD functionality for Reaction::InterfaceModel data


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::UI::Controller::Collection::CRUD - Basic CRUD functionality for Reaction::InterfaceModel data

DESCRIPTION

Top

Controller class which extends Reaction::UI::Controller::Collection to provide basic Create / Update / Delete / DeleteAll actions.

Building on the base of the Collection controller this controller allows you to easily create complex and highly flexible CRUD functionality for your InterfaceModel models by providing a simple way to render and process your custom InterfaceModel Actions and customize built-ins.

ROLES CONSUMED

Top

This role also consumes the following roles:

METHODS

Top

get_model_action $c, $action_name, $target_im

DEPRECATED. Get an instance of the $action_name InterfaceModel::Action for model $target This action is suitable for passing to an Action|Reaction::UI::ViewPort::Action viewport

basic_model_action $c, \%vp_args

DEPRECTAED extension to basic_page which automatically instantiates an InterfaceModel::Action with the right data target using get_model_action

after_create_callback $c, $vp, $result

When a <create> action is applied, move the user to the new object's, update page.

_build_action_viewport_map

Map list to ListView (Reaction::UI::ViewPort::ListView).

_build_default_member_actions

Add update and delete to the list of default actions.

_build_default_collection_actions

Add create and delete_all to the list of default actions.

ACTIONS

Top

create

Chained to base. See Reaction::UI::Controller::Role::Action::Create

delete_all

Chained to base. See Reaction::UI::Controller::Role::Action::DeleteAll

update

Chained to object. See Reaction::UI::Controller::Role::Action::Update

delete

Chained to object. See Reaction::UI::Controller::Role::Action::Delete

SEE ALSO

Top

Reaction::UI::Controller::Collection, Reaction::UI::Controller

AUTHORS

Top

See Reaction::Class for authors.

LICENSE

Top

See Reaction::Class for the license.


Reaction documentation Contained in the Reaction distribution.

package Reaction::UI::Controller::Collection::CRUD;

use Moose;
BEGIN { extends 'Reaction::UI::Controller::Collection'; }

use aliased 'Reaction::UI::ViewPort::ListView';

__PACKAGE__->config(
  action => {
    create => { Chained => 'base', },
    delete_all => { Chained => 'base', },
    update => { Chained => 'object', },
    delete => { Chained => 'object', },
  },
);

with(
  'Reaction::UI::Controller::Role::Action::Create',
  'Reaction::UI::Controller::Role::Action::Update',
  'Reaction::UI::Controller::Role::Action::Delete',
  'Reaction::UI::Controller::Role::Action::DeleteAll',
);

around _build_action_viewport_map => sub {
  my $orig = shift;
  my $map = shift->$orig( @_ );
  $map->{list} = ListView;
  return $map;
};

sub _build_default_member_actions {
  [ @{shift->next::method(@_)}, qw/update delete/ ];
}

sub _build_default_collection_actions {
  [ @{shift->next::method(@_)}, qw/create delete_all/ ];
}

##DEFAULT CALLBACKS

sub on_delete_all_close_callback {
  my($self, $c) = @_;
  $self->redirect_to($c, 'list');
}

sub on_create_apply_callback {
  my ($self, $c, $vp, $result) = @_;
  if( $self->can('after_create_callback') ){
    $c->log->debug("'after_create_callback' has been replaced with 'on_create_apply_callback' and is deprecated.");
    shift @_;
    return $self->after_create_callback(@_);
  }
  return $self->redirect_to
    ( $c, 'update', [ @{$c->req->captures}, $result->id ] );
}

sub on_create_close_callback {
  my($self, $c, $vp) = @_;
  $self->redirect_to( $c, 'list' );
}

sub on_update_close_callback {
  my($self, $c) = @_;
  #this needs a better solution. currently thinking about it
  my @cap = @{$c->req->captures};
  pop(@cap); # object id
  $self->redirect_to($c, 'list', \@cap);
}

sub on_delete_close_callback {
  my($self, $c) = @_;
  #this needs a better solution. currently thinking about it
  my @cap = @{$c->req->captures};
  pop(@cap); # object id
  $self->redirect_to($c, 'list', \@cap);
}

#### DEPRECATED METHODS

sub get_model_action {
  my ($self, $c, $name, $target) = @_;
  if( $c->debug ){
    my ($package,undef,$line,$sub_name,@rest) = caller(1);
    my $message = "The method 'get_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
    $c->log->debug( $message );
  }
  return $target->action_for($name, ctx => $c);
}

sub basic_model_action {
  my ($self, $c, $vp_args) = @_;
  if( $c->debug ){
    my ($package,undef,$line,$sub_name,@rest) = caller(1);
    my $message = "The method 'basic_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
    $c->log->debug( $message );
  }
  my $stash = $c->stash;
  my $target = delete $vp_args->{target};
  $target ||= ($stash->{object} || $stash->{collection} || $self->get_collection($c));

  my $action_name = join('', map{ ucfirst } split('_', $c->stack->[-1]->name));
  my $model = $self->get_model_action($c, $action_name, $target);
  return $self->basic_page($c, { model => $model, %{$vp_args||{}} });
}

1;

__END__