[Jifty-commit] r1918 - jifty/trunk/lib/Jifty/Web/Form
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sat Sep 2 08:56:13 EDT 2006
Author: clkao
Date: Sat Sep 2 08:56:05 2006
New Revision: 1918
Modified:
jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
jifty/trunk/lib/Jifty/Web/Form/Element.pm
jifty/trunk/lib/Jifty/Web/Form/Link.pm
Log:
Refactor the constructors for Jifty::Web::Form::*, which takes initial
hash and values to be overridden with accessors.
Modified: jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Clickable.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form/Clickable.pm Sat Sep 2 08:56:05 2006
@@ -136,17 +136,6 @@
my $class = shift;
my ($root) = $ENV{'REQUEST_URI'} =~ /([^\?]*)/;
- my $self = bless {
- class => '',
- label => 'Click me!',
- url => $root,
- escape_label => 1,
- tooltip => '',
- continuation => Jifty->web->request->continuation,
- submit => [],
- preserve_state => 0,
- }, $class;
-
my %args = (
parameters => {},
as_button => 0,
@@ -157,11 +146,17 @@
$args{render_as_button} = delete $args{as_button};
$args{render_as_link} = delete $args{as_link};
- $self->{parameters} = {};
-
- for my $field ( $self->accessors() ) {
- $self->$field( $args{$field} ) if exists $args{$field};
- }
+ my $self = $class->SUPER::new({
+ class => '',
+ label => 'Click me!',
+ url => $root,
+ escape_label => 1,
+ tooltip => '',
+ continuation => Jifty->web->request->continuation,
+ submit => [],
+ preserve_state => 0,
+ parameters => {},
+ }, \%args);
for (qw/continuation call/) {
$self->{$_} = $self->{$_}->id if $self->{$_} and ref $self->{$_};
@@ -171,11 +166,6 @@
$self->{submit} = [ $self->{submit} ] unless ref $self->{submit} eq "ARRAY";
$self->{submit}
= [ map { ref $_ ? $_->moniker : $_ } @{ $self->{submit} } ];
-
- # If they have an onclick, add any and all submit actions to the onclick's submit list
- if ($self->{onclick}) {
- $self->{onclick} = [ (ref $self->{onclick} eq "ARRAY" ? @{ $self->{onclick} } : $self->{onclick}), map { submit => $_ }, @{$self->{submit}} ];
- }
}
# Anything doing fragment replacement needs to preserve the
Modified: jifty/trunk/lib/Jifty/Web/Form/Element.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Element.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form/Element.pm Sat Sep 2 08:56:05 2006
@@ -147,6 +147,32 @@
sub accessors { shift->handlers, qw(class key_binding id label tooltip) }
__PACKAGE__->mk_accessors(qw(_onclick class key_binding id label tooltip));
+=head2 new PARAMHASH OVERRIDE
+
+Create a new C<Jifty::Web::Form::Element> object blessed with
+PARAMHASH, and set with accessors for the hash values in OVERRIDE.
+
+=cut
+
+sub new {
+ my ($class, $args, $override) = @_;
+ # force using accessor for onclick init
+ if (my $onclick = delete $args->{onclick}) {
+ $override->{onclick} = $onclick;
+ }
+
+ my $self = $class->SUPER::new($args);
+
+ if ($override) {
+ for my $field ( $self->accessors() ) {
+ # XXX: warn about unexpected ones
+ $self->$field( $override->{$field} ) if exists $override->{$field};
+ }
+ }
+
+ return $self;
+}
+
=head2 onclick
=cut
Modified: jifty/trunk/lib/Jifty/Web/Form/Link.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Link.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form/Link.pm Sat Sep 2 08:56:05 2006
@@ -68,19 +68,14 @@
sub new {
my $class = shift;
+ my $args = ref($_[0]) ? $_[0] : {@_};
my $self = $class->SUPER::new(
{ url => $ENV{PATH_INFO},
label => "Click me!",
tooltip => undef,
escape_label => 1,
class => '',
- target => '' }
- );
- my $args = ref($_[0]) ? $_[0] : {@_};
-
- for my $field ( keys %$args ) {
- $self->$field( $args->{$field} );
- }
+ target => '' }, $args );
return $self;
}
More information about the Jifty-commit
mailing list