% if ( my @links = $jump_to->($class, $offset, $show_all, $others) ) {
% }
<% $caption %>
<& '/widgets/profile/select.mc',
value => $sort_by_val,
useTable => 0,
width => 100,
options => $sort_by->{$class},
name => $class . '_sort_by',
js => qq{onchange="location.href='} . $r->uri . "?${class}_sort_by=' + " . qq{escape(this.options[this.selectedIndex].value)"},
&>
<%args>
$class => 'story'
$caption => ''
$sort_by_val => undef
$others => {}
$show_all => undef
$offset => undef
%args>
<%init>;
$caption ||= $pl_names->{$class};
$sort_by_val = get_pref('Default Asset Sort') unless defined $sort_by_val;
my $sites = $c->get('__SITES__');
unless ($sites) {
$sites = Bric::Biz::Site->list({ active => 1 });
$c->set('__SITES__', $sites);
}
if (@$sites > 1) {
$sort_by->{$_}[5] ||= [ site_id => 'Site'] for qw(story media template);
} else {
delete $sort_by->{$_}[5] for qw(story media template);
}
%init>
<%once>;
my $sort_by = {
story => [
[ name => 'Title' ],
[ uri => 'Primary URI' ],
[ cover_date => 'Cover Date' ],
[ element_type => 'Story Type' ],
[ priority => 'Priority' ],
],
media => [
[ name => 'Title' ],
[ uri => 'Primary URI' ],
[ cover_date => 'Cover Date' ],
[ element_type => 'Media Type' ],
[ priority => 'Priority' ],
],
template => [
[ name => 'File Name' ],
[ deploy_date => 'Deployed Date' ],
[ output_channel => 'Output Channel' ],
[ priority => 'Priority' ],
]
};
my $pl_names = {
story => get_class_info('story')->get_plural_name,
media => get_class_info('media')->get_plural_name,
template => get_class_info('template')->get_plural_name
};
my $offset_by = sub {
my ($type, $offset, $others) = @_;
my $per_page = get_pref('Search Results / Page') or return;
return 0 if $type eq 'story';
my $prev = $others->{story};
$prev += $others->{media} if $type eq 'template';
return int $prev / $per_page;
};
my $jump_to = sub {
my ($type, $offset, $show_all, $others) = @_;
my $per_page = get_pref('Search Results / Page');
my @links;
if ($show_all || !$per_page) {
for my $what qw(story media template) {
push @links, {
link => "#$what",
label => $pl_names->{$what},
} unless $type eq $what or !$others->{$what};
}
return @links;
}
for my $what qw(story media template) {
next if $type eq $what or !$others->{$what};
my $starts_on = $offset_by->($type, $offset, $others);
if (defined $starts_on) {
if ($starts_on == $offset) {
push @links, {
link => "#$what",
label => $pl_names->{$what},
};
} else {
push @links, {
link => $r->uri . "?offset=$starts_on#$what",
label => $pl_names->{$what},
};
}
}
}
return @links;
};
%once>