search spec components factored out of T365
[catagits/Reaction.git] / lib / Reaction / UI / Widget / Field.pm
index aa0abf9..7e5fcd3 100644 (file)
@@ -2,76 +2,142 @@ package Reaction::UI::Widget::Field;
 
 use Reaction::UI::WidgetClass;
 
-class Field, which {
+use namespace::clean -except => [ qw(meta) ];
 
-  has id   => (isa => 'Str', is => 'ro', lazy_build => 1);
-  has name => (isa => 'Str', is => 'ro', lazy_build => 1);
 
-  implements build_id   => as { shift->viewport->event_id_for('value'); };
-  implements build_name => as { shift->viewport->event_id_for('value'); };
-
-  widget renders [qw/label field message/
-                  => { id       => func('self', 'id'),
-                       name     => func('self', 'name'),
-                       viewport => func('self', 'viewport'),  }
-                 ];
-
-  field   renders [ string { $_{viewport}->value },   ];
-
-  label   renders [ string { $_{viewport}->label   }, ];
-  message renders [ string { $_{viewport}->message }, ];
+before fragment widget {
+  if ($_{viewport}->can('value_string')) {
+    arg 'field_value' => $_{viewport}->value_string;
+  } else {
+    arg 'field_value' => ''; #$_{viewport}->value;
+  }
+};
 
+implements fragment label_fragment {
+  if (my $label = $_{viewport}->label) {
+    arg label => localized $label;
+    render 'label';
+  }
 };
 
+__PACKAGE__->meta->make_immutable;
+
 1;
 
 __END__;
 
 =head1 NAME
 
-Reaction::UI::Widget::Field
+Reaction::UI::Widget::Field - A simple labelled text field
 
 =head1 DESCRIPTION
 
-=head1 ATTRIBUTES
+This widget renders a simple labelled text field.
 
-=head2 id
+=head1 FRAGMENTS
 
-Str, lazy builds.
+=head2 widget
 
-=head2 name
+Sets the C<field_value> argument either to the result of the C<value_string>
+method on the viewport, or to an empty string if the viewport does not support
+the method.
 
-Str, lazy builds.
+=head2 label_fragment
 
-=head1 METHODS
+Will set the C<label> argument to the localised value of the viewport's C<label>
+method and render the C<label> fragment I<if> the viewport's C<label> value
+is true.
 
-=head2 build_id
+=head1 LAYOUT SETS
 
-Returns the viewport's C<event_id_for('value')>
+=head2 base
 
-=head2 build_name
+  share/skin/base/layout/field.tt
 
-Returns the viewport's C<event_id_for('value')>
+The following layouts are provided:
 
-=head1 FRAGMENTS
+=over 4
 
-=head2 widget
+=item widget
+
+Renders the C<label_fragment> and C<value_layout> fragments.
+
+=item label
+
+Renders a C<span> element with a C<field_label> class attribute containing the
+C<label> argument and a double colon.
+
+=item value_layout
+
+Renders a C<span> element with a C<field_value> class attribute containing the
+C<field_value> argument.
+
+=back
+
+=head2 default
+
+  share/skin/default/layout/field.tt
+
+This layout set inherits from the C<NEXT> one in the skin inheritance.
+
+The following layouts are provided:
+
+=item label
+
+The same as in the C<base> skin except that the C<label> argument is surrounded
+by a C<strong> element.
+
+=head1 SUBCLASSES
+
+For mutable fields see L<Reaction::UI::Widget::Field::Mutable>.
+
+=over 4
+
+=item L<Reaction::UI::Field::Text>
+
+A simple text subclass of L<Reaction::UI::Field>.
+
+=item L<Reaction::UI::Field::String>
+
+A simple string subclass of L<Reaction::UI::Field>.
+
+=item L<Reaction::UI::Field::RelatedObject>
+
+A simple subclass of L<Reaction::UI::Field>.
+
+=item L<Reaction::UI::Field::Number>
+
+A simple number subclass of L<Reaction::UI::Field>.
+
+=item L<Reaction::UI::Field::Integer>
+
+A simple integer subclass of L<Reaction::UI::Field>.
+
+=item L<Reaction::UI::Field::Image>
+
+A field representing an optional image.
+
+=item L<Reaction::UI::Field::DateTime>
+
+A simple DateTime subclass of L<Reaction::UI::Field>.
+
+=item L<Reaction::UI::Field::Container>
 
-Additional variables available in topic hash: "viewport", "id", "name".
+A container field for multiple values.
 
-Renders "label","field" and "message"
+=item L<Reaction::UI::Field::Collection>
 
-=head2 field
+A field containing a collection of localised values.
 
- C<content> will contain the value, if any,  of the field.
+=item L<Reaction::UI::Field::Boolean>
 
-=head2 label
+A simple boolean subclass of L<Reaction::UI::Field>.
 
- C<content> will contain the label, if any, of the field.
+=item L<Reaction::UI::Field::Array>
 
-=head2 message
+A field representing an array of values, like L<Reaction::UI::Field::Collection>.
 
- C<content> will contain the message, if any, of the field.
+=back
 
 =head1 AUTHORS