=head1 NAME
-Reaction::UI::Widget::Controller
+Reaction::UI::Controller
=head1 DESCRIPTION
=head2 model_name
-The name of the model this controller will use as it's data source. Should be a name
-that can be passed to C<$C-E<gt>model>
+The name of the model this controller will use as it's data source. Should be a
+name that can be passed to C<$C-E<gt>model>
=head2 collection_name
-The name of the collection whithin the model that this Controller will be utilizing.
+The name of the collection whithin the model that this Controller will be
+utilizing.
=head2 action_viewport_map
=back
-Read-write lazy building hashref. The keys should match action names in the Controller
-and the value should be the ViewPort class that this action should use.
- See method C<basic_page> for more info.
+Read-write lazy building hashref. The keys should match action names in the
+Controller and the value should be the ViewPort class that this action should
+use. See method C<basic_page> for more info.
=head action_viewport_args
-Read-write lazy building hashref. Additional ViewPort arguments for the action named
-as the key in the controller. See method C<basic_page> for more info.
+Read-write lazy building hashref. Additional ViewPort arguments for the action
+named as the key in the controller. See method C<basic_page> for more info.
=over 4
Returns an empty hashref.
+=head2 basic_page $c, \%vp_args
+
+Accepts two arguments, context, and a hashref of viewport arguments. It will
+automatically determine the action name using the catalyst stack and call
+C<push_viewport> with the ViewPort class name contained in the
+C<action_viewport_map> with a set of options determined by merging C<$vp_args>
+and the arguments contained in C<action_viewport_args>, if any.
+
=head1 ACTIONS
=head2 base
=head2 list
-Chain link, chained to C<base> forwards to basic page passing one custom argument,
-C<collection> which includes an instance of the current collection.
+Chain link, chained to C<base>. C<list> fetches the collection for the model
+and calls C<basic_page> with a single argument, C<collection>.
-The default ViewPort for this action is C<Reaction::UI::ViewPort::ListView> and can be
-changed by altering the C<action_viewport_map> attribute hash.
+The default ViewPort for this action is C<Reaction::UI::ViewPort::ListView> and
+can be changed by altering the C<action_viewport_map> attribute hash.
=head2 object
-Chain link, chained to C<base>, captures one argument, 'id'. Attempts to find a single
-object by searching for a member of the current collection which has a Primary Key or
-Unique constraint matching that argument. If the object is found it is stored in the
- stash under the C<object> key.
+Chain link, chained to C<base>, captures one argument, 'id'. Attempts to find
+a single object by searching for a member of the current collection which has a
+Primary Key or Unique constraint matching that argument. If the object is found
+it is stored in the stash under the C<object> key.
=head2 view
-Chain link, chained to C<object>. Forwards to C<basic page> with one custom vp argument
- of C<object>, which is the object located in the previous chain link of the same name.
+Chain link, chained to C<object>. Calls C<basic page> with one argument,
+C<model>, which contains an instance of the object fetched by the C<object>
+action link.
-The default ViewPort for this action is C<Reaction::UI::ViewPort::Object> and can be
-changed by altering the C<action_viewport_map> attribute hash.
+The default ViewPort for this action is C<Reaction::UI::ViewPort::Object> and
+can be changed by altering the C<action_viewport_map> attribute hash.
-=head2 basic_page
+=SEE ALSO
-Private action, accepts one argument, a hashref of viewport arguments (C<$vp_args>).
- It will automatically determine the action name using the catalyst stack and call
-C<push_viewport> with the ViewPort class name contained in the C<action_viewport_map>
-and arguments of C<$vp_args> and the arguments contained in C<action_viewport_args>,
-if any.
+L<Reaction::UI::Controller>
=head1 AUTHORS
sub delete :Chained('object') :Args(0) {
my ($self, $c) = @_;
#this needs a better solution. currently thinking about it
- my @cap = @{$c->req->captures};
+ my @cap = @{$c->req->captures};
pop(@cap); # object id
my $vp_args = { next_action => [ $self, 'redirect_to', 'list', \@cap ]};
$self->basic_model_action( $c, $vp_args);
my $target = exists $c->stash->{object} ?
$c->stash->{object} : $self->get_collection($c);
- my $cat_action_name = $c->stack->[-1]->name;
- my $im_action_name = join('', (map{ ucfirst } split('_', $cat_action_name)));
- return $self->push_viewport
- (
- $self->action_viewport_map->{$cat_action_name},
- model => $self->get_model_action($c, $im_action_name, $target),
- %{ $vp_args || {} },
- %{ $self->action_viewport_args->{$cat_action_name} || {} },
- );
+ 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 });
}
1;
+
+__END__
+
+=head1 NAME
+
+Reaction::UI::Controller::CRUD - Basic CRUD functionality for Reaction::InterfaceModel data
+
+=head1 DESCRIPTION
+
+Controller class which extends L<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.
+
+=head1 METHODS
+
+=head2 get_model_action $c, $action_name, $target_im
+
+Get an instance of the C<$action_name>
+L<InterfaceModel::Action|Reaction::InterfaceModel::Action> for model C<$target>
+This action is suitable for passing to an
+C<Action|Reaction::UI::ViewPort::Action> viewport
+
+=head2 after_create_callback $c, $vp, $result
+
+When a <create> action is applied, move the user to the new object's,
+C<update> page.
+
+=head2 basic_model_action $c, \%vp_args
+
+Extension to C<basic_page> which automatically instantiates an
+L<InterfaceModel::Action|Reaction::InterfaceModel::Action> with the right
+data target using C<get_model_action>
+
+=head2 _build_action_viewport_map
+
+Map C<create>, C<update>, C<delete> and C<delete_all> to use the
+C<Action|Reaction::UI::ViewPort::Action> viewport by default.
+
+=head2 _build_action_viewport_args
+
+Add action_prototypes to the C<list> action so that action links render correctly in L<ListView|Rection::UI::ViewPort::Listview>.
+
+=head1 ACTIONS
+
+=head2 create
+
+Chaned to C<base>. Create a new member of the collection represented by
+this controller. By default it attaches the C<after_create_callback> to
+DWIM after apply operations.
+
+See L<Create|Reaction::InterfaceModel::Action::DBIC::ResultSet::Create>
+ for more info.
+
+=head2 delete_all
+
+Chained to B<base>, delete all the members of the B<collection>. In most cases
+this is very much like a C<TRUNCATE> operation.
+
+See L<DeleteAll|Reaction::InterfaceModel::Action::DBIC::ResultSet::DeleteAll>
+ for more info.
+
+=head2 update
+
+Chained to C<object>, update a single object.
+
+See L<Update|Reaction::InterfaceModel::Action::DBIC::Result::Update>
+ for more info.
+
+=head2 delete
+
+Chained to C<object>, deletee a single object.
+
+
+See L<Delete|Reaction::InterfaceModel::Action::DBIC::Result::Delete>
+ for more info.
+
+=head1 SEE ALSO
+
+L<Reaction::UI::Controller::Collection>, L<Reaction::UI::Controller>
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut