Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MyApp::Controller::Foo;
- use Moose;
- BEGIN { extends 'Reaction::Controller'; }
- #Import the capabilities we need
- with(
- 'Reaction::UI::Controller::Role::GetCollection', #automatically fetch a model
- 'Reaction::UI::Controller::Role::Action::Simple', # for Create / View etc
- 'Reaction::UI::Controller::Role::Action::Object', #load object based on URI
- 'Reaction::UI::Controller::Role::Action::View', #display a view page
- 'Reaction::UI::Controller::Role::Action::List', #display a list page
- 'Reaction::UI::Controller::Role::Action::Create' #create page
- );
- #set up the URIs for our actions and our model / collection
- __PACKAGE__->config(
- model_name => 'MyInterfaceModel',
- collection_name => 'Foo',
- action => {
- base => { Chained => '/base', PathPart => '/foo' },
- create => { Chained => 'base', },
- list => { Chained => 'base', PathPart => '' },
- object => { Chained => 'base', PathPart => 'id' },
- view => { Chained => 'object', },
- },
- );
- #different behaviors for Apply / OK buttons
- sub on_create_apply_callback {
- my ($self, $c, $vp, $result) = @_;
- $c->res->redirect($c->uri_for( $self->action_for('view'), [ $result->id ] ));
- }
- sub on_create_close_callback {
- my($self, $c, $vp) = @_;
- $c->res->redirect($c->uri_for( $self->action_for('list') ));
- }
- #automatically create links on the 'list' page for viewing and creating items
- sub _build_action_viewport_args {
- my $self = shift;
- {
- list => {
- action_prototypes => {
- create => {
- label => 'create',
- uri => sub {
- my($collection, $ctx) = @_;
- $ctx->uri_for($self->action_for('create'));
- }
- },
- },
- Member => {
- action_prototypes => {
- view => {
- label => 'view',
- uri => sub {
- my($obj, $ctx) = @_;
- $ctx->uri_for($self->action_for('view'), [ $obj->id ]);
- }
- },
- }
- }
- }
- }
- 1;
- __END__;
Add Comment
Please, Sign In to add comment