$r->{template} = "list";
}
+sub stringify_column {
+ my $class = shift;
+ return ($class->columns("Stringify"),
+ (grep { $_ ne "id" } $class->primary_columns),
+ (grep { $_ eq "name" } $class->columns)
+ )[0];
+}
+
sub adopt {
my ($self, $child) = @_;
$child->autoupdate(1);
- if (grep { $_ eq "name" } $child->columns) { # Common case
- $child->columns( Stringify => qw/ name / );
- } # Otherwise, work it out for yourself.
+ if (my $col = $child->stringify_column) {
+ $child->columns( Stringify => $col );
+ }
}
sub search :Exported {
#%]
[%
+
MACRO maybe_link_view(object) BLOCK;
IF object.moniker; # It's an object, i.e. a has-a
link(object.moniker, "view", object.id, object);
"<td>";
IF col == "url";
"<A HREF="; item.url; "> "; item.url; "</A>";
- ELSIF col == "name";
+ ELSIF col == item.stringify_column;
maybe_link_view(item);
ELSE;
maybe_link_view(item.$col);
[% INCLUDE header %]
[% FOR item = objects %]
-<h2> [% item.name %]</h2>
+[% SET string = item.stringify_column %]
+<h2> [% item.$string %]</h2>
[% INCLUDE navbar %]
<TABLE class="view">
- <TR><TD class="field">Name</TD><TD> [% item.name %] </TD></TR>
+ <TR><TD class="field">[% classmetadata.colnames.$string %]</TD><TD> [% item.$string %] </TD></TR>
[%
FOR col = classmetadata.columns.list;
- NEXT IF col == "id" OR col == "name";
+ NEXT IF col == "id" OR col == string;
NEXT UNLESS item.$col;
%]
It gets the displayable form of a column's name from the hash returned
from the C<column_names> method:
-%#]
+#%]
<TR>
<TD class="field"> [% classmetadata.colnames.$col; %] </TD>
#One interesting macro used in this template is C<maybe_link_view>:
maybe_link_view(item.$col);
-%]
+%]
[%#