basic example with lots to do such as berrs, brewery, adding handpumps
to pubs, styles.
git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@505
48953598-375a-da11-a14b-
00016c27c3ee
# Columns to display
sub BeerDB::Handpump::display_columns { qw/pub beer/ }
-sub BeerDB::Pint::display_columns { qw/drinker handpump/ }
sub BeerDB::Person::display_columns { qw/first_name last_name dob email/ }
BeerDB->config->{loader}->relationship($_) for (
$r->template_args->{classmetadata}{cgi} = { $self->to_cgi(@cols) };
}
+
+# Template switcheroo bug bit me -- was seeing view page but the view action was never
+# being executed after an edit.
+sub do_edit : Exported {
+ my ($self, $r) = (shift, shift);
+ $self->SUPER::do_edit($r, @_);
+ if (my $obj = $r->object) {
+ my $url = $r->config->uri_base . "/" . $r->table . "/view/" . $obj->id;
+ $r->redirect_request(url => $url);
+ }
+}
+
+sub metadata: Exported {}
+
+
1;
my ($self, $r, $obj) = @_;
$self->_croak( "Object method only") unless $obj;
- if ($r->params->{submit} eq 'drink') {
- $r->params->{drinker} = $self;
- my ($pint, $errs) = $self->related_class($r, 'pints')->create_from_cgi($r);
- $r->template_args->{errors} = $errs if $errs;
+ if ($r->params->{submit}) {
+ my ($pint) = $obj->add_to_from_cgi($r);
+ if (my $errs = $obj->cgi_update_errors) {
+ $r->template_args->{errors} = $errs;
+ }
}
my %cgi = $self->to_cgi('pints');
- $cgi{pints}{drinker} = $obj->to_field(drinker => 'link_hidden', {r => $r});
+ delete $cgi{pints}{drinker}; # = $obj->to_field(drinker => 'link_hidden', {r => $r});
$r->template_args->{classmetadata}{cgi} = \%cgi ;
}
--- /dev/null
+<h3> Class::DBI meta info for [% classmetadata.name %] </h3>
+[%
+ USE this = Class(classmetadata.name);
+ USE Dumper; Dumper.dump(this.meta_info);
+%]
<div id="search">
<form action="[% base _ "/" _ request.table _ "/" _ request.action _ "/" _ object.id %]" method="post">
<fieldset>
-<legend> Drink a beer </legend>
+<legend> Drink a pint </legend>
[%
- INCLUDE display_inputs classmetadata.columns=['pints'] ;%]
-
+ INCLUDE display_inputs classmetadata.columns=['pints'] ;
+%]
<input type='submit'name='submit' value='Hellyeah!'\>
+
</fieldset>
</form>