<& '/widgets/profile/hidden.mc',
    name    => "$widget|update_cb",
    value   => 1,
&>

<%perl>
my $rightText = $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|trail_cb",
  image    => "view_trail_teal",
  alt      => 'Trail',
) . '&nbsp;';

$rightText .= $m->scomp( '/widgets/profile/imageSubmit.mc',
  formName => "theForm",
  callback => $widget . "|notes_cb",
  image    =>  $story->has_notes ? 'note_fill' : "note",
  alt      => 'Notes',
  useGlobalImage => 1,
  value    => 'edit'
);

$m->comp("/widgets/wrappers/sharky/table_top.mc",
         caption => "Information",
         number  => $num++,
         id      => 'storyinfo',
         rightText => $rightText

);

</%perl>
<dl class="viewmeta">
  <dt><% $lang->maketext('UUID') %>:</dt>
  <dd title="ID: <% $story->get_id %>"><% $story->get_uuid %></dd>
  <dt><% $lang->maketext('Story Type') %>:</dt>
  <dd><% $story->get_element_name || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Current Version') %>:</dt>
  <dd><% $story->get_current_version %></dd>
  <dt><% $lang->maketext('Published Version') %>:</dt>
  <dd><% $story->get_published_version || '&nbsp;' %></dd>
  <dt><% $lang->maketext('First Published') %>:</dt>
  <dd><% $story->get_first_publish_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('Last Published') %>:</dt>
  <dd><% $story->get_publish_date || '&nbsp;' %></dd>
  <dt><% $lang->maketext('URI') %>:</dt>
% if (@ocs == 1) {
  <dd><% $m->comp(
      '/widgets/profile/preview_link.mc',
      doc => $story,
  )%></dd>
% } else {
% my $oc_opts = [
%     map { [ $_->get_id => $_->get_name ] }
%         $story->get_output_channels
% ];
  <dd><% $story->get_primary_uri %></dd>
  <dt><% $lang->maketext('Preview in') %>:</dt>
  <dd><&
          '/widgets/profile/select.mc',
          options => $oc_opts,
          name    => 'ocSelect',
          useTable => 0,
          value   => $story->get_primary_oc_id,
      &>
      <% $m->comp('/widgets/profile/preview_link.mc',
      type  => 'story',
      value => $story->get_primary_uri,
      doc   => $story,
      oc_js => 'window.document.theForm.ocSelect.options[window.document.theForm.ocSelect.selectedIndex].value',
       style => 'blackUnderlinedLink',
) %></dd>
% }
% if (@$sites > 1) {
  <dt><% $lang->maketext('Site') %>:</dt>
  <dd><% Bric::Biz::Site->lookup({id => $story->get_site_id})->
  get_name() %></dd>
% }
</dl>

<div class="editmeta">
<& '/widgets/select_object/select_object.mc',
  object   => 'source',
  name     => "$widget|source__id",
  field    => 'source_name',
  selected => $story->get_source__id,
  indent   => 0,
  useTable => 1,
  disp     => "Source",
  exclude => sub { !chk_authz($_[0], READ, 1) },
&>
<& '/widgets/profile/displayFormElement.mc',
   objref => $story,
   key => 'priority',
&>
<& '/widgets/profile/displayFormElement.mc',
   objref => $story,
   key => 'title',
&>
<& '/widgets/profile/displayFormElement.mc',
   objref => $story,
   key => 'description',
&>
<& '/widgets/profile/displayFormElement.mc',
   vals => $slug_vals,
   id => 'slug',
   key => 'slug',
&>
<%perl>;
TZ: {
    # XXX Yes, ugly hack, but it's the best way to prevent the
    # user's preferences from affecting the time zone.
    local $HTML::Mason::Commands::session{_bric_user}->{object} = undef;
    $m->comp(
        '/widgets/profile/displayFormElement.mc',
        objref => $story,
        key    => 'cover_date',
    );
}
</%perl>
<& '/widgets/profile/displayFormElement.mc',
   objref => $story,
   key => 'expire_date',
&>
</div> <!-- .editmeta -->
<& '/widgets/wrappers/sharky/table_bottom.mc' &>

<%perl>;
$num = $m->comp('/widgets/container_prof/container_prof.mc',
        element            => $element,
        element_type       => 'story',
        action          => $story->get_alias_id ? 'view' : 'edit',
        title           => 'Content',
        num             => $num,
        start_count     => 4
);
</%perl>
% unless (ENABLE_CATEGORY_BROWSER) {
% $m->comp("/widgets/wrappers/sharky/table_top.mc",
%        caption => "Categories",
%        number  => $num++);

% my @cat = $story->get_categories;
% my $primary = $story->get_primary_category();
% my $p_id    = $primary ? $primary->get_id : '';
% my $rowspan = scalar (@cat) + 2;

<table class="listManager">
<tr>
  <th><% $lang->maketext('Name') %></th>
  <th><% $lang->maketext('URI') %></th>
  <th class="radio"><% $lang->maketext('Primary') %></th>
  <th class="checkbox"><% $lang->maketext('Delete') %></th>
</tr>
% # BEGIN FOREACH CAT
% my $curr_cats = {};
% foreach (sort { $a->get_uri cmp $b->get_uri } @cat) {
%     my $cat_id = $_->get_id;
%     $curr_cats->{$cat_id} = 1;
  <tr>
    <td><% $_->get_name %></td>
    <td><% $_->get_uri %></td>
    <td class="radio">
<& "/widgets/profile/radio.mc",
    disp        => '',
    value       => $_->get_id,
    name        => "$widget|primary_cat",
    js          => '',
    req         => 0,
    checked     => ($cat_id == $p_id),
&>
    </td>
    <td class="checkbox">
% if ($cat_id != $p_id) {
<& '/widgets/profile/checkbox.mc',
        name => "$widget|delete_cat",
        value => $_->get_id
&>
% }
&nbsp;
    </td>
  </tr>
% }
% # END FOREACH CAT


% if (!@cat) {
<tr>
  <td colspan="4"><% $lang->maketext('This story has not been assigned to a category.')%></td>
</tr>
% } else {

<tr>
  <td colspan="3">&nbsp;</td>
  <td align="center" valign="middle">
  <& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Delete Categories"),
    widget    => $widget,
    cb        => 'delete_cat_cb',
    button    => 'delete_red',
    useTable  => 0 &>
  </td>
</tr>
% }

</table>
% # Create the subroutine to exclude categories.
% my $excl_sub = sub { $curr_cats->{$_[0]->get_id} || ! chk_authz($_[0], READ, 1) };

<div class="actions">
<&
  '/widgets/profile/imageSubmit.mc',
             formName => "theForm",
             callback => "$widget|add_category_cb",
             image    => "add_category_lgreen",
             alt      => 'Add Category',
             vspace   => 3,
             hspace   => 2
&>
<& '/widgets/select_object/select_object.mc',
        object => 'category',
        name => "$widget|new_category_id",
        constrain => { site_id => $story->get_site_id },
        exclude => $excl_sub,
        field => 'uri',
        sort_field => 'uri',
        useTable => 0
&>
</div>

<%perl>;
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

}   # unless ENABLE_CATEGORY_BROWSER

