- # Has-many methods; XXX this is a hack
- map {to_PL($_)}
- grep { exists $r->{config}{ok_tables}{$_} }
- map {$_->table}
- keys %{shift->__hasa_list || {}}
+sub do_edit : Exported
+{
+ my ($self, $r, $obj) = @_;
+
+ my $config = $r->config;
+ my $table = $r->table;
+
+ my $required_cols = $config->{$table}->{required_cols} || [];
+
+ ($obj, my $fatal, my $creating) = $self->_do_update_or_create($r, $obj, $required_cols);
+
+ # handle errors, if none, proceed to view the newly created/updated object
+ my %errors = $fatal ? (FATAL => $fatal) : $obj->cgi_update_errors;
+
+ if (%errors)
+ {
+ # Set it up as it was:
+ $r->template_args->{cgi_params} = $r->params;
+ $r->template_args->{errors} = \%errors;
+
+ undef $obj if $creating;
+ $r->template("edit");
+ }
+ else
+ {
+ $r->template("view");
+ }
+
+ $r->objects( $obj ? [$obj] : []);