1 package Reaction::UI::ViewPort::Action;
5 use MooseX::Types::Moose qw/Int Str/;
6 use Reaction::Types::Core qw/NonEmptySimpleStr/;
8 use namespace::clean -except => [ qw(meta) ];
10 extends 'Reaction::UI::ViewPort::Object::Mutable';
11 with 'Reaction::UI::ViewPort::Action::Role::OK';
13 has message => (is => 'rw', isa => Str);
14 has '+model' => (handles => [qw/error_message has_error_message/]);
16 #this has to fucking go. it BLOWS.
19 isa => NonEmptySimpleStr,
20 default => sub { 'post' }
26 reader => 'is_changed',
32 foreach my $field ( @{ $self->fields } ) {
33 return 0 if $field->needs_sync;
34 # if e.g. a datetime field has an invalid value that can't be re-assembled
35 # into a datetime object, the action may be in a consistent state but
36 # not synchronized from the fields; in this case, we must not apply
38 return $self->model->can_apply;
42 shift->model->do_apply;
45 after apply_child_events => sub {
46 # interrupt here because fields will have been updated
48 $self->sync_action_from_fields;
51 sub sync_action_from_fields {
53 foreach my $field (@{$self->fields}) {
54 $field->sync_to_action; # get the field to populate the $action if possible
56 $self->model->sync_all;
57 foreach my $field (@{$self->fields}) {
58 $field->sync_from_action; # get errors from $action if applicable
63 __PACKAGE__->meta->make_immutable;
71 Reaction::UI::ViewPort::Action - Provide user with a form with OK, Apply and Close.
75 $controller->push_viewport('Reaction::UI::ViewPort::Action',
76 model => $interface_model_action,
77 field_order => [qw( firstname lastname )],
78 excluded_fields => [qw( password )],
83 This subclass of L<Reaction::UI::ViewPort::Object::Mutable> is used for
84 rendering a complete form supporting Apply, Close and OK.
92 Inherited from L<Reaction::UI::ViewPort::Object::Mutable>. Must be a
93 L<Reaction::InterfaceModel::Action>.
95 Also handles C<error_message> and C<has_error_message> methods.
103 Returns true if a field has been edited.
109 Returns true if no field C<needs_sync> and the L</model> C<can_apply>.
113 Delegates to C<do_apply> on the L</model>, which is a
114 L<Reaction::InterfaceModel::Action>.
116 =head2 sync_action_from_fields
118 Firstly calls C<sync_to_action> on every L<Reaction::UI::ViewPort::Field::Mutable>
119 in L<fields|Reaction::UI::ViewPort::Object/fields>. Then it calls C<sync_all> on
120 the L<Reaction::InterfaceModel::Action> in L</model>. Next it will call
121 C<sync_from_action> on every field to repopulate them from the L</model>.
125 package MyApp::UI::ViewPort::Action;
127 use MooseX::Types::Moose qw( Int );
129 use namespace::clean -except => 'meta';
131 extends 'Reaction::UI::ViewPort::Action';
133 has render_timestamp => (
136 default => sub { time },
140 has '+field_order' => (default => sub {[qw( firstname lastname )]});
146 L<Reaction::UI::ViewPort>
148 L<Reaction::UI::ViewPort::Object>
150 L<Reaction::UI::ViewPort::Object::Mutable>
152 L<Reaction::InterfaceModel::Action::Role::Apply>
154 L<Reaction::InterfaceModel::Action::Role::Close>
156 L<Reaction::InterfaceModel::Action::Role::OK>
160 See L<Reaction::Class> for authors.
164 See L<Reaction::Class> for the license.