X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FWidget%2FAction.pm;h=3d8b1c4389bb2d4f37a383e71c04747c901d024d;hb=7b5e71adcc00ae151a7908c2cddcd7323408efc7;hp=a54afcb9f5bb2574e0af18a5baff06008ea2d2f7;hpb=cc44a3371f6bb93dfcc28961004b00064942e27b;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/Widget/Action.pm b/lib/Reaction/UI/Widget/Action.pm index a54afcb..3d8b1c4 100644 --- a/lib/Reaction/UI/Widget/Action.pm +++ b/lib/Reaction/UI/Widget/Action.pm @@ -2,38 +2,55 @@ package Reaction::UI::Widget::Action; use Reaction::UI::WidgetClass; -class Action is 'Reaction::UI::Widget::Object', which { - - #before fragment widget { - # arg form_id => $_{viewport}->location; - #}; - - implements fragment ok_button_fragment { - if (grep { $_ eq 'ok' } $_{viewport}->accept_events) { - arg 'event_id' => event_id 'ok'; - arg 'label' => $_{viewport}->ok_label; - render 'ok_button'; - } - }; - - implements fragment apply_button_fragment { - if (grep { $_ eq 'apply' } $_{viewport}->accept_events) { - arg 'event_id' => event_id 'apply'; - arg 'label' => $_{viewport}->apply_label; - render 'apply_button'; - } - }; - - implements fragment cancel_button_fragment { - if (grep { $_ eq 'cancel' } $_{viewport}->accept_events) { - arg 'event_id' => event_id 'cancel'; - arg 'label' => $_{viewport}->cancel_label; - render 'cancel_button'; - } - }; +use namespace::clean -except => [ qw(meta) ]; +extends 'Reaction::UI::Widget::Object::Mutable'; + +after fragment widget { + my $vp = $_{viewport}; + arg 'method' => $vp->method; + arg 'form_id' => $vp->location; + arg 'action' => $vp->has_action ? $vp->action : ''; +}; + +implements fragment message { + return unless $_{viewport}->has_message; + arg message_string => $_{viewport}->message; + render 'message_layout'; +}; +implements fragment error_message { + return unless $_{viewport}->has_error_message; + arg message_string => $_{viewport}->error_message; + render 'error_message_layout'; }; +implements fragment ok_button_fragment { + if (grep { $_ eq 'ok' } $_{viewport}->accept_events) { + arg 'event_id' => event_id 'ok'; + arg 'label' => localized $_{viewport}->ok_label; + render 'ok_button'; + } +}; + +implements fragment apply_button_fragment { + if (grep { $_ eq 'apply' } $_{viewport}->accept_events) { + arg 'event_id' => event_id 'apply'; + arg 'label' => localized $_{viewport}->apply_label; + render 'apply_button'; + } +}; + +implements fragment cancel_button_fragment { + if (grep { $_ eq 'close' } $_{viewport}->accept_events) { + arg 'event_id' => event_id 'close'; + arg 'label' => localized $_{viewport}->close_label; + render 'cancel_button'; + } +}; + +__PACKAGE__->meta->make_immutable; + + 1; __END__; @@ -44,14 +61,172 @@ Reaction::UI::Widget::Action =head1 DESCRIPTION +This is a subclass of L. + =head1 FRAGMENTS +=head2 widget + +Additionally provides the C argument containing the value of +the viewport's C. + +=head2 message + +Empty if the viewport's C returns false. Otherwise sets +the C argument to the viewport's C and +renders the C fragment. + +=head2 error_message + +Same as the C fragment above except that it checks +C, sets C to the viewport's +C and renders C. + =head2 ok_button_fragment +Renders nothing unless the viewport accepts the C event. + +If it does, it provides the following arguments before rendering C: + +=over 4 + +=item event_id + +Is set to the event id C. + +=item label + +Is set to the localized C of the viewport. + +=back + =head2 apply_button_fragment +Renders nothing unless the viewport accepts the C event. + +If it does, it provides the following arguments before rendering C: + +=over 4 + +=item event_id + +Is set to the event id C. + +=item label + +Is set to the localized C of the viewport. + +=back + =head2 cancel_button_fragment +Renders nothing unless the viewport accepts the C event. + +If it does, it provides the following arguments before rendering C: + +=over 4 + +=item event_id + +Is set to the event id C. + +=item label + +Is set to the localized C of the viewport. + +=back + +=head1 LAYOUT SETS + +=head2 base + + share/skin/base/layout/action.tt + +The following layouts are provided: + +=over 4 + +=item widget + +Renders a C
element containing a C
. The C element contains the rendered +C
, C, C and C