use MooseX::Types::Common and MooseX::Types::DateTime
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Object / Mutable.pm
CommitLineData
e984a788 1package Reaction::UI::ViewPort::Object::Mutable;
2
3use Reaction::Class;
4
5use aliased 'Reaction::UI::ViewPort::Object';
6use aliased 'Reaction::UI::ViewPort::Field::Mutable::Text';
7use aliased 'Reaction::UI::ViewPort::Field::Mutable::Array';
8use aliased 'Reaction::UI::ViewPort::Field::Mutable::String';
9use aliased 'Reaction::UI::ViewPort::Field::Mutable::Number';
10use aliased 'Reaction::UI::ViewPort::Field::Mutable::Integer';
11use aliased 'Reaction::UI::ViewPort::Field::Mutable::Boolean';
12use aliased 'Reaction::UI::ViewPort::Field::Mutable::Password';
13use aliased 'Reaction::UI::ViewPort::Field::Mutable::DateTime';
14use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseOne';
15use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseMany';
16use aliased 'Reaction::UI::ViewPort::Field::Mutable::File';
17
18use namespace::clean -except => [ qw(meta) ];
19extends Object;
20
21#this her for now. mutable fields need an action to build correctly
22has model => (
23 is => 'ro',
24 isa => 'Reaction::InterfaceModel::Action',
25 required => 1,
26);
27
029c34a8 28sub is_modified {
29 my $self = shift;
30 foreach my $field (@{$self->fields}) {
31 return 1 if $field->is_modified;
32 }
33 return 0;
34}
35
e984a788 36sub _build_fields_for_type_Num {
37 my ($self, $attr, $args) = @_;
38 $self->_build_simple_field(attribute => $attr, class => Number, %$args);
39}
40
41sub _build_fields_for_type_Int {
42 my ($self, $attr, $args) = @_;
43 $self->_build_simple_field(attribute => $attr, class => Integer, %$args);
44}
45
46sub _build_fields_for_type_Bool {
47 my ($self, $attr, $args) = @_;
48 $self->_build_simple_field(attribute => $attr, class => Boolean, %$args);
49}
50
51sub _build_fields_for_type_Reaction_Types_Core_SimpleStr {
52 my ($self, $attr, $args) = @_;
53 $self->_build_simple_field(attribute => $attr, class => String, %$args);
54}
55
56sub _build_fields_for_type_Reaction_Types_File_File {
57 my ($self, $attr, $args) = @_;
58 $self->_build_simple_field(attribute => $attr, class => File, %$args);
59}
60
61sub _build_fields_for_type_Str {
62 my ($self, $attr, $args) = @_;
63 if ($attr->has_valid_values) { # There's probably a better way to do this
64 $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
65 } else {
66 $self->_build_simple_field(attribute => $attr, class => Text, %$args);
67 }
68}
69
70sub _build_fields_for_type_Reaction_Types_Core_Password {
71 my ($self, $attr, $args) = @_;
72 $self->_build_simple_field(attribute => $attr, class => Password, %$args);
73}
74
75sub _build_fields_for_type_Reaction_Types_DateTime_DateTime {
76 my ($self, $attr, $args) = @_;
77 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
78}
79
80sub _build_fields_for_type_Enum {
81 my ($self, $attr, $args) = @_;
82 $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
83}
84
85#this needs to be fixed. somehow. beats the shit our of me. really.
86#implements build_fields_for_type_Reaction_InterfaceModel_Object => as {
87sub _build_fields_for_type_DBIx_Class_Row {
88 my ($self, $attr, $args) = @_;
89 $self->_build_simple_field(attribute => $attr, class => ChooseOne, %$args);
90}
91
92sub _build_fields_for_type_ArrayRef {
93 my ($self, $attr, $args) = @_;
94 if ($attr->has_valid_values) {
95 $self->_build_simple_field(attribute => $attr, class => ChooseMany, %$args);
96 } else {
97 $self->_build_simple_field
98 (
99 attribute => $attr,
100 class => Array,
101 layout => 'field/mutable/hidden_array',
102 %$args);
103 }
104}
105
baee102d 106sub _build_fields_for_type_MooseX_Types_Common_String_SimpleStr {
107 my ($self, $attr, $args) = @_;
108 $self->_build_simple_field(attribute => $attr, class => String, %$args);
109}
110
111sub _build_fields_for_type_MooseX_Types_Common_String_Password {
112 my ($self, $attr, $args) = @_;
113 $self->_build_simple_field(attribute => $attr, class => Password, %$args);
114}
115
116sub _build_fields_for_type_MooseX_Types_DateTime_DateTime {
117 my ($self, $attr, $args) = @_;
118 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
119}
120
121sub _build_fields_for_type_DateTime {
122 my ($self, $attr, $args) = @_;
123 $self->_build_simple_field(attribute => $attr, class => DateTime, %$args);
124}
125
e984a788 126__PACKAGE__->meta->make_immutable;
127
1281;
129
130__END__;
131
132=head1 NAME
133
134Reaction::UI::ViewPort::Object::Mutable
135
136=head1 SYNOPSIS
137
138=head1 DESCRIPTION
139
140This subclass of L<Reaction::UI::ViewPort::Object> is used for rendering a
141collection of C<Reaction::UI::ViewPort::Field::Mutable::*> objects for user editing.
142
143=head1 ATTRIBUTES
144
145=head2 model
146
147L<Reaction::InterfaceModel::Action>
148
149=head1 METHODS
150
151=head2 _build_fields_for_type_Num
152
153=head2 _build_fields_for_type_Int
154
155=head2 _build_fields_for_type_Bool
156
157=head2 _build_fields_for_type_Reaction_Types_Core_SimpleStr
158
159=head2 _build_fields_for_type_Reaction_Types_File_File
160
161=head2 _build_fields_for_type_Str
162
163=head2 _build_fields_for_type_Reaction_Types_Core_Password
164
165=head2 _build_fields_for_type_Reaction_Types_DateTime_DateTime
166
167=head2 _build_fields_for_type_Enum
168
169=head2 _build_fields_for_type_DBIx_Class_Row
170
171=head2 _build_fields_for_type_ArrayRef
172
173=head1 SEE ALSO
174
175L<Reaction::UI::ViewPort::Object>
176
177L<Reaction::UI::ViewPort>
178
179L<Reaction::InterfaceModel::Action>
180
181=head1 AUTHORS
182
183See L<Reaction::Class> for authors.
184
185=head1 LICENSE
186
187See L<Reaction::Class> for the license.
188
189=cut
190