1 package Reaction::UI::ViewPort::Action;
5 use MooseX::Types::URI qw/Uri/;
6 use MooseX::Types::Moose qw/Int Str/;
7 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
9 use namespace::clean -except => [ qw(meta) ];
11 extends 'Reaction::UI::ViewPort::Object::Mutable';
12 with 'Reaction::UI::ViewPort::Action::Role::OK';
14 has message => (is => 'rw', isa => Str);
15 has '+model' => (handles => [qw/error_message has_error_message/]);
17 #this has to fucking go. it BLOWS.
20 isa => NonEmptySimpleStr,
21 default => sub { 'post' }
24 has action => ( is => 'rw', isa => Uri );
29 reader => 'is_changed',
35 foreach my $field ( @{ $self->fields } ) {
36 return 0 if $field->needs_sync;
37 # if e.g. a datetime field has an invalid value that can't be re-assembled
38 # into a datetime object, the action may be in a consistent state but
39 # not synchronized from the fields; in this case, we must not apply
41 return $self->model->can_apply;
45 shift->model->do_apply;
48 after apply_child_events => sub {
49 # interrupt here because fields will have been updated
51 $self->sync_action_from_fields;
54 sub sync_action_from_fields {
56 foreach my $field (@{$self->fields}) {
57 $field->sync_to_action; # get the field to populate the $action if possible
59 $self->model->sync_all;
60 foreach my $field (@{$self->fields}) {
61 $field->sync_from_action; # get errors from $action if applicable
65 after handle_events => sub {
66 my ($self, $events) = @_;
67 foreach my $event ($self->accept_events) {
68 unless (exists $events->{$event} ) {
69 # for <input type="image"... buttons
70 if ( exists $events->{"${event}.x"} && exists $events->{"${event}.y"} ) {
71 $self->_dump_event($event, $events->{$event}) if DEBUG_EVENTS;
72 $self->$event($events->{$event});
78 __PACKAGE__->meta->make_immutable;
86 Reaction::UI::ViewPort::Action - Provide user with a form with OK, Apply and Close.
90 $controller->push_viewport('Reaction::UI::ViewPort::Action',
91 model => $interface_model_action,
92 field_order => [qw( firstname lastname )],
93 excluded_fields => [qw( password )],
98 This subclass of L<Reaction::UI::ViewPort::Object::Mutable> is used for
99 rendering a complete form supporting Apply, Close and OK.
107 Inherited from L<Reaction::UI::ViewPort::Object::Mutable>. Must be a
108 L<Reaction::InterfaceModel::Action>.
110 Also handles C<error_message> and C<has_error_message> methods.
118 Returns true if a field has been edited.
124 Returns true if no field C<needs_sync> and the L</model> C<can_apply>.
128 Delegates to C<do_apply> on the L</model>, which is a
129 L<Reaction::InterfaceModel::Action>.
131 =head2 sync_action_from_fields
133 Firstly calls C<sync_to_action> on every L<Reaction::UI::ViewPort::Field::Mutable>
134 in L<fields|Reaction::UI::ViewPort::Object/fields>. Then it calls C<sync_all> on
135 the L<Reaction::InterfaceModel::Action> in L</model>. Next it will call
136 C<sync_from_action> on every field to repopulate them from the L</model>.
140 package MyApp::UI::ViewPort::Action;
142 use MooseX::Types::Moose qw( Int );
144 use namespace::clean -except => 'meta';
146 extends 'Reaction::UI::ViewPort::Action';
148 has render_timestamp => (
151 default => sub { time },
155 has '+field_order' => (default => sub {[qw( firstname lastname )]});
161 L<Reaction::UI::ViewPort>
163 L<Reaction::UI::ViewPort::Object>
165 L<Reaction::UI::ViewPort::Object::Mutable>
167 L<Reaction::InterfaceModel::Action::Role::Apply>
169 L<Reaction::InterfaceModel::Action::Role::Close>
171 L<Reaction::InterfaceModel::Action::Role::OK>
175 See L<Reaction::Class> for authors.
179 See L<Reaction::Class> for the license.