Guest User

Untitled

a guest
Apr 26th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package MyApp::Controller::Foo;
  2.  
  3. use Moose;
  4. BEGIN { extends 'Reaction::Controller'; }
  5.  
  6. #Import the capabilities we need
  7. with(
  8. 'Reaction::UI::Controller::Role::GetCollection', #automatically fetch a model
  9. 'Reaction::UI::Controller::Role::Action::Simple', # for Create / View etc
  10. 'Reaction::UI::Controller::Role::Action::Object', #load object based on URI
  11. 'Reaction::UI::Controller::Role::Action::View', #display a view page
  12. 'Reaction::UI::Controller::Role::Action::List', #display a list page
  13. 'Reaction::UI::Controller::Role::Action::Create' #create page
  14. );
  15.  
  16. #set up the URIs for our actions and our model / collection
  17. __PACKAGE__->config(
  18. model_name => 'MyInterfaceModel',
  19. collection_name => 'Foo',
  20. action => {
  21. base => { Chained => '/base', PathPart => '/foo' },
  22. create => { Chained => 'base', },
  23. list => { Chained => 'base', PathPart => '' },
  24. object => { Chained => 'base', PathPart => 'id' },
  25. view => { Chained => 'object', },
  26. },
  27. );
  28.  
  29. #different behaviors for Apply / OK buttons
  30. sub on_create_apply_callback {
  31. my ($self, $c, $vp, $result) = @_;
  32. $c->res->redirect($c->uri_for( $self->action_for('view'), [ $result->id ] ));
  33. }
  34.  
  35. sub on_create_close_callback {
  36. my($self, $c, $vp) = @_;
  37. $c->res->redirect($c->uri_for( $self->action_for('list') ));
  38. }
  39.  
  40. #automatically create links on the 'list' page for viewing and creating items
  41. sub _build_action_viewport_args {
  42. my $self = shift;
  43. {
  44. list => {
  45. action_prototypes => {
  46. create => {
  47. label => 'create',
  48. uri => sub {
  49. my($collection, $ctx) = @_;
  50. $ctx->uri_for($self->action_for('create'));
  51. }
  52. },
  53. },
  54. Member => {
  55. action_prototypes => {
  56. view => {
  57. label => 'view',
  58. uri => sub {
  59. my($obj, $ctx) = @_;
  60. $ctx->uri_for($self->action_for('view'), [ $obj->id ]);
  61. }
  62. },
  63. }
  64. }
  65. }
  66. }
  67.  
  68. 1;
  69.  
  70. __END__;
Add Comment
Please, Sign In to add comment