[Jifty-commit] r2769 - in jifty/trunk: lib/Jifty/Web

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Feb 9 00:04:24 EST 2007


Author: jesse
Date: Fri Feb  9 00:04:20 2007
New Revision: 2769

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Web/PageRegion.pm

Log:
 r21899 at hualien:  jesse | 2007-02-09 00:02:01 -0500
 * Added the ability to force arguments and path when rengering a region. This lets developers force override something passed in via ajax or a "sticky" value from a previous request.


Modified: jifty/trunk/lib/Jifty/Web/PageRegion.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/PageRegion.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/PageRegion.pm	Fri Feb  9 00:04:20 2007
@@ -15,7 +15,7 @@
 =cut
 
 use base qw/Jifty::Object Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw(name default_path default_arguments qualified_name parent region_wrapper));
+__PACKAGE__->mk_accessors(qw(name force_path force_arguments default_path default_arguments qualified_name parent region_wrapper));
 use Jifty::JSON;
 
 =head2 new PARAMHASH
@@ -40,6 +40,15 @@
 Specifies an optional set of parameter defaults.  These should all be
 simple scalars, as they might be passed across HTTP if AJAX is used.
 
+=item force_arguments (optional)
+
+Specifies an optional set of parameter values. They will override anything
+sent by the user or set via AJAX.
+
+=item force_path (optional)
+
+A fixed path to the fragment that this page region contains.  Overrides anything set by the user.
+
 =item parent (optional)
 
 The parent L<Jifty::Web::PageRegion> that this region is enclosed in.
@@ -50,6 +59,9 @@
 HTML region preamble that makes Javascript aware of its presence.
 Defaults to true.
 
+
+=item
+
 =back
 
 =cut
@@ -63,6 +75,8 @@
                 path => "/__jifty/empty",
                 defaults => {},
                 parent => undef,
+                force_arguments => {},
+                force_path => undef,
                 region_wrapper => 1,
                 @_
                );
@@ -84,6 +98,8 @@
     $self->qualified_name(Jifty->web->qualified_region($self));
     $self->default_path($args{path});
     $self->default_arguments($args{defaults});
+    $self->force_arguments($args{force_arguments});
+    $self->force_path($args{force_path});
     $self->arguments({});
     $self->parent($args{parent} || Jifty->web->current_region);
     $self->region_wrapper($args{region_wrapper});
@@ -158,7 +174,7 @@
     my $self = shift;
     my $name = shift;
     $self->{arguments}{$name} = shift if @_;
-    return $self->{arguments}{$name} || $self->default_argument($name);
+    return $self->force_arguments->{$name}||$self->{arguments}{$name} || $self->default_argument($name);
 }
 
 =head2 arguments [HASHREF]
@@ -171,7 +187,7 @@
 sub arguments {
     my $self = shift;
     $self->{arguments} = shift if @_;
-    return { %{$self->{default_arguments}}, %{$self->{arguments}}};
+    return { %{$self->{default_arguments}}, %{$self->{arguments}}, %{$self->force_arguments}};
 }
 
 =head2 enter
@@ -179,7 +195,7 @@
 Enters the region; this sets the qualified name based on
 L<Jifty::Web/qualified_region>, and uses that to pull runtime values
 for the L</path> and L</argument>s from the
-L<Jifty::Request/state_variables>.
+L<Jifty::Request/state_variables> before overriding them with the "force" versions.
 
 =cut
 
@@ -204,6 +220,12 @@
         # We should always inherit the state variables from the uplevel request.
         Jifty->web->set_variable($key => $value);
     }
+
+    for my $argument (keys %{$self->force_arguments}) {
+            $self->argument($argument => $self->force_arguments->{$argument});
+    }
+
+    $self->path($self->force_path) if ($self->force_path);
 }
 
 =head2 exit 


More information about the Jifty-commit mailing list