From 881dd5577887267d76437631ccd0f456d56f9d99 Mon Sep 17 00:00:00 2001 From: matthewt Date: Tue, 11 Mar 2008 02:17:31 +0000 Subject: special exists event, force_events --- lib/Reaction/UI/ViewPort.pm | 12 ++++++++++-- lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm | 2 ++ lib/Reaction/UI/Widget/Field/Mutable.pm | 7 +++++++ share/skin/default/layout/field/mutable/boolean.tt | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Reaction/UI/ViewPort.pm b/lib/Reaction/UI/ViewPort.pm index 0e9cbb2..1c2b755 100644 --- a/lib/Reaction/UI/ViewPort.pm +++ b/lib/Reaction/UI/ViewPort.pm @@ -18,7 +18,7 @@ class ViewPort which { has _tangent_stacks => ( isa => 'HashRef', is => 'ro', default => sub { {} } ); - has ctx => (isa => 'Catalyst', is => 'ro', required => 1); + has ctx => (isa => 'Catalyst', is => 'ro'); #, required => 1); implements _build_layout => as { ''; @@ -90,13 +90,19 @@ class ViewPort which { implements handle_events => as { my ($self, $events) = @_; + my $exists = exists $events->{exists}; + if ($exists) { + my %force = $self->force_events; + my @need = grep { !exists $events->{$_} } keys %force; + @{$events}{@need} = @force{@need}; + } foreach my $event ($self->accept_events) { if (exists $events->{$event}) { if (DEBUG_EVENTS) { my $name = join(' at ', $self, $self->location); $self->ctx->log->debug( "Applying Event: $event on $name with value: " - .$events->{$event} + .(defined $events->{$event} ? $events->{$event} : '') ); } $self->$event($events->{$event}); @@ -106,6 +112,8 @@ class ViewPort which { implements accept_events => as { () }; + implements force_events => as { () }; + implements event_id_for => as { my ($self, $name) = @_; return join(':', $self->location, $name); diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm index 66fa464..4244b31 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm @@ -31,6 +31,8 @@ role Simple which { around accept_events => sub { ('value_string', shift->(@_)) }; + around force_events => sub { (value_string => '', shift->(@_)) }; + }; 1; diff --git a/lib/Reaction/UI/Widget/Field/Mutable.pm b/lib/Reaction/UI/Widget/Field/Mutable.pm index 98d7e9b..c4d2e44 100644 --- a/lib/Reaction/UI/Widget/Field/Mutable.pm +++ b/lib/Reaction/UI/Widget/Field/Mutable.pm @@ -8,6 +8,13 @@ class Mutable is 'Reaction::UI::Widget::Field', which { arg 'field_id' => event_id 'value_string'; arg 'field_name' => event_id 'value_string' unless defined $_{field_name}; arg 'field_type' => 'text'; + + # 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 { diff --git a/share/skin/default/layout/field/mutable/boolean.tt b/share/skin/default/layout/field/mutable/boolean.tt index f50b377..6d70f36 100644 --- a/share/skin/default/layout/field/mutable/boolean.tt +++ b/share/skin/default/layout/field/mutable/boolean.tt @@ -1,5 +1,10 @@ =extends field/mutable +=for layout widget + + +[% call_next %] + =for layout field_body value="1" [% is_checked %] -- cgit v1.2.3-54-g00ecf