if (ENABLE_OC_ASSET_ASSOCIATION) {
    $m->comp('/widgets/profile/asset_ocs.mc',
             asset  => $story,
             widget => $widget,
             ocs    => \@ocs,
             num    => $num++,
             at_ocs => \@aocs
         );
}

$m->comp("/widgets/wrappers/sharky/table_top.mc",
       caption => "Associations",
       number  => $num++);
</%perl>

% my $rowColor = "even";
<table class="associations">
% if (ENABLE_CATEGORY_BROWSER) {
% $rowColor = $rowColor eq "odd" ? "even" : "odd";
<tr class="<% $rowColor %>">
<th><% $lang->maketext('Categories') %>:</th>
<td><%perl>
my @cats;
my $primary_cat_uri = $story->get_primary_category->get_uri;
push @cats, $primary_cat_uri;
foreach my $cat ($story->get_secondary_categories) {
    push @cats, $cat->get_uri;
}
$m->out(scalar(@cats) ? join('<br />', @cats) : $lang->maketext("No categories defined."));
</%perl></td>
<td class="edit"><& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Edit"),
    widget    => $widget,
    cb        => 'categories_cb',
    button    => 'pencil',
    useTable  => 0,
    globalImage => 1 &></td>
</tr>
% }

% $rowColor = $rowColor eq "odd" ? "even" : "odd";
<tr class="<% $rowColor %>">
<th><% $lang->maketext('Contributors') %>:</th>
<td><%perl>
my @contribs;
foreach my $cntr ($story->get_contributors) {
    push @contribs,  $cntr->get_name;
}
$m->out(scalar(@contribs) ? join(", ", @contribs) : $lang->maketext("No contributors defined."));

</%perl></td>
<td class="edit">
% unless ($story->get_alias_id) {
<& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Edit"),
    widget    => $widget,
    cb        => 'contributors_cb',
    button    => 'pencil',
    useTable  => 0,
    globalImage => 1 &>
% }
</td>
</tr>

% $rowColor = $rowColor eq "odd" ? "even" : "odd";
<tr class="<% $rowColor %>">
<th><% $lang->maketext('Keywords') %>:</th>
<td><%perl>
my @keywords;
foreach my $kw ($story->get_keywords) {
    push @keywords, $kw->get_name;
}

$m->out(scalar(@keywords) ? join(", ", @keywords) : $lang->maketext("No keywords defined."));

</%perl></td>
<td class="edit"><& '/widgets/profile/button.mc',
    disp      => $lang->maketext("Edit"),
    widget    => $widget,
    cb        => 'keywords_cb',
    button    => 'pencil',
    useTable  => 0,
    globalImage => 1 &></td>
</tr>
</table>
<%perl>

$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

$m->comp("/widgets/profile/buttonBar.mc",
         widget      => $widget,
         desks       => $desks,
         cd          => $cd,
         obj         => $story,
);

</%perl>
<%args>
$widget
</%args>
<%init>
my $story   = get_state_data($widget, 'story');
my $element    = $story->get_element();
my $id = $story->get_id;
my $wf_id = get_state_data($widget, 'work_id');
$wf_id = $story->get_workflow_id() unless $wf_id;
my $wf = Bric::Biz::Workflow->lookup( { id => $wf_id });
my $desks = $wf->allowed_desks();
my $cd = $story->get_current_desk();
$cd = $wf->get_start_desk() unless $cd;
my $num = 1;
my $sites = $c->get('__SITES__') || Bric::Biz::Site->list({ active => 1 });

# get output channel info
my $asset_type = $story->get_element_type;
my @aocs = $asset_type->get_output_channels;
my @ocs = $story->get_output_channels;

# Set slug required if it is
my $slug_req = 0;
unless (ALLOW_SLUGLESS_NONFIXED || $story->is_fixed) {
    # This isn't a Cover (it's non-fixed) and ALLOW_SLUGLESS_NONFIXED
    # is false, so we make slug required
    $slug_req = 1;
}
my $slug_vals = {
    %{ Bric::Biz::Asset::Business::Story->my_meths->{slug} },
    value => $story->get_slug,
    req => $slug_req,
};
</%init>
