[Jifty-commit] r4249 - in jifty/trunk: lib/Jifty/Web/Form share/web/static/js t/TestApp/lib/TestApp t/TestApp/lib/TestApp/Action

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Oct 17 11:46:35 EDT 2007


Author: jesse
Date: Wed Oct 17 11:46:35 2007
New Revision: 4249

Added:
   jifty/trunk/t/TestApp/lib/TestApp/Action/SayHi.pm
Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/META.yml
   jifty/trunk/lib/Jifty/Web/Form/Element.pm
   jifty/trunk/share/web/static/js/jifty.js
   jifty/trunk/t/TestApp/lib/TestApp/View.pm

Log:
 r68166 at pinglin:  jesse | 2007-10-17 16:45:22 +0100
 
 * working toward onclick => { submit => { action => $action,    
                                 arguments => { foo => 'value', bar => 'other value'} }}
 
 Jifty's js still needs help


Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml	(original)
+++ jifty/trunk/META.yml	Wed Oct 17 11:46:35 2007
@@ -60,6 +60,7 @@
   Class::Container: 0
   Class::Data::Inheritable: 0
   Class::Trigger: 0.12
+  Clone: 0.27
   Compress::Zlib: 0
   Crypt::CBC: 0
   Crypt::Rijndael: 0
@@ -82,6 +83,7 @@
   File::Find::Rule: 0
   File::MMagic: 0
   File::ShareDir: 0.04
+  File::Spec: 3.14
   HTML::Entities: 0
   HTML::Lint: 0
   HTML::Mason: 1.3101
@@ -95,7 +97,7 @@
   IPC::PubSub: 0.23
   IPC::Run3: 0
   JSON::Syck: 0.15
-  Jifty::DBI: 0.42
+  Jifty::DBI: 0.44
   LWP::UserAgent: 0
   Locale::Maketext::Extract: 0.20
   Locale::Maketext::Lexicon: 0.60
@@ -120,6 +122,7 @@
   Test::LongString: 0
   Test::More: 0.62
   Test::Pod::Coverage: 0
+  Test::WWW::Declare: 0
   Test::WWW::Mechanize: 1.04
   Test::WWW::Selenium: 0
   UNIVERSAL::require: 0

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	Wed Oct 17 11:46:35 2007
@@ -2,6 +2,7 @@
 use strict;
 
 package Jifty::Web::Form::Element;
+use Scalar::Util qw/blessed/;
 
 =head1 NAME
 
@@ -84,8 +85,14 @@
 
 =item submit => MONIKER
 
-An action, moniker of an action, or array reference to such; these
-actions are submitted when the event is fired.
+A Jifty::Action, Jifty::Action moniker, hashref of 
+    { action => Jifty::Action::Subclass, 
+     arguments => { argument => value, argument2 => value2 }
+
+or an arrayref of them.
+
+These actions are submitted when the event is fired. Any arguments 
+specified will override arguments submitted by form field.
 
 =item disable => BOOLEAN
 
@@ -397,18 +404,34 @@
         # since Jifty::Action caches instances of Jifty::Web::Form::Clickable.
         if ( $hook->{submit} ) {
             $hook->{submit} = [ $hook->{submit} ] unless ref $hook->{submit} eq "ARRAY";
-            $hook->{submit} = [ map { ref $_ ? $_->moniker : $_ } @{ $hook->{submit} } ];
+
+            my @submit_tmp;
+            foreach my $submit ( @{$hook->{submit}}) {
+                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'};
+                }
+
+            }
+
+            @{$hook->{submit}} =  @submit_tmp;
         }
 
