X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FAction.pm;h=b2af6748a706efc06e81f7d7d43cbb31ef20c152;hb=029c34a8754728e0f1622ea56ac112941226ebd3;hp=9fc808f1f202aeb7cd2a58e9bb735759a0a0df2e;hpb=08451970f95a0f815bbf8ea544141a619bef9ef3;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Action.pm b/lib/Reaction/UI/ViewPort/Action.pm index 9fc808f..b2af674 100644 --- a/lib/Reaction/UI/ViewPort/Action.pm +++ b/lib/Reaction/UI/ViewPort/Action.pm @@ -2,47 +2,30 @@ package Reaction::UI::ViewPort::Action; 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 MooseX::Types::Moose qw/Int Str/; 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 - ); +extends 'Reaction::UI::ViewPort::Object::Mutable'; +with 'Reaction::UI::ViewPort::Action::Role::OK'; -has changed => ( - is => 'rw', - isa => Int, - reader => 'is_changed', - default => sub{0} - ); +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 changed => ( + is => 'rw', + isa => Int, + reader => 'is_changed', + default => sub{0} +); sub can_apply { my ($self) = @_; @@ -76,75 +59,6 @@ sub sync_action_from_fields { } } -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; @@ -154,88 +68,46 @@ __END__; =head1 NAME -Reaction::UI::ViewPort::Object::Mutable +Reaction::UI::ViewPort::Action =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 is used for rendering a -collection of C objects for user editing. +This subclass of L is used for +rendering a complete form supporting Apply, Close and OK. =head1 ATTRIBUTES -=head2 model - -L - -=head2 ok_label - -Default: 'ok' - -=head2 apply_label - -Default: 'apply' - -=head2 close_label_close - -Default: 'close' - -=head2 close_label_cancel +=head2 method -This label is only shown when C is true. - -Default: 'cancel' - -=head2 fields - -=head2 can_apply - -=head2 can_close +post / get =head2 changed Returns true if a field has been edited. -=head2 next_action - -=head2 on_apply_callback - -CodeRef. - =head1 METHODS -=head2 ok +=head2 can_apply -Calls C, and then C if successful. +=head2 do_apply -=head2 close +=head2 sync_action_from_fields -Pop viewport and proceed to C. +=head1 SEE ALSO -=head2 apply +L -Attempt to save changes and update C attribute if required. +L -=head1 SEE ALSO +L -L +L -L +L -L +L =head1 AUTHORS