X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FWidget%2FField%2FMutable.pm;h=9fc565e2ede6c44983037a63b3f4a38b644c7bbd;hb=56d5a4eb0f9cef44c02759663616dd1f0893d483;hp=5d658dc782faa71ca8aff60d14ae58fddbca8d3f;hpb=36d54b146cfba17f5c7757eced453429ee31c780;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/Widget/Field/Mutable.pm b/lib/Reaction/UI/Widget/Field/Mutable.pm index 5d658dc..9fc565e 100644 --- a/lib/Reaction/UI/Widget/Field/Mutable.pm +++ b/lib/Reaction/UI/Widget/Field/Mutable.pm @@ -2,23 +2,235 @@ package Reaction::UI::Widget::Field::Mutable; use Reaction::UI::WidgetClass; -class Mutable is 'Reaction::UI::Widget::Field', which { +use namespace::clean -except => [ qw(meta) ]; +extends 'Reaction::UI::Widget::Field'; - before fragment widget { - arg 'field_id' => event_id 'value'; - arg 'field_name' => event_id 'value'; - arg 'field_type' => 'text'; - }; - implements fragment message_fragment { - if (my $message = $_{viewport}->message) { - arg message => $message; - render 'message'; - } - }; -}; + before fragment widget { + arg 'field_id' => event_id 'value_string'; + arg 'field_name' => event_id 'value_string' unless defined $_{field_name}; + arg 'field_type' => 'text'; + arg 'field_class' => "action-field " . $_{viewport}->name; + + # these two are to fire force_events in viewports + # where you can end up without an event for e.g. + # HTML checkbox fields + + arg 'exists_event' => event_id 'exists'; + arg 'exists_value' => 1; + }; + + implements fragment message_fragment { + my $vp = $_{viewport}; + return unless $vp->has_message; + my $message = $vp->message; + if ($message) { + arg message => localized $message; + render 'message'; + } + }; + + implements fragment field_is_required { + my $vp = $_{viewport}; + if ( $vp->value_is_required && !$vp->value_string ) { + render 'field_is_required_yes'; + } else { + render 'field_is_required_no'; + } + }; + +__PACKAGE__->meta->make_immutable; + 1; __END__; + +=head1 NAME + +Reaction::UI::Widget::Field::Mutable - Mutable fields + +=head1 DESCRIPTION + +An extension of L representing fields +whose values can be mutated. + +=head1 FRAGMENTS + +=head2 widget + +The following additional arguments are provided: + +=over 4 + +=item field_id + +Contains the viewport's event id for C. + +=item field_name + +Defaults to the C argument unless already defined + +=item field_type + +Defaults to C. + +=item field_class + +A string containing the joined class attribute. Defaults to +C and the current viewport's C. + +=item exists_event + +Contains the event id for C. + +=item exists_value + +Defaults to C<1>. + +=back + +=head2 message_fragment + +Renders nothing if the viewport doesn't have a message. + +Otherwise, the C argument will be set to the localised string contained +in the viewport's C attribute and the C fragment will be rendered. + +=head2 field_is_required + +Will render either C or C depending on +if C on the viewport returns true and the viewports C +is empty. + +=head1 LAYOUT SETS + +=head2 base + + share/skin/base/layout/field/mutable.tt + +The following layouts are provided: + +=over 4 + +=item widget + +Builds a C element with a class attribute set to the C argument. +The element contents will be the C, C and C +fragments. + +=item label + +Builds a C