[Jifty-commit] r3377 - in jifty/trunk: lib/Jifty/Plugin
lib/Jifty/Web share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jun 6 22:24:06 EDT 2007
Author: clkao
Date: Wed Jun 6 22:24:03 2007
New Revision: 3377
Modified:
jifty/trunk/lib/Jifty/Plugin/SinglePage.pm
jifty/trunk/lib/Jifty/Web/Form.pm
jifty/trunk/share/web/static/js/jifty.js
jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
Log:
In SPA mode, allow Action::Redirect to happen within webservice and have
the client js accepts it.
Modified: jifty/trunk/lib/Jifty/Plugin/SinglePage.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/SinglePage.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/SinglePage.pm Wed Jun 6 22:24:03 2007
@@ -20,9 +20,7 @@
my $url = $args->{'url'};
if ( $url && $url !~ m/^#/ ) {
delete $args->{'url'};
-
# XXX mind the existing onclick
- use Data::Dumper;
warn 'ooops got original onclick' . Dumper( $args->{onclick} )
if $args->{onclick};
$args->{onclick} = {
@@ -31,6 +29,11 @@
args => delete $args->{parameters}
};
}
+ elsif (exists $args->{submit}) {
+ $args->{onclick} = { submit => delete $args->{submit} };
+ $args->{refresh_self} = 1;
+ $args->{as_button} = 1;
+ }
my $onclick = $args->{onclick};
if ( ref($onclick) eq 'HASH' ) {
if ( $onclick->{region} && !ref( $onclick->{region} ) ) {
Modified: jifty/trunk/lib/Jifty/Web/Form.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form.pm Wed Jun 6 22:24:03 2007
@@ -218,22 +218,9 @@
sub submit {
my $self = shift;
- 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);
- }
- }
-
+ my $button = Jifty::Web::Form::Clickable->new(submit => undef, @_)->generate;
Jifty->web->out(qq{<div class="submit_button">});
- $button->generate->render_widget;
+ $button->render_widget;
Jifty->web->out(qq{</div>});
return '';
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 Jun 6 22:24:03 2007
@@ -746,13 +746,21 @@
// default to disable fields
var form = Form.Element.getForm(trigger);
if (form)
- Form.getActions(form).map(function(x){named_args['actions'][x.moniker] = 1 });
+ Form.getActions(form).map(function(x){
+ named_args['actions'][x.moniker] = 1;
+ });
}
// Build actions structure
request['actions'] = $H();
+ var optional_fragments;
for (var moniker in named_args['actions']) {
var disable = named_args['actions'][moniker];
var a = new Action(moniker, button_args);
+ // Special case for Redirect, allow optional, implicit __page
+ // from the response to be used.
+ if (a.actionClass == 'Jifty::Action::Redirect')
+ optional_fragments = [ prepare_element_for_update({'mode':'Replace','args':{},'region':'__page','path': a.fields().last().value}) ];
+
if (a.register) {
if (a.hasUpload())
return true;
@@ -786,13 +794,14 @@
// Grab the XML response
var response = transport.responseXML.documentElement;
// Loop through the result looking for it
+ var expected_fragments = optional_fragments ? optional_fragments : named_args['fragments'];
for (var response_fragment = response.firstChild;
response_fragment != null && response_fragment.nodeName == 'fragment';
response_fragment = response_fragment.nextSibling) {
var f;
- for (var i = 0; i < named_args['fragments'].length; i++) {
- f = named_args['fragments'][i];
+ for (var i = 0; i < expected_fragments.length; i++) {
+ f = expected_fragments[i];
if (response_fragment.getAttribute("id") == f['region'])
break;
}
Modified: jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm (original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm Wed Jun 6 22:24:03 2007
@@ -70,4 +70,16 @@
};
+before '__jifty/webservices/*' => run {
+ my (@actions) = grep { $_->class eq 'Jifty::Action::Redirect' } values %{ Jifty->web->request->{'actions'} };
+ $_->active(0) for @actions;
+};
+
+on qr{(__jifty/webservices/.*)} => run {
+ use Data::Dumper;
+ for $act (@actions) {
+ warn Dumper($act);
+ }
+};
+
1;
More information about the Jifty-commit
mailing list