[Jifty-commit] r3364 - in jifty/trunk: lib/Jifty/Web/Form
share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Jun 5 18:52:49 EDT 2007
Author: clkao
Date: Tue Jun 5 18:52:47 2007
New Revision: 3364
Modified:
jifty/trunk/lib/Jifty/Web/Form.pm
jifty/trunk/lib/Jifty/Web/Form/Element.pm
jifty/trunk/share/web/static/js/jifty.js
Log:
Implement "submit => undef" in onclick hook where it should submit all actions.
Modified: jifty/trunk/lib/Jifty/Web/Form.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form.pm Tue Jun 5 18:52:47 2007
@@ -218,9 +218,22 @@
sub submit {
my $self = shift;
- my $button = Jifty::Web::Form::Clickable->new(submit => undef, @_)->generate;
+ my $button = Jifty::Web::Form::Clickable->new(submit => undef, @_);
+ my ($spa) = Jifty->find_plugin('Jifty::Plugin::SinglePage');
+ if ($spa) {
+ # XXX: move to _sp_link hook.
+ if ($button->onclick) {
+ Carp::cluck "already has onclick, fix me later";
+ }
+ else {
+ my $submit = delete $button->{submit};
+ $button->onclick({ submit => $submit },
+ refresh_self => 1);
+ }
+ }
+
Jifty->web->out(qq{<div class="submit_button">});
- $button->render_widget;
+ $button->generate->render_widget;
Jifty->web->out(qq{</div>});
return '';
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 Jun 5 18:52:47 2007
@@ -236,7 +236,7 @@
next unless $value;
my @fragments;
- my %actions; # Maps actions => disable?
+ my $actions; # Maps actions => disable?
my $confirm;
my $beforeclick;
@@ -246,10 +246,11 @@
# Submit action
if ( $hook->{submit} ) {
+ %$actions = ();
my $disable = exists $hook->{disable} ? $hook->{disable} : 1;
# Normalize to 1/0 to pass to JS
$disable = $disable ? 1 : 0;
- $actions{$_} = $disable for (@{ $hook->{submit} });
+ $actions->{$_} = $disable for (@{ $hook->{submit} });
}
$hook->{region} ||= Jifty->web->qualified_region;
@@ -317,9 +318,9 @@
}
my $string = join ";", (grep {not ref $_} (ref $value eq "ARRAY" ? @{$value} : ($value)));
- if (@fragments or %actions) {
+ if (@fragments or (!$actions || %$actions)) {
- my $update = Jifty->web->escape("update( ". Jifty::JSON::objToJson( {actions => \%actions, fragments => \@fragments }, {singlequote => 1}) .", this );");
+ my $update = Jifty->web->escape("update( ". Jifty::JSON::objToJson( {actions => $actions, fragments => \@fragments }, {singlequote => 1}) .", this );");
$string .= $self->javascript_preempt ? "return $update" : "$update; return true;";
}
if ($confirm) {
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 Tue Jun 5 18:52:47 2007
@@ -740,6 +740,12 @@
// Grab extra arguments (from a button)
var button_args = Form.Element.buttonFormElements(trigger);
+ // If the action is null, take all actions
+ if (named_args['actions'] == null) {
+ named_args['actions'] = {};
+ // default to disable fields
+ Form.getActions(Form.Element.getForm(trigger)).map(function(x){named_args['actions'][x.moniker] = 1 });
+ }
// Build actions structure
request['actions'] = $H();
for (var moniker in named_args['actions']) {
More information about the Jifty-commit
mailing list