[Jifty-commit] r6614 - in jifty/trunk: lib/Jifty/Web/Form
Jifty commits
jifty-commit at lists.jifty.org
Tue Mar 17 10:59:23 EDT 2009
Author: alexmv
Date: Tue Mar 17 10:59:17 2009
New Revision: 6614
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
jifty/trunk/lib/Jifty/Web/Form/Element.pm
Log:
r43253 at kohr-ah: chmrr | 2009-03-17 10:39:46 -0400
Never loop over _all handlers, only the ones we installed things into; also, remove two-hashref calling convention from Elements->new
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 Tue Mar 17 10:59:17 2009
@@ -159,8 +159,6 @@
my %args = (
parameters => {},
- as_button => 0,
- as_link => 0,
@_,
);
@@ -170,17 +168,19 @@
$args{render_as_link} = delete $args{as_link};
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 => {},
+ { class => '',
+ label => 'Click me!',
+ url => $root,
+ escape_label => 1,
+ tooltip => '',
+ continuation => Jifty->web->request->continuation,
+ submit => [],
+ preserve_state => 0,
+ parameters => {},
+ render_as_button => 0,
+ render_as_link => 0,
+ %args,
},
- \%args
);
for (qw/continuation call/) {
@@ -222,7 +222,7 @@
# Anything doing fragment replacement needs to preserve the
# current state as well
- if ( grep { $self->$_ } $self->handlers or $self->preserve_state ) {
+ if ( grep { $self->$_ } $self->handlers_used or $self->preserve_state ) {
my %state_vars = Jifty->web->state_variables;
while ( my ( $key, $val ) = each %state_vars ) {
if ( $key =~ /^region-(.*?)\.(.*)$/ ) {
@@ -581,7 +581,7 @@
sub generate {
my $self = shift;
- for my $trigger ( $self->handlers ) {
+ for my $trigger ( $self->handlers_used ) {
my $value = $self->$trigger;
next unless $value;
my @hooks = @{$value};
@@ -611,7 +611,6 @@
$self->region_fragment( $hook->{region},
"/__jifty/empty" );
-# Jifty->web->request->remove_state_variable('region-'.$region->qualified_name);
} else {
$self->region_fragment( $hook->{region},
$hook->{replace_with} );
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 Tue Mar 17 10:59:17 2009
@@ -162,10 +162,13 @@
=cut
-sub handlers { qw(onclick onchange ondblclick onmousedown onmouseup onmouseover
- onmousemove onmouseout onfocus onblur onkeypress onkeydown
- onkeyup onselect) }
+use constant handlers => qw(
+ onclick onchange ondblclick onmousedown onmouseup onmouseover
+ onmousemove onmouseout onfocus onblur onkeypress onkeydown
+ onkeyup onselect
+);
+use constant possible_handlers => { map {($_ => 1)} handlers};
=head2 accessors
@@ -176,11 +179,10 @@
=cut
-sub accessors { shift->handlers, qw(class title key_binding key_binding_label id label tooltip continuation rel) }
-__PACKAGE__->mk_accessors(qw(_onclick _onchange _ondblclick _onmousedown _onmouseup _onmouseover
- _onmousemove _onmouseout _onfocus _onblur _onkeypress _onkeydown
- _onkeyup _onselect
- class title key_binding key_binding_label id label tooltip continuation rel));
+sub accessors { handlers, qw(class title key_binding key_binding_label id label tooltip continuation rel) }
+
+__PACKAGE__->mk_accessors(map "_$_", handlers);
+__PACKAGE__->mk_accessors(qw(class title key_binding key_binding_label id label tooltip continuation rel) );
=head2 new PARAMHASH OVERRIDE
@@ -190,22 +192,17 @@
=cut
sub new {
- my ($class, $args, $override) = @_;
+ my ($class, $args, $other) = @_;
+ $args = {%{$args}, %{$other || {}}};
# force using accessor for onclick init
- for my $trigger ( __PACKAGE__->handlers() ) {
- if (my $triggerArgs = delete $args->{$trigger}) {
- $override->{$trigger} = $triggerArgs;
- }
- }
+ my $override = {};
+ $override->{$_} = delete $args->{$_}
+ for grep {possible_handlers->{$_} and defined $args->{$_}} keys %{$args};
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};
- }
- }
+ $self->{handlers_used} = {};
+ $self->$_( $override->{$_} ) for keys %{$override};
return $self;
}
@@ -311,6 +308,7 @@
my $trigger = shift;
return $self->$trigger unless @_;
+ $self->{handlers_used}{$trigger} = 1;
my ($arg) = @_;
@@ -328,15 +326,13 @@
my @submit_tmp;
foreach my $submit ( @{$hook->{submit}}) {
- if (!ref($submit)){
- push @submit_tmp, $submit;
- }
- elsif(blessed($submit)) {
- push @submit_tmp, $submit->moniker;
-
+ if (!ref($submit)) {
+ push @submit_tmp, $submit;
+ } elsif(blessed($submit)) {
+ push @submit_tmp, $submit->moniker;
} else { # it's a hashref
- push @submit_tmp, $submit->{'action'}->moniker;
- $hook->{'action_arguments'}->{ $submit->{'action'}->moniker } = $submit->{'arguments'};
+ push @submit_tmp, $submit->{'action'}->moniker;
+ $hook->{'action_arguments'}->{ $submit->{'action'}->moniker } = $submit->{'arguments'};
}
}
@@ -364,6 +360,11 @@
}
+sub handlers_used {
+ my $self = shift;
+ return keys %{$self->{handlers_used}};
+}
+
=head2 javascript
Returns the javascript necessary to make the events happen, as a
@@ -390,10 +391,19 @@
my %response;
HANDLER:
- for my $trigger ( $self->handlers ) {
+ for my $trigger ( $self->handlers_used ) {
my $value = $self->$trigger;
next unless $value;
+ if ( !( $self->handler_allowed($trigger) ) ) {
+ $self->log->error(
+ "Handler '$trigger' is not supported for field '"
+ . $self->label
+ . "' with class "
+ . ref $self );
+ next;
+ }
+
my @fragments;
# if $actions is undef, that means we're submitting _all_ actions in the clickable
# if $actions is defined but empty, that means we're submitting no actions
@@ -403,19 +413,9 @@
my $beforeclick;
my $action_arguments = {};
for my $hook (grep {ref $_ eq "HASH"} (@{$value})) {
-
- if (!($self->handler_allowed($trigger))) {
- $self->log->error("Handler '$trigger' is not supported for field '" .
- $self->label .
- "' with class " . ref $self);
- next HANDLER;
- }
-
my %args;
# Submit action
-
-
if ( exists $hook->{submit} ) {
$actions = undef;
my $disable_form_on_click = exists $hook->{disable} ? $hook->{disable} : 1;
@@ -492,7 +492,7 @@
push @fragments, \%args;
}
- my $string = join ";", (grep {not ref $_} (ref $value eq "ARRAY" ? @{$value} : ($value)));
+ my $string = join ";", grep {not ref $_} @{$value};
if ( @fragments or ( !$actions || %$actions ) ) {
my $update =
More information about the Jifty-commit
mailing list