Reaction::UI::ViewPort::Action - Provide user with a form with OK, Apply and Close.


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::UI::ViewPort::Action - Provide user with a form with OK, Apply and Close.

SYNOPSIS

Top

  $controller->push_viewport('Reaction::UI::ViewPort::Action',
    model           => $interface_model_action,
    field_order     => [qw( firstname lastname )],
    excluded_fields => [qw( password )],
  );

DESCRIPTION

Top

This subclass of Reaction::UI::ViewPort::Object::Mutable is used for rendering a complete form supporting Apply, Close and OK.

ATTRIBUTES

Top

message

model

Inherited from Reaction::UI::ViewPort::Object::Mutable. Must be a Reaction::InterfaceModel::Action.

Also handles error_message and has_error_message methods.

method

post / get

changed

Returns true if a field has been edited.

METHODS

Top

can_apply

Returns true if no field needs_sync and the model can_apply.

do_apply

Delegates to do_apply on the model, which is a Reaction::InterfaceModel::Action.

sync_action_from_fields

Firstly calls sync_to_action on every Reaction::UI::ViewPort::Field::Mutable in fields. Then it calls sync_all on the Reaction::InterfaceModel::Action in model. Next it will call sync_from_action on every field to repopulate them from the model.

SUBCLASSING

Top

  package MyApp::UI::ViewPort::Action;
  use Reaction::Class;
  use MooseX::Types::Moose qw( Int );

  use namespace::clean -except => 'meta';

  extends 'Reaction::UI::ViewPort::Action';

  has render_timestamp => (
    is       => 'ro',
    isa      => Int,
    default  => sub { time },
    required => 1,
  );

  has '+field_order' => (default => sub {[qw( firstname lastname )]});

  1;

SEE ALSO

Top

Reaction::UI::ViewPort

Reaction::UI::ViewPort::Object

Reaction::UI::ViewPort::Object::Mutable

Reaction::InterfaceModel::Action::Role::Apply

Reaction::InterfaceModel::Action::Role::Close

Reaction::InterfaceModel::Action::Role::OK

AUTHORS

Top

See Reaction::Class for authors.

LICENSE

Top

See Reaction::Class for the license.


Reaction documentation Contained in the Reaction distribution.

package Reaction::UI::ViewPort::Action;

use Reaction::Class;

use MooseX::Types::URI qw/Uri/;
use MooseX::Types::Moose qw/Int Str/;
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;

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

extends 'Reaction::UI::ViewPort::Object::Mutable';
with 'Reaction::UI::ViewPort::Action::Role::OK';

has message => (is => 'rw', isa => Str);
has '+model' => (handles => [qw/error_message has_error_message/]);

#this has to fucking go. it BLOWS.
has method => (
  is => 'rw',
  isa => NonEmptySimpleStr,
  default => sub { 'post' }
);

has action => ( is => 'rw', isa => Uri );

has changed => (
  is => 'rw',
  isa => Int,
  reader => 'is_changed',
  default => sub{0}
);

sub can_apply {
  my ($self) = @_;
  foreach my $field ( @{ $self->fields } ) {
    return 0 if $field->needs_sync;
    # if e.g. a datetime field has an invalid value that can't be re-assembled
    # into a datetime object, the action may be in a consistent state but
    # not synchronized from the fields; in this case, we must not apply
  }
  return $self->model->can_apply;
}

sub do_apply {
  shift->model->do_apply;
}

after apply_child_events => sub {
  # interrupt here because fields will have been updated
  my ($self) = @_;
  $self->sync_action_from_fields;
};

sub sync_action_from_fields {
  my ($self) = @_;
  foreach my $field (@{$self->fields}) {
    $field->sync_to_action; # get the field to populate the $action if possible
  }
  $self->model->sync_all;
  foreach my $field (@{$self->fields}) {
    $field->sync_from_action; # get errors from $action if applicable
  }
}

__PACKAGE__->meta->make_immutable;

1;

__END__;