use Class::DBI::AsForm;
use Class::DBI::FromCGI;
use Class::DBI::AbstractSearch;
+use Class::DBI::Plugin::RetrieveAll;
use Class::DBI::Pager;
use CGI::Untaint;
use strict;
sub list :Exported {
my ($self, $r) = @_;
+ my %ok_columns = map {$_ => 1} $self->columns;
if ( my $rows = $r->config->{rows_per_page}) {
$self = $self->pager($rows, $r->query->{page});
$r->{template_args}{pager} = $self;
}
- $r->objects([ $self->retrieve_all ]);
+ my $order;
+ if ($order = $r->query->{order} and $ok_columns{$order}) {
+ $r->objects([ $self->retrieve_all_sorted_by( $order.
+ ($r->query->{o2} eq "desc" && " DESC")
+ )]);
+ } else {
+ $r->objects([ $self->retrieve_all ]);
+ }
}
1;
<TR>
[% FOR col = classmetadata.columns.list;
NEXT IF col == "id";
- "<TH>"; classmetadata.colnames.$col; "</TH>";
+ "<TH>";
+ '<A HREF="'; base; classmetadata.moniker; "/list/?";
+ "page=" _ pager.current_page _ "&" IF pager;
+ "order="; col;
+ "&o2=desc" IF col == request.query.order and request.query.o2 != "desc";
+ '">';
+ classmetadata.colnames.$col;
+ '</A>';
+ "</TH>";
END %]
</TR>
IF num == pager.current_page;
"["; num; "] ";
ELSE;
- '<A HREF="'; base; table; "/list/?page="; num; '">';
+ '<A HREF="'; base; classmetadata.moniker; "/list/?page="; num; '">';
"["; num; "]";
'</A> ';
END;