CGI-Widget-DBI-Browse
view release on metacpan or search on metacpan
lib/CGI/Widget/DBI/Browse.pm view on Meta::CPAN
'&', @cume_category_filters, '_browse_skip_to_results_=1', $extra_vars||(),
).'" class="breadcrumbNavLink" id="skipToResultsLink"><span>'.$ws->translate('Show all items in this category').'</span></a></i>';
} elsif ($q->param('_browse_skip_to_results_')) {
$self->{'category_title'} .= ' ('.$ws->translate('all results').')';
} elsif (! $self->{-skip_to_results}) {
# -skip_to_results typically used for searching, so don't add anything to the title
$self->{'category_title'} .= ' ('.$ws->translate('results').')';
}
$self->configure_grid_or_table_view() if ! $self->is_browsing();
$ws->{-optional_header} .= '<div id="breadcrumbNavDiv">'.join(' > ', @{ $self->{'breadcrumb_links'} }).$skip_to_results.'</div>'
. '<div class="categoryContentDiv" id="categoryContentDiv-'.join('__', @{ $self->{'breadcrumbs'} }).'"></div>'; # available for CSS-configured content
$self->{'_added_breadcrumbs'} = 1;
}
sub grid_layout_enabled {
my ($self) = @_;
return ! $self->{-default_grid_layout} && $self->{q}->param('grid_layout')
|| $self->{-default_grid_layout} && ! $self->{q}->param('no_grid_layout');
}
sub configure_grid_or_table_view {
my ($self) = @_;
my $ws = $self->{ws};
my $grid_layout_on = $self->grid_layout_enabled();
if ($grid_layout_on) {
$ws->{-display_mode} = 'grid';
$ws->{-grid_columns} ||= 4; # TODO: should call _set_display_defaults() somehow, but can't from outside $ws->display_results()
if ($ws->{-max_results_per_page} % $ws->{-grid_columns} != 0) {
# logic to round -max_results_per_page up to next integer large enough to be divisible by -grid_columns
$ws->{-max_results_per_page} = (int($ws->{-max_results_per_page} / $ws->{-grid_columns}) + 1) * $ws->{-grid_columns};
}
}
my $extra_vars = $ws->extra_vars_for_uri([ qw/grid_layout no_grid_layout/ ]);
$ws->{-optional_header} .= '<div id="gridTableViewLinkDiv" style="float: right;">'.$ws->translate('view').': '
. ($grid_layout_on
? '<a href="?'.($self->{-default_grid_layout} ? 'no_grid_layout=1&' : '').$extra_vars.'">'.$ws->translate('table').'</a> | <b>'.$ws->translate('grid').'</b>'
: '<b>'.$ws->translate('table').'</b> | <a href="?'.($self->{-default_grid_layout} ? '' : 'grid_layout=1&').$extra_vars.'">'.$ws->translate('grid').'</a>')
. '</div>';
}
sub _uri_param_pair {
my ($key, $val) = @_;
return uri_escape($key).'='.uri_escape_utf8($val||'');
}
sub link_for_category_column {
my ($self, $category_col, $row, @exclude_params) = @_;
my (@cols, $col_found);
foreach (@{ $self->{-category_columns} }) {
push(@cols, $_);
if ($_ eq $category_col) {
$col_found = 1;
last;
}
}
my $extra_vars = $self->{ws}->extra_vars_for_uri([ @{ $self->{'filter_columns'} }, '_browse_skip_to_results_', @exclude_params ]);
my $category_decoded = $self->decode_utf8($row->{$category_col});
return $col_found
? '<a href="?'.join('&', (map { _uri_param_pair($_, $self->decode_utf8($row->{$_})) } @cols), $extra_vars || ()).'" id="jumpToCategoryLink">'
.$category_decoded.'</a>'
: $category_decoded;
}
sub _category_columndata_closure {
my ($self, $category_col) = @_;
my $existing_category_filters =
join('&', map { _uri_param_pair($_, $self->decode_utf8(scalar $self->{q}->param($_))) } @{ $self->{'filter_columns'} });
my $before_link_closure = $self->{-category_before_link_closures}->{$category_col};
my $column_closure = $self->{-category_column_closures}->{$category_col};
my @filter_columns = @{ $self->{'filter_columns'} };
return sub {
my ($sd, $row) = @_;
my $category_decoded = $sd->decode_utf8($row->{$category_col}) || '(empty)';
my $category_display_value = ref $column_closure eq 'CODE' ? $column_closure->($sd, $row) : $category_decoded;
my $extra_vars = $sd->extra_vars_for_uri([ @filter_columns, '_browse_skip_to_results_' ]);
return ($before_link_closure ? $before_link_closure->($sd, $row) : '').'<a href="?'.join(
'&', $existing_category_filters || (),
_uri_param_pair($category_col, $category_decoded),
$extra_vars || (),
).'" id="categoryNavLink-'.CGI::escapeHTML($category_decoded).'">'.$category_display_value.'</a>'; # TODO: HTML::Escape is faster than CGI
};
}
1;
__END__
=back
=head1 AUTHOR
Adi Fairbank <adi@adiraj.org>
=head1 COPYRIGHT
Copyright (C) 2008-2014 Adi Fairbank
=head1 COPYLEFT (LICENSE)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 LAST MODIFIED
Dec 7, 2014
=cut
( run in 0.706 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )