1 package Reaction::UI::ViewPort::Object::Mutable;
5 use aliased 'Reaction::UI::ViewPort::Object';
6 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Text';
7 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Array';
8 use aliased 'Reaction::UI::ViewPort::Field::Mutable::String';
9 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Number';
10 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Integer';
11 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Boolean';
12 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Password';
13 use aliased 'Reaction::UI::ViewPort::Field::Mutable::DateTime';
14 use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseOne';
15 use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseMany';
17 use aliased 'Reaction::UI::ViewPort::Field::Mutable::File';
18 #use aliased 'Reaction::UI::ViewPort::Field::Mutable::TimeRange';
20 use MooseX::Types::Moose qw/Int/;
21 use Reaction::Types::Core qw/NonEmptySimpleStr/;
23 use namespace::clean -except => [ qw(meta) ];
25 with 'Reaction::UI::ViewPort::Action::Role::OK';
29 isa => 'Reaction::InterfaceModel::Action',
36 reader => 'is_changed',
40 #this has to fucking go. it BLOWS.
43 isa => NonEmptySimpleStr,
44 default => sub { 'post' }
49 foreach my $field ( @{ $self->fields } ) {
50 return 0 if $field->needs_sync;
51 # if e.g. a datetime field has an invalid value that can't be re-assembled
52 # into a datetime object, the action may be in a consistent state but
53 # not synchronized from the fields; in this case, we must not apply
55 return $self->model->can_apply;
59 shift->model->do_apply;
62 after apply_child_events => sub {
63 # interrupt here because fields will have been updated
65 $self->sync_action_from_fields;
68 sub sync_action_from_fields {
70 foreach my $field (@{$self->fields}) {
71 $field->sync_to_action; # get the field to populate the $action if possible
73 $self->model->sync_all;
74 foreach my $field (@{$self->fields}) {
75 $field->sync_from_action; # get errors from $action if applicable
79 sub _build_fields_for_type_Num {
80 my ($self, $attr, $args) = @_;
81 $self->_build_simple_field(attribute => $attr, class => Number, %$args);
84 sub _build_fields_for_type_Int {
85 my ($self, $attr, $args) = @_;
86 $self->_build_simple_field(attribute => $attr, class => Integer, %$args);
89 sub _build_fields_for_type_Bool {
90 my ($self, $attr, $args) = @_;
91 $self->_build_simple_field(attribute => $attr, class => Boolean, %$args);
94 sub _build_fields_for_type_Reaction_Types_Core_SimpleStr {
95 my ($self, $attr, $args) = @_;
96 $self->_build_simple_field(attribute => $attr, class => String, %$args);
99 sub _build_fields_for_type_Reaction_Types_File_File {
100 my ($self, $attr, $args) = @_;
101 $self->_build_simple_field(attribute => $attr, class => File, %$args);
104 sub _build_fields_for_type_Str {
105 my ($self, $attr, $args) = @_;
106 if ($attr->has_valid_values) { # There's probably a better way to do this
107 $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
109 $self->_build_simple_field(attribute => $attr, class => Text, %$args);
113 sub _build_fields_for_type_Reaction_Types_Core_Password {
114 my ($self, $attr, $args) = @_;
115 $self->_build_simple_field(attribute => $attr, class => Password, %$args);
118 sub _build_fields_for_type_Reaction_Types_DateTime_DateTime {
119 my ($self, $attr, $args) = @_;
120 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
123 sub _build_fields_for_type_Enum {
124 my ($self, $attr, $args) = @_;
125 $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
128 #this needs to be fixed. somehow. beats the shit our of me. really.
129 #implements build_fields_for_type_Reaction_InterfaceModel_Object => as {
130 sub _build_fields_for_type_DBIx_Class_Row {
131 my ($self, $attr, $args) = @_;
132 $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
135 sub _build_fields_for_type_ArrayRef {
136 my ($self, $attr, $args) = @_;
137 if ($attr->has_valid_values) {
138 $self->_build_simple_field(attribute => $attr, class => ChooseMany, %$args);
140 $self->_build_simple_field
144 layout => 'field/mutable/hidden_array',
149 __PACKAGE__->meta->make_immutable;
157 Reaction::UI::ViewPort::Object::Mutable
161 use aliased 'Reaction::UI::ViewPort::Object::Mutable';
163 $self->push_viewport(Mutable,
164 layout => 'register',
166 next_action => [ $self, 'redirect_to', 'accounts', $c->req->captures ],
169 qw / contact_title company_name email address1 address2 address3
170 city country post_code telephone mobile fax/ ],
175 This subclass of L<Reaction::UI::ViewPort::Object> is used for rendering a
176 collection of C<Reaction::UI::ViewPort::Field::Mutable::*> objects for user editing.
182 L<Reaction::InterfaceModel::Action>
192 =head2 close_label_close
196 =head2 close_label_cancel
198 This label is only shown when C<changed> is true.
210 Returns true if a field has been edited.
214 =head2 on_apply_callback
222 Calls C<apply>, and then C<close> if successful.
226 Pop viewport and proceed to C<next_action>.
230 Attempt to save changes and update C<changed> attribute if required.
234 L<Reaction::UI::ViewPort::Object>
236 L<Reaction::UI::ViewPort>
238 L<Reaction::InterfaceModel::Action>
242 See L<Reaction::Class> for authors.
246 See L<Reaction::Class> for the license.