[Bps-public-commit] r17108 - in Prophet/branches/actions: lib/Prophet lib/Prophet/Server lib/Prophet/Server/ViewHelpers
jesse at bestpractical.com
jesse at bestpractical.com
Thu Dec 4 23:28:28 EST 2008
Author: jesse
Date: Thu Dec 4 23:28:27 2008
New Revision: 17108
Modified:
Prophet/branches/actions/lib/Prophet/Record.pm
Prophet/branches/actions/lib/Prophet/Server/Controller.pm
Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm
Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm
Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm
Log:
* Create with webformy magic
Modified: Prophet/branches/actions/lib/Prophet/Record.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Record.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Record.pm Thu Dec 4 23:28:27 2008
@@ -280,6 +280,12 @@
);
}
+
+sub loaded {
+ my $self = shift;
+ return $self->uuid ? 1 : 0;
+}
+
=head2 set_prop { name => $name, value => $value }
Updates the current record to set an individual property called C<$name> to C<$value>
Modified: Prophet/branches/actions/lib/Prophet/Server/Controller.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server/Controller.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Server/Controller.pm Thu Dec 4 23:28:27 2008
@@ -119,6 +119,8 @@
if ($self->actions->{$action}->{action} eq 'update') {
$self->_exec_action_update($self->actions->{$action});
+ } elsif ($self->actions->{$action}->{action} eq 'create') {
+ $self->_exec_action_create($self->actions->{$action});
} else {
die "I don't know how to handle a ".$self->actions->{$action}->{action};
}
@@ -130,6 +132,23 @@
}
+sub _exec_action_create {
+ my $self = shift;
+ my $action = shift;
+
+ die $action->{class} ." is not a valid class " unless (UNIVERSAL::isa($action->{class}, 'Prophet::Record'));
+ my $object = $action->{class}->new( app_handle => $self->app_handle);
+ my ( $val, $msg ) = $object->create(
+ props => {
+ map {
+ $action->{params}->{$_}->{prop} => $action->{params}->{$_}->{value}
+ } keys %{ $action->{params} }
+ }
+
+ );
+ warn $val, $msg;
+
+}
sub _exec_action_update {
my $self = shift;
my $action = shift;
@@ -137,8 +156,6 @@
die $action->{class} ." is not a valid class " unless (UNIVERSAL::isa($action->{class}, 'Prophet::Record'));
my $object = $action->{class}->new( uuid => $action->{uuid}, app_handle => $self->app_handle);
die "Did not find the object " unless $object->uuid;
-
- warn YAML::Dump({ map { $_ -> $action->{props}->{$_}->{value} } keys %{$action->{props}}});
warn "YAY we got ".$object->uuid;
my ( $val, $msg ) = $object->set_props(
props => {
Modified: Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm Thu Dec 4 23:28:27 2008
@@ -48,7 +48,7 @@
sub new {
my $self = shift->SUPER::new(@_);
- $self->name ( $self->record->uuid . "-" . $self->action ) unless ($self->name);
+ $self->name ( ($self->record->loaded ? $self->record->uuid : 'new') . "-" . $self->action ) unless ($self->name);
return $self;
};
Modified: Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm Thu Dec 4 23:28:27 2008
@@ -37,12 +37,14 @@
name => $self->_generate_name(),
record => $self->function->record,
label => $self->prop,
- value => $self->function->record->prop( $self->prop )
+ value => ($self->function->record->loaded ? $self->function->record->prop( $self->prop ) : ''),
+
);
my $orig = Prophet::Web::Field->new(
name => "original-value-". $self->_generate_name(),
- value => $self->function->record->prop( $self->prop ),
+ value =>
+ ($self->function->record->loaded ? $self->function->record->prop( $self->prop ) : ''),
type => 'hidden'
);
outs_raw( $orig->render_input );
Modified: Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm
==============================================================================
--- Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm (original)
+++ Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm Thu Dec 4 23:28:27 2008
@@ -23,12 +23,24 @@
$c->matching(sub { return 1});
my $r = $c->items->[0];
h1 { $r->prop('title')};
+
+
form {
my $f = function( record => $r, action => 'update');
widget( function => $f, prop => 'title');
+ input {attr { label => 'save', type => 'submit'}};
+ };
+
+ form {
+ my $f = function( record => App::WebToy::Model::WikiPage->new(app_handle => $self->app_handle ),
+ action => 'create');
+ widget( function => $f, prop => 'title');
input {attr { label => 'save', type => 'submit'}};
- }
+
+}
+
+
};
More information about the Bps-public-commit
mailing list