Customising Reaction::UI::Controller::Collection::CRUD behaviour

Setting a field automatically when creating a row

For example when a field in the newly created object needs to have a value based on some data from the current session or user.

sub create : Chained('base') : PathPart('create') : Args(0) {
  my $self      = shift;
  my ($c)       = @_;
  my $action_vp = $self->next::method(@_);
  $action_vp->model->some_field($some_value)
    unless $c->request->method eq 'POST'; 
}

If the field is non editable (that is, set in create => { ViewPort => { excluded_fields = [...] } }, the 'unless ...' part can be omitted.

Disabling the 'delete_all' action

sub _build_default_collection_actions {
  [ grep { $_ ne 'delete_all' } @{ shift->next::method(@_) } ];
}
sub delete_all { }

Adding the table name as a heading above tables

We need to add a heading to the ListView template. First create the template share/skin/$app/layout/list_view.tt

=extends NEXT

=for layout widget

[% heading %]

[% call_next %]

=for layout heading

<h1>[% name %]</h1>

=cut

Then create (or extend) your lib/$APP/UI/Widget/ListView.pm class. In this case the heading name is derived from the collection member_type.

package T365::UI::Widget::ListView;

use Reaction::UI::WidgetClass;

extends 'Reaction::UI::Widget::ListView';

use namespace::clean -except => [qw(meta)];

implements fragment heading {
  my $name = $_{viewport}->collection->member_type;
  $name =~ s/.*://;
  arg name => "$name list";
};

1;
My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker