sub is_applicable {
my $self = shift;
my $config = $self->config;
- my %ok = map {$_ => 1} @{$config->{display_tables}};
+ $config->{ok_tables} = {map {$_ => 1} @{$config->{display_tables}}};
warn "We don't have that table ($self->{table})"
- unless $ok{$self->{table}};
- return DECLINED() unless exists $ok{$self->{table}};
+ unless $config->{ok_tables}{$self->{table}};
+ return DECLINED() unless exists $config->{ok_tables}{$self->{table}};
# Does the action method exist?
# XXX We should set the method class to the class for the table
package Apache::MVC::Model::CDBI;
use base qw(Apache::MVC::Model::Base Class::DBI);
+use Lingua::EN::Inflect::Number qw(to_PL);
use Class::DBI::AsForm;
use Class::DBI::FromCGI;
use CGI::Untaint;
return $self->retrieve(shift @{$r->{args}});
}
+sub related {
+ my ($self, $r) = @_;
+ # 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) = @_;
my $h = CGI::Untaint->new(%{$r->{params}});
name => $class,
columns => [ $class->columns ],
colnames => { $class->column_names },
+ related_accessors => [ $class->related($r) ],
moniker => $class->moniker,
plural => $class->plural_moniker,
cgi => { $class->to_cgi },
</TD>
[% END %]
+[% MACRO view_related(object) BLOCK;
+ FOR accessor = classmetadata.related_accessors.list;
+ "<H3>"; accessor | ucfirst; "</H3>\n";
+ "<UL id=\"vlist\">";
+ FOR thing = object.$accessor;
+ "<LI>"; maybe_link_view(thing); "</LI>\n";
+ END;
+ "</UL>";
+ END;
+END;
+%]
[% END; %]
</TABLE>
[%
+ view_related(item);
button(item, "edit");
button(item, "delete");
%]
-</TABLE>
[% END; %]