collection-grid already does Pager and Actions
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort.pm
index 34c2fee..7b2898e 100644 (file)
@@ -19,7 +19,7 @@ has focus_stack => (
 has _tangent_stacks => (
   isa => 'HashRef', is => 'ro', default => sub { {} }
 );
-has ctx => (isa => 'Catalyst', is => 'ro'); #, required => 1);
+has ctx => (isa => 'Catalyst', is => 'ro', weak_ref => 1); #, required => 1);
 
 sub _build_layout {
   '';
@@ -68,25 +68,23 @@ sub apply_child_events {
   foreach my $child ($self->child_event_sinks) {
     confess blessed($child) ."($child) is not a valid object"
       unless blessed($child) && $child->can('apply_events');
-    $child->apply_events($events);
+    my $loc = $child->location;
+    my %child_events = map { $_ => delete $events->{$_} }
+      grep { /^${loc}[-:]/ } keys %$events;
+    $child->apply_events(\%child_events);
   }
 }
 
 sub apply_our_events {
   my ($self, $events) = @_;
-  my @keys = keys %$events;
-  return unless @keys;
   my $loc = $self->location;
   my %our_events;
   foreach my $key (keys %$events) {
     if ($key =~ m/^${loc}:(.*)$/) {
-      $our_events{$1} = $events->{$key};
+      $our_events{$1} = delete $events->{$key};
     }
   }
-  if (keys %our_events) {
-    #warn "$self: events ".join(', ', %our_events)."\n";
-    $self->handle_events(\%our_events);
-  }
+  $self->handle_events(\%our_events) if keys %our_events;
 }
 
 sub handle_events {
@@ -99,17 +97,20 @@ sub handle_events {
   }
   foreach my $event ($self->accept_events) {
     if (exists $events->{$event}) {
-      if (DEBUG_EVENTS) {
-        my $name = join(' at ', $self, $self->location);
-        print STDERR
-          "Applying Event: $event on $name with value: "
-          .(defined $events->{$event} ? $events->{$event} : '<undef>');
-      }
+      $self->_dump_event($event, $events->{$event}) if DEBUG_EVENTS;
       $self->$event($events->{$event});
     }
   }
 }
 
+sub _dump_event {
+  my ( $self, $name, $value ) = @_;
+  my $vp_name = join(' at ', $self, $self->location);
+  print STDERR
+    "Applying Event: $name on $vp_name with value: "
+    . (defined $value ? $value : '<undef>') . "\n";
+}
+
 sub accept_events { () }
 
 sub force_events { () }
@@ -152,7 +153,7 @@ Reaction::UI::ViewPort - Page layout building block
 
   # Create a new ViewPort:
   # $stack isa Reaction::UI::FocusStack object
-  my $vp = $stack->push_viewport('Reaction::UI::ViewPort', layout => 'xthml');
+  my $vp = $stack->push_viewport('Reaction::UI::ViewPort', layout => 'xhtml');
 
   # Fetch ViewPort higher up the stack (further out)
   my $outer = $vp->outer();
@@ -252,6 +253,16 @@ The layout attribute can either be specifically passed when calling
 C<push_viewport>, or it will be determined using the last part of the
 ViewPorts classname.
 
+=item layout_args
+
+This read-only hashref attribute will pass all it's keys as variables to the
+layout at render time. They should be accessible from both the layout templates
+and the widget, if applicable, through the C<%_> hash.
+
+    $controller->push_viewport(VPName, layout => 'foo', layout_args => { bar => 'bar'});
+    $_{bar} #in widget
+    [% bar %] in template
+
 =item column_order
 
 This is generally used by more specialised ViewPorts such as the