[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Gervase Markham <gerv@gerv.net>
  #                 Vaskin Kissoyan <vkissoyan@yahoo.com>
  #                 Frédéric Buclin <LpSolit@gmail.com>
  #                 Guy Pyrzak <guy.pyrzak@gmail.com>
  #%]

<div id="status">
  [% INCLUDE bug/field.html.tmpl
      no_tds = 1
      field  = bug_fields.bug_status
      value  = bug.bug_status
      override_legal_values = bug.statuses_available
      editable = bug.statuses_available.size > 1
  %]

  [% IF bug.resolution OR bug.check_can_change_field('resolution', bug.resolution, 1) %]
    <noscript><br>resolved&nbsp;as&nbsp;</noscript>
  [% END %]

  <span id="resolution_settings">
  [% INCLUDE bug/field.html.tmpl
      no_tds = 1
      field  = bug_fields.resolution
      value  = bug.resolution
      editable = bug.check_can_change_field('resolution', bug.resolution, 1)
  %]
  </span>

  [%# CustIS Bug 129375 - status filter link after resolution field %]
  &nbsp;(<a href="/buglist.cgi?query_format=advanced&product=[% bug.product FILTER uri %]&bug_status=[% bug.bug_status_obj.name FILTER uri %]" target="_blank" id="search_link_bug_status" class="search-link">search</a>)

  [% IF bug.check_can_change_field('dup_id', 0, 1) %]
    <noscript><br> duplicate</noscript>
    <span id="duplicate_settings">of
      <span id="dup_id_container" class="bz_default_hidden">
        [% "${terms.bug} ${bug.dup_id}" FILTER bug_link(bug.dup_id) FILTER none %]
        (<a href="#" id="dup_id_edit_action">edit</a>)
      </span
      ><input id="dup_id" name="dup_id" size="6" value="[% bug.dup_id FILTER html %]" />
    </span>
    [% IF bug.dup_id %]
        <noscript>[% bug.dup_id FILTER bug_link(bug.dup_id) FILTER none %]</noscript>
    [% END %]
    <div id="dup_id_discoverable" class="bz_default_hidden">
      <a href="javascript:void(0)" id="dup_id_discoverable_action">Mark as Duplicate</a>
    </div>
  [% ELSIF bug.dup_id %]
    <noscript><br /> duplicate</noscript>
    <span id="duplicate_display">of
      [% "${terms.bug} ${bug.dup_id}" FILTER bug_link(bug.dup_id) FILTER none %]</span>
  [% END %]
</div>

<script type="text/javascript">
[%# FIXME Move close_status_array into "js resource data" %]
var close_status_array = [
  [% SET i = 0 %]
  [% FOREACH status = bug.statuses_available %]
    [% NEXT IF status.is_open %]
    [% ',' IF i; SET i = 1 %]'[% status.name FILTER js %]'
  [% END %]
];
removeClass('dup_id_discoverable', 'bz_default_hidden');
hideEditableField(
  "dup_id_container", "dup_id", 'dup_id_edit_action',
  'dup_id', '[% bug.dup_id | js %]'
);
function onchange_bug_status()
{
  showHideStatusItems('[% "is_duplicate" IF bug.dup_id %]', '[% bug.bug_status_obj.name | js %]');
  var s = document.getElementById('bug_status');
  [%# FIXME Remove hardcode bug_status==ASSIGNED => assign to self, bug_status==VERIFIED => qa to self %]
  if (s.value == "ASSIGNED" && document.changeform.assigned_to.value != "[% user.login %]")
  {
    document.changeform.assigned_to.value = "[% user.login %]";
    showEditableField("bz_assignee_edit_action", [ 'bz_assignee_edit_container', 'bz_assignee_input' ]);
  }
  else if (s.value == "VERIFIED" && document.changeform.qa_contact.value != "[% user.login %]")
  {
    document.changeform.qa_contact.value = "[% user.login %]";
    showEditableField("bz_qa_contact_edit_action", [ 'bz_qa_contact_edit_container', 'bz_qa_contact_input' ]);
  }
}
addListener('bug_status', 'change', onchange_bug_status);
addListener('resolution', 'change', showDuplicateItem);
addListener('dup_id_discoverable_action', 'click', function() {
  setResolutionToDuplicate('[% Param('duplicate_or_move_bug_status') | js %]');
});
addListener(window, 'load', function() {
  showHideStatusItems('[% "is_duplicate" IF bug.dup_id %]', '[% bug.bug_status_obj.name | js %]');
});
</script>
