isa => 'HashRef', is => 'ro', default => sub { {} }
);
has ctx => (isa => 'Catalyst', is => 'ro'); #, required => 1);
+
sub _build_layout {
'';
-};
+}
+
sub create_tangent {
my ($self, $name) = @_;
my $t_map = $self->_tangent_stacks;
my $tangent = Reaction::UI::FocusStack->new(loc_prefix => $loc);
$t_map->{$name} = $tangent;
return $tangent;
-};
+}
+
sub focus_tangent {
my ($self, $name) = @_;
if (my $tangent = $self->_tangent_stacks->{$name}) {
} else {
return;
}
-};
+}
+
sub focus_tangents {
return keys %{shift->_tangent_stacks};
-};
+}
+
sub child_event_sinks {
my $self = shift;
return values %{$self->_tangent_stacks};
-};
+}
+
sub apply_events {
my ($self, $events) = @_;
return unless keys %$events;
$self->apply_child_events($events);
$self->apply_our_events($events);
-};
+}
+
sub apply_child_events {
my ($self, $events) = @_;
return unless keys %$events;
unless blessed($child) && $child->can('apply_events');
$child->apply_events($events);
}
-};
+}
+
sub apply_our_events {
my ($self, $events) = @_;
my @keys = keys %$events;
#warn "$self: events ".join(', ', %our_events)."\n";
$self->handle_events(\%our_events);
}
-};
+}
+
sub handle_events {
my ($self, $events) = @_;
my $exists = exists $events->{exists};
$self->$event($events->{$event});
}
}
-};
-sub accept_events { () };
-sub force_events { () };
+}
+
+sub accept_events { () }
+
+sub force_events { () }
+
sub event_id_for {
my ($self, $name) = @_;
return join(':', $self->location, $name);
-};
+}
+
sub sort_by_spec {
my ($self, $spec, $items) = @_;
return $items if not defined $spec;
}
return [sort {$order_map{$b} <=> $order_map{$a}} @$items];
-};
+}
__PACKAGE__->meta->make_immutable;
package Reaction::UI::ViewPort::Action;
use Reaction::Class;
+extends 'Reaction::UI::ViewPort::Object::Mutable';
-use aliased 'Reaction::UI::ViewPort::Object';
-
-BEGIN { *DEBUG_EVENTS = \&Reaction::UI::ViewPort::DEBUG_EVENTS; }
-
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::Text';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::Array';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::String';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::Number';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::Integer';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::Boolean';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::Password';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::DateTime';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseOne';
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseMany';
-
-use aliased 'Reaction::UI::ViewPort::Field::Mutable::File';
-#use aliased 'Reaction::UI::ViewPort::Field::Mutable::TimeRange';
-
-use Reaction::Types::Core qw/NonEmptySimpleStr/;
-
-use namespace::clean -except => [ qw(meta) ];
-extends Object;
-
-
-has model => (is => 'ro', isa => 'Reaction::InterfaceModel::Action', required => 1);
-#has '+model' => (isa => 'Reaction::InterfaceModel::Action');
-has method => ( isa => NonEmptySimpleStr, is => 'rw', default => sub { 'post' } );
-
-has on_apply_callback => (is => 'rw', isa => 'CodeRef');
-has on_close_callback => (is => 'rw', isa => 'CodeRef');
-
-has ok_label => (is => 'rw', isa => 'Str', lazy_build => 1);
-has apply_label => (is => 'rw', isa => 'Str', lazy_build => 1);
-has close_label => (is => 'rw', isa => 'Str', lazy_fail => 1);
-has close_label_close => (is => 'rw', isa => 'Str', lazy_build => 1);
-has close_label_cancel => (is => 'rw', isa => 'Str', lazy_build => 1);
-
-has changed => (is => 'rw', isa => 'Int', reader => 'is_changed', default => sub{0});
sub BUILD {
- my $self = shift;
- $self->close_label($self->close_label_close);
-};
-sub _build_ok_label { 'ok' };
-sub _build_apply_label { 'apply' };
-sub _build_close_label_close { 'close' };
-sub _build_close_label_cancel { 'cancel' };
-sub can_apply {
- my ($self) = @_;
- foreach my $field ( @{ $self->fields } ) {
- if ($field->needs_sync) {
- if (DEBUG_EVENTS) {
- $self->ctx->log->debug(
- "Failing out of can_apply on ${\ref($self)} at ${\$self->location}"
- ." because field for ${\$field->attribute->name} needs sync"
- );
- }
- return 0;
- }
- # 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
- }
- if (DEBUG_EVENTS) {
- my $ret = $self->model->can_apply;
- $self->ctx->log->debug(
- "model can_apply returned ${ret}"
- ." on ${\ref($self)} at ${\$self->location}"
- );
- return $ret;
- }
- return $self->model->can_apply;
-};
-sub do_apply {
- shift->model->do_apply;
-};
-sub ok {
- my $self = shift;
- $self->close(@_) if $self->apply(@_);
-};
-sub apply {
- my $self = shift;
- if ($self->can_apply && (my $result = $self->do_apply)) {
- $self->changed(0);
- $self->close_label($self->close_label_close);
- $self->on_apply_callback->($self => $result) if $self->has_on_apply_callback;
- return 1;
- } else {
- $self->changed(1);
- $self->close_label($self->close_label_cancel);
- return 0;
- }
-};
-sub close {
- my $self = shift;
- return unless $self->has_on_close_callback;
- $self->on_close_callback->($self);
-};
-sub can_close { 1 };
-
-override accept_events => sub {
- (($_[0]->has_on_close_callback ? ('ok', 'close') : ()), 'apply', super());
-}; # can't do a close-type operation if there's nowhere to go afterwards
-
-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
- }
-};
-sub _build_fields_for_type_Num {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => Number, %$args);
-};
-sub _build_fields_for_type_Int {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => Integer, %$args);
-};
-sub _build_fields_for_type_Bool {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => Boolean, %$args);
-};
-sub _build_fields_for_type_Reaction_Types_Core_SimpleStr {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => String, %$args);
-};
-sub _build_fields_for_type_Reaction_Types_File_File {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => File, %$args);
-};
-sub _build_fields_for_type_Str {
- my ($self, $attr, $args) = @_;
- if ($attr->has_valid_values) { # There's probably a better way to do this
- $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
- } else {
- $self->_build_simple_field(attribute => $attr, class => Text, %$args);
- }
-};
-sub _build_fields_for_type_Reaction_Types_Core_Password {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => Password, %$args);
-};
-sub _build_fields_for_type_Reaction_Types_DateTime_DateTime {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
-};
-sub _build_fields_for_type_Enum {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
-};
-
-#this needs to be fixed. somehow. beats the shit our of me. really.
-#implements build_fields_for_type_Reaction_InterfaceModel_Object => as {
-sub _build_fields_for_type_DBIx_Class_Row {
- my ($self, $attr, $args) = @_;
- $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
-};
-sub _build_fields_for_type_ArrayRef {
- my ($self, $attr, $args) = @_;
- if ($attr->has_valid_values) {
- $self->_build_simple_field(attribute => $attr, class => ChooseMany, %$args);
- } else {
- $self->_build_simple_field
- (
- attribute => $attr,
- class => Array,
- layout => 'field/mutable/hidden_array',
- %$args);
- }
-};
-
-#implements _build_fields_for_type_DateTime_Spanset => as {
-# my ($self, $attr, $args) = @_;
-# $self->_build_simple_field(attribute => $attr, class => TimeRange, %$args);
-#};
+ warn "This package is deprecated. please use 'Reaction::UI::ViewPort::Object::Mutable'";
+}
__PACKAGE__->meta->make_immutable;
+1;
- 1;
-
-=head1 NAME
-
-Reaction::UI::ViewPort::Action
-
-=head1 SYNOPSIS
-
- use aliased 'Reaction::UI::ViewPort::Action';
-
- $self->push_viewport(Action,
- layout => 'register',
- model => $action,
- next_action => [ $self, 'redirect_to', 'accounts', $c->req->captures ],
- ctx => $c,
- field_order => [
- qw / contact_title company_name email address1 address2 address3
- city country post_code telephone mobile fax/ ],
- );
-
-=head1 DESCRIPTION
-
-This subclass of L<Reaction::UI::ViewPort::Object> is used for rendering a
-collection of C<Reaction::UI::ViewPort::Field::Mutable::*> objects for user editing.
-
-=head1 ATTRIBUTES
-
-=head2 model
-
-L<Reaction::InterfaceModel::Action>
-
-=head2 ok_label
-
-Default: 'ok'
-
-=head2 apply_label
-
-Default: 'apply'
-
-=head2 close_label_close
-
-Default: 'close'
-
-=head2 close_label_cancel
-
-This label is only shown when C<changed> is true.
-
-Default: 'cancel'
-
-=head2 fields
-
-=head2 can_apply
-
-=head2 can_close
-
-=head2 changed
-
-Returns true if a field has been edited.
-
-=head2 next_action
-
-=head2 on_apply_callback
-
-CodeRef.
-
-=head1 METHODS
-
-=head2 ok
-
-Calls C<apply>, and then C<close> if successful.
-
-=head2 close
-
-Pop viewport and proceed to C<next_action>.
-
-=head2 apply
-
-Attempt to save changes and update C<changed> attribute if required.
-
-=head1 SEE ALSO
-
-L<Reaction::UI::ViewPort::Object>
-
-L<Reaction::UI::ViewPort>
-
-L<Reaction::InterfaceModel::Action>
-
-=head1 AUTHORS
-
-See L<Reaction::Class> for authors.
-
-=head1 LICENSE
-
-See L<Reaction::Class> for the license.
+__END__;
-=cut
--- /dev/null
+package Reaction::UI::ViewPort::Action::Role::Apply;
+
+use Reaction::Role;
+use MooseX::Types::Moose qw/Str CodeRef/;
+
+requires 'do_apply';
+has apply_label => (is => 'rw', isa => Str, lazy_build => 1);
+has on_apply_callback => (is => 'rw', isa => CodeRef);
+
+sub _build_apply_label { 'apply' }
+
+sub can_apply { 1 }
+
+sub apply {
+ my $self = shift;
+ if ($self->can_apply && (my $result = $self->do_apply)) {
+ $self->on_apply_callback->($self => $result) if $self->has_on_apply_callback;
+ return 1;
+ } else {
+ if( my $coderef = $self->can('close_label') ){
+ $self->$coderef( $self->close_label_cancel );
+ }
+ return 0;
+ }
+};
+
+around accept_events => sub { ( 'apply', shift->(@_) ) };
+
+1;
--- /dev/null
+package Reaction::UI::ViewPort::Action::Role::Close;
+
+use Reaction::Role;
+use MooseX::Types::Moose qw/Str CodeRef/;
+with 'Reaction::UI::ViewPort::Action::Role::Apply';
+
+has close_label => (is => 'rw', isa => Str, lazy_build => 1);
+has on_close_callback => (is => 'rw', isa => CodeRef);
+has close_label_close => (is => 'rw', isa => Str, lazy_build => 1);
+has close_label_cancel => (is => 'rw', isa => Str, lazy_build => 1);
+
+sub _build_close_label { shift->_build_close_label_close }
+sub _build_close_label_close { 'close' }
+sub _build_close_label_cancel { 'cancel' }
+
+sub can_close { 1 }
+
+sub close {
+ my $self = shift;
+ return unless $self->has_on_close_callback;
+ $self->on_close_callback->($self);
+}
+
+around apply => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $success = $self->$orig(@_);
+ $self->close_label( $self->close_label_cancel ) unless $success;
+ return $success;
+};
+
+# can't do a close-type operation if there's nowhere to go afterwards
+around accept_events => sub {
+ my $orig = shift;
+ my $self = shift;
+ ( ($self->has_on_close_callback ? ('close') : ()), $self->$orig(@_) );
+};
+
+1;
--- /dev/null
+package Reaction::UI::ViewPort::Action::Role::OK;
+
+use Reaction::Role;
+use MooseX::Types::Moose qw/Str/;
+with 'Reaction::UI::ViewPort::Action::Role::Close';
+
+has ok_label => (is => 'rw', isa => 'Str', lazy_build => 1);
+
+sub _build_ok_label { 'ok' }
+
+sub ok {
+ my $self = shift;
+ $self->close(@_) if $self->apply(@_);
+}
+
+around accept_events => sub {
+ my $orig = shift;
+ my $self = shift;
+ ( ($self->has_on_close_callback ? ('pl') : ()), $self->$orig(@_) );
+};
+
+1;
clearer => 'clear_value',
);
has needs_sync => (is => 'rw', isa => 'Int', default => 0);
-#predicates are autmagically generated for lazy and non-required attrs
+
has message => (is => 'rw', isa => 'Str', clearer => 'clear_message');
after clear_value => sub {
$self->clear_message if $self->has_message;
$self->needs_sync(1);
};
+
sub adopt_value {
my ($self) = @_;
$self->clear_message if $self->has_message;
$self->needs_sync(1); # if $self->has_attribute;
-};
+}
+
sub can_sync_to_action {
my $self = shift;
return 1 unless $self->needs_sync;
use namespace::clean -except => [ qw(meta) ];
extends 'Reaction::UI::ViewPort';
-
-
#everything is read only right now. Later I can make somethings read-write
#but first I need to figure out what depends on what so we can have decent triggers
has model => (is => 'ro', isa => IM_Object, required => 1);
$self->field_args( $field_args );
}
};
+
sub _build_excluded_fields { [] };
sub _build_builder_cache { {} };
sub _build_fields {
}
return \@fields;
};
+
sub _build_computed_field_order {
my ($self) = @_;
my %excluded = map { $_ => undef } @{ $self->excluded_fields };
#XXX
sub _build_fields_for_type_Reaction_Types_Core_Password { return };
+
sub _build_fields_for_type_Str {
my ($self, $attr, $args) = @_;
#XXX
--- /dev/null
+package Reaction::UI::ViewPort::Object::Mutable;
+
+use Reaction::Class;
+
+use aliased 'Reaction::UI::ViewPort::Object';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::Text';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::Array';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::String';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::Number';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::Integer';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::Boolean';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::Password';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::DateTime';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseOne';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseMany';
+
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::File';
+#use aliased 'Reaction::UI::ViewPort::Field::Mutable::TimeRange';
+
+use MooseX::Types::Moose qw/Int/;
+use Reaction::Types::Core qw/NonEmptySimpleStr/;
+
+use namespace::clean -except => [ qw(meta) ];
+extends Object;
+with 'Reaction::UI::ViewPort::Action::Role::OK';
+
+has model => (
+ is => 'ro',
+ isa => 'Reaction::InterfaceModel::Action',
+ required => 1
+ );
+
+has changed => (
+ is => 'rw',
+ isa => Int,
+ reader => 'is_changed',
+ default => sub{0}
+ );
+
+#this has to fucking go. it BLOWS.
+has method => (
+ is => 'rw',
+ isa => NonEmptySimpleStr,
+ default => sub { 'post' }
+ );
+
+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
+ }
+}
+
+sub _build_fields_for_type_Num {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => Number, %$args);
+}
+
+sub _build_fields_for_type_Int {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => Integer, %$args);
+}
+
+sub _build_fields_for_type_Bool {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => Boolean, %$args);
+}
+
+sub _build_fields_for_type_Reaction_Types_Core_SimpleStr {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => String, %$args);
+}
+
+sub _build_fields_for_type_Reaction_Types_File_File {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => File, %$args);
+}
+
+sub _build_fields_for_type_Str {
+ my ($self, $attr, $args) = @_;
+ if ($attr->has_valid_values) { # There's probably a better way to do this
+ $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
+ } else {
+ $self->_build_simple_field(attribute => $attr, class => Text, %$args);
+ }
+}
+
+sub _build_fields_for_type_Reaction_Types_Core_Password {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => Password, %$args);
+}
+
+sub _build_fields_for_type_Reaction_Types_DateTime_DateTime {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
+}
+
+sub _build_fields_for_type_Enum {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
+}
+
+#this needs to be fixed. somehow. beats the shit our of me. really.
+#implements build_fields_for_type_Reaction_InterfaceModel_Object => as {
+sub _build_fields_for_type_DBIx_Class_Row {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
+}
+
+sub _build_fields_for_type_ArrayRef {
+ my ($self, $attr, $args) = @_;
+ if ($attr->has_valid_values) {
+ $self->_build_simple_field(attribute => $attr, class => ChooseMany, %$args);
+ } else {
+ $self->_build_simple_field
+ (
+ attribute => $attr,
+ class => Array,
+ layout => 'field/mutable/hidden_array',
+ %$args);
+ }
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::ViewPort::Object::Mutable
+
+=head1 SYNOPSIS
+
+ use aliased 'Reaction::UI::ViewPort::Object::Mutable';
+
+ $self->push_viewport(Mutable,
+ layout => 'register',
+ model => $action,
+ next_action => [ $self, 'redirect_to', 'accounts', $c->req->captures ],
+ ctx => $c,
+ field_order => [
+ qw / contact_title company_name email address1 address2 address3
+ city country post_code telephone mobile fax/ ],
+ );
+
+=head1 DESCRIPTION
+
+This subclass of L<Reaction::UI::ViewPort::Object> is used for rendering a
+collection of C<Reaction::UI::ViewPort::Field::Mutable::*> objects for user editing.
+
+=head1 ATTRIBUTES
+
+=head2 model
+
+L<Reaction::InterfaceModel::Action>
+
+=head2 ok_label
+
+Default: 'ok'
+
+=head2 apply_label
+
+Default: 'apply'
+
+=head2 close_label_close
+
+Default: 'close'
+
+=head2 close_label_cancel
+
+This label is only shown when C<changed> is true.
+
+Default: 'cancel'
+
+=head2 fields
+
+=head2 can_apply
+
+=head2 can_close
+
+=head2 changed
+
+Returns true if a field has been edited.
+
+=head2 next_action
+
+=head2 on_apply_callback
+
+CodeRef.
+
+=head1 METHODS
+
+=head2 ok
+
+Calls C<apply>, and then C<close> if successful.
+
+=head2 close
+
+Pop viewport and proceed to C<next_action>.
+
+=head2 apply
+
+Attempt to save changes and update C<changed> attribute if required.
+
+=head1 SEE ALSO
+
+L<Reaction::UI::ViewPort::Object>
+
+L<Reaction::UI::ViewPort>
+
+L<Reaction::InterfaceModel::Action>
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
+