<a name="<% $class %>"></a>

% if (($link1) || ($link2)) {
<div class="jump">
% if ($link1) {
  <a href="#<% $link1 %>"><img src="/media/images/<% "$lang_key/$img1" %>_dgreen.gif"></a>
% } if ($link2) {
  <a href="#<% $link2 %>"><img src="/media/images/<% "$lang_key/$img2" %>_dgreen.gif"></a>
% }
</div>
% }
<div class="desk-top">
  <h1><% $caption %></h1>
  <div class="sort">
    <label for="<% $class %>_sort_by"><% $lang->maketext('Sort By') %>:</label> 
    <& '/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)"},
    &>
  </div>
</div>

<div class="desk">
<%args>
$class => 'story'
$caption => ''
$sort_by_val => undef
$others => {}
</%args>
<%init>;
$caption ||= $pl_names->{$class};
$sort_by_val = get_pref('Default Asset Sort') unless defined $sort_by_val;
my ($link1, $link2, $lab1, $lab2, $img1, $img2);
if ($class eq 'story') {
    ($link1, $lab1, $img1) = ('media', $pl_names->{media}, 'media') if $others->{media};
    ($link2, $lab2, $img2) = ('template', $pl_names->{template}, 'templates')
      if $others->{template};
} elsif ($class eq 'media') {
    ($link1, $lab1, $img1) = ('story', $pl_names->{story}, 'stories') if $others->{story};
    ($link2, $lab2, $img2) = ('template', $pl_names->{template}, 'templates')
      if $others->{template};
} else {
    ($link1, $lab1, $img1) = ('story', $pl_names->{story}, 'stories') if $others->{story};
    ($link2, $lab2, $img2) = ('media', $pl_names->{media}, 'media') if $others->{media};
}

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
};
</%once>
