[%# 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): Myk Melez <myk@mozilla.org>
  #                 Joel Peshkin <bugreport@peshkin.net>
  #                 Erik Stambaugh <erik@dasbistro.com>
  #                 Marc Schumann <wurblzap@gmail.com>
  #%]

[%# Define strings that will serve as the title and header of this page %]
[% title = BLOCK %]Create New Attachment for [% terms.Bug %] #[% bug.bug_id %][% END %]
[% header = BLOCK %]Create New Attachment for
  [%+ "$terms.Bug $bug.bug_id" FILTER bug_link(bug) FILTER none %][% END %]
[% subheader = BLOCK %][% bug.short_desc FILTER html %][% END %]

[% PROCESS global/header.html.tmpl
  title = title
  header = header
  subheader = subheader
  style_urls = [ 'skins/standard/create_attachment.css' ]
  javascript_urls = [ "js/attachment.js", "js/field.js" ]
  doc_section = "attachments.html"
%]

<form name="entryform" method="post" action="attachment.cgi"
      enctype="multipart/form-data"
      onkeypress="return ctrlEnter(event||window.event,this)"
      onsubmit="return validateAttachmentForm(this)">
  <input type="hidden" name="bugid" value="[% bug.bug_id %]" />
  <input type="hidden" name="action" value="insert" />
  <input type="hidden" name="token" value="[% token FILTER html %]" />

  <table class="attachment_entry">
    [% PROCESS attachment/createformcontents.html.tmpl %]

    [%# Additional fields for attachments on existing bugs: %]
    <tr>
      <th>Obsoletes:</th>
      <td>
        <em>(optional) Check each existing attachment made obsolete by your new attachment.</em><br />
        [% IF attachments.size %]
          [% FOREACH attachment = attachments %]
            [% IF ((attachment.isprivate == 0) || user.is_insider) %]
              <input type="checkbox" id="[% attachment.id %]"
                   name="obsolete" value="[% attachment.id %]" />
              <a href="attachment.cgi?id=[% attachment.id %]&amp;action=edit">[% attachment.id %]: [% attachment.description FILTER html %]</a><br />
            [% END %]
          [% END %]
        [% ELSE %]
            [no attachments can be made obsolete]
        [% END %]
      </td>
    </tr>

    [% IF user.id != bug.assigned_to.id %]
    <tr>
      <th>Reassignment:</th>
      <td>
        <em>If you want to assign this [% terms.bug %] to yourself,
            check the box below.</em><br />
        <input type="checkbox" id="takebug" name="takebug" value="1" />
        <label for="takebug">take [% terms.bug %]</label>
      </td>
    </tr>
    [% END %]

    [% bug_statuses = bug.statuses_available %]
    [% IF bug_statuses.size %]
    <tr>
      <th><label for="bug_status">Change bug status to:</label></th>
      <td>
        <select id="bug_status" name="bug_status">
          <option value="[% bug.status.name FILTER html %]">[% bug.status.name FILTER html %] (current)</option>
          [% FOREACH bug_status = bug_statuses %]
            [% NEXT IF bug_status.id == bug.status.id %]
            <option value="[% bug_status.name FILTER html %]">[% bug_status.name FILTER html %]</option>
          [% END %]
        </select>
        [% 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">
        [% PROCESS bug/field.html.tmpl
            no_tds = 1
            field  = Bugzilla.get_field('resolution')
            value  = bug.resolution
            editable = bug.check_can_change_field('resolution', bug.resolution, 1)
        %]
        </span>
        <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 %]
        ];
        function onchange_bug_status()
        {
          showHideStatusItems('[% "is_duplicate" IF bug.dup_id %]', '[% bug.bug_status_obj.name | js %]');
        }
        addListener('bug_status', 'change', onchange_bug_status);
        addListener('resolution', 'change', showDuplicateItem);
        addListener(window, 'load', onchange_bug_status);
        //-->
        </script>

        [% 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 %]
        [% 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 %]
      </td>
    </tr>
    [% END %]

    <tr>
      <th><label for="work_time">Hours Worked:</label></th>
      <td><input type="text" size="10" value="[% work_time || '0.0' %]" name="work_time" id="work_time" /></td>
    </tr>
    <tr>
      <th><label for="comment">Comment:</label></th>
      <td>
        <em>(optional) Add a comment about this attachment to the [% terms.bug %].</em>
        [% IF Param('allow_commentsilent') %]
          <input type="checkbox" id="commentsilent" name="commentsilent" value="1" /> <label for="commentsilent">Silent</label>
        [% END %]
        <br />
        [% INCLUDE global/textarea.html.tmpl
          name    = 'comment'
          id      = 'comment_textarea'
          minrows = 6
          maxrows = 15
          cols    = constants.COMMENT_COLS
          wrap    = 'soft'
          style   = 'width: 100%'
          defaultcontent = commenttext
        %]
        [% PROCESS "bug/comment-preview-div.html.tmpl" %]
      </td>
    </tr>
    [% IF user.is_insider %]
      <tr>
        <th>Privacy:</th>
        <td>
          <input type="checkbox" name="isprivate" id="isprivate"
            value="1" onclick="updateCommentPrivacy(this)" />
          <label for="isprivate">
            Make attachment and comment private (visible only to members of
            the <strong>[% Param('insidergroup') FILTER html %]</strong>
            group)
          </label>
        </td>
      </tr>
    [% END %]
    <tr>
      <th>&nbsp;</th>
      <td>
        <input type="submit" id="commit" value="Submit" />
        <input type="button" value="Preview comment" onclick="showcommentpreview()" tabindex="-1" />
      </td>
    </tr>
  </table>

</form>

[% Hook.process('end') %]

[% PROCESS global/footer.html.tmpl %]