+        $hook->{args} ||= $hook->{arguments}; # should be able to use 'arguments' and not lose.
+
         if ( $hook->{args} ) {
             # We're going to pass complex query mapping structures
             # as-is to the server, but we need to make sure we're not
             # trying to pass around Actions, merely their monikers.
             for my $key ( keys %{ $hook->{args} } ) {
                 next unless ref $hook->{args}{$key} eq "HASH";
-                $hook->{args}{$key}{$_} = $hook->{args}{$key}{$_}->moniker
-                  for grep { ref $hook->{args}{$key}{$_} }
-                  keys %{ $hook->{args}{$key} };
+                $hook->{args}{$key}{$_} = $hook->{args}{$key}{$_}->moniker for grep { ref $hook->{args}{$key}{$_} } keys %{ $hook->{args}{$key} };
             }
         } else {
             $hook->{args} = {};
@@ -442,7 +465,7 @@
         my $actions = {};    # Maps actions => disable?
         my $confirm;
         my $beforeclick;
-
+        my $action_arguments = {};
         for my $hook (grep {ref $_ eq "HASH"} (@{$value})) {
 
             if (!($self->handler_allowed($trigger))) {
@@ -462,7 +485,11 @@
                 my $disable_form_on_click = exists $hook->{disable} ? $hook->{disable} : 1;
                 # Normalize to 1/0 to pass to JS
                 $disable_form_on_click = $disable_form_on_click ? 1 : 0;
-                $actions->{$_} = $disable_form_on_click for (@{ $hook->{submit} || [] }); 
+                for (@{ $hook->{submit} || [] }) {
+                    $actions->{$_} = $disable_form_on_click;
+                    $action_arguments->{$_} = $hook->{'action_arguments'}->{$_};
+                }
+
             }
 
             $hook->{region} ||= Jifty->web->qualified_region;
@@ -530,11 +557,25 @@
         }
 
         my $string = join ";", (grep {not ref $_} (ref $value eq "ARRAY" ? @{$value} : ($value)));
-        if (@fragments or (!$actions || %$actions)) {
+        if ( @fragments or ( !$actions || %$actions ) ) {
 
-            my $update = Jifty->web->escape("update( ". Jifty::JSON::objToJson( {actions => $actions, fragments => \@fragments, continuation => $self->continuation }, {singlequote => 1}) .", this );");
-            $string .= 'if(event.ctrlKey||event.metaKey||event.altKey||event.shiftKey) return true; ' if ($trigger eq 'onclick');
-            $string .= $self->javascript_preempt ? "return $update" : "$update; return true;";
+            my $update = Jifty->web->escape(
+                "update( "
+                    . Jifty::JSON::objToJson(
+                    {   actions      => $actions,
+                        action_arguments => $action_arguments,
+                        fragments    => \@fragments,
+                        continuation => $self->continuation
+                    },
+                    { singlequote => 1 }
+                    ) . ", this );"
+            );
+            $string
+                .= 'if(event.ctrlKey||event.metaKey||event.altKey||event.shiftKey) return true; '
+                if ( $trigger eq 'onclick' );
+            $string .= $self->javascript_preempt
+                ? "return $update"
+                : "$update; return true;";
         }
         if ($confirm) {
             $string = Jifty->web->escape("if(!confirm(" . Jifty::JSON::objToJson($confirm, {singlequote => 1}) . ")) { Event.stop(event); return false }") . $string;

Modified: jifty/trunk/share/web/static/js/jifty.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty.js	(original)
+++ jifty/trunk/share/web/static/js/jifty.js	Wed Oct 17 11:46:35 2007
@@ -992,6 +992,8 @@
 
 // Update a region.  Takes a hash of named parameters, including:
 //  - 'actions' is an array of monikers to submit
+//  - 'action_arguments' is an array of hashes of arguments which should override any arguments coming from form fields
+//        the hash keys for 'action_arguments' are the values of the 'actions' array
 //  - 'fragments' is an array of hashes, which may have:
 //     - 'region' is the name of the region to update
 //     - 'args' is a hash of arguments to override
@@ -1041,7 +1043,7 @@
     for (var moniker in named_args['actions']) {
         var disable = named_args['actions'][moniker];
         var a = new Action(moniker, button_args);
-	current_actions[moniker] = a; // XXX: how do i make this bloody singleton?
+	    current_actions[moniker] = a; // XXX: how do i make this bloody singleton?
         // Special case for Redirect, allow optional, implicit __page
         // from the response to be used.
         if (a.actionClass == 'Jifty::Action::Redirect')

Added: jifty/trunk/t/TestApp/lib/TestApp/Action/SayHi.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/lib/TestApp/Action/SayHi.pm	Wed Oct 17 11:46:35 2007
@@ -0,0 +1,18 @@
+package TestApp::Action::SayHi;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+
+    param 'name';
+    param 'greeting';
+
+
+};
+
+sub take_action {
+    my $self = shift;
+
+    $self->result->message($self->argument_value('name').', '. $self->argument_value('greeting'));
+}
+
+1;

Modified: jifty/trunk/t/TestApp/lib/TestApp/View.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/View.pm	(original)
+++ jifty/trunk/t/TestApp/lib/TestApp/View.pm	Wed Oct 17 11:46:35 2007
@@ -6,6 +6,26 @@
 
 __PACKAGE__->use_mason_wrapper;
 
+template 'say_hi' => page {
+    my $a = Jifty->web->new_action( class => 'SayHi' );
+    form {
+
+        #render_param($a => 'name');
+        render_param( $a => 'greeting' );
+        Jifty->web->form->submit(
+            label   => _('Create'),
+            onclick => [
+                {   submit => {
+                        action    => $a,
+                        arguments => { name => 'dave' }
+                    }
+                }
+            ]
+        );
+
+    };
+};
+
 template 'concrete2.html' => sub {
     html {
         body {
@@ -110,4 +130,7 @@
     h1 { 'In a Mason Wrapper?' };
 };
 
+
+
+
 1;


More information about the Jifty-commit mailing list