[%# 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>
  #                 Ville Skyttä <ville.skytta@iki.fi>
  #                 Shane H. W. Travis <travis@sedsystems.ca>
  #                 Marc Schumann <wurblzap@gmail.com>
  #                 Akamai Technologies <bugzilla-dev@akamai.com>
  #                 Max Kanat-Alexander <mkanat@bugzilla.org>
  #                 Frédéric Buclin <LpSolit@gmail.com>
  #%]

[% PROCESS "global/field-descs.none.tmpl" %]

[% title = BLOCK %]Enter [% terms.Bug %]: [% product.name FILTER html %][% END %]

[% PROCESS global/header.html.tmpl
  title = title
  generate_api_token = 1
  style_urls = [ 'skins/standard/attachment.css',
                 'skins/standard/enter_bug.css',
                 'skins/standard/create_bug.css' ]
  javascript_urls = [ "js/attachment.js",
                      "js/field.js", "js/TUI.js", "js/bug.js",
                      "js/create_bug.js" ]
  onload = "init();"
%]

<script [% script_nonce FILTER none %]>
<!--

function init() {
  const $comment = document.querySelector('#comment');

  // Change the description edit state if the comment text is already entered. This could happen if the `comment` URL
  // param is passed, the user has cloned other b[%%]ug, or the page is loaded during session restore or from BFCache.
  if ($comment.value.match(/\S/)) {
    desc_edited = true;
  }

  set_assign_to();
  hideElementById('attachment_true');
  showElementById('attachment_false');
  showElementById('btn_no_attachment');
  init_take_handler('[% user.login FILTER js %]');
  bz_attachment_form.update_requirements(false);

  document.querySelector('#bug_type').addEventListener('change', () => {
    bug_type_specified = true;
  }, { once: true });

  $comment.addEventListener('input', () => {
    desc_edited = true;
  }, { once: true });
}

const params = new URLSearchParams(location.search);
let bug_type_specified = params.has('bug_type') || params.has('cloned_bug_id') || params.has('regressed_by');
let desc_edited = false;

var initialowners = new Array([% product.components.size %]);
var last_initialowner;
var default_bug_types = new Array([% product.components.size %]);
var desc_templates = new Array([% product.components.size %]);
var initialccs = new Array([% product.components.size %]);
var components = new Array([% product.components.size %]);
var comp_desc = new Array([% product.components.size %]);
var flags = new Array([% product.components.size %]);
[% IF Param("useqacontact") %]
    var initialqacontacts = new Array([% product.components.size %]);
    var last_initialqacontact;
[% END %]
[% count = 0 %]
[%- FOREACH comp = product.components %]
    [% NEXT IF NOT comp.is_active %]
    components[[% count %]] = "[% comp.name FILTER js %]";
    comp_desc[[% count %]] = "[% comp.description FILTER html_light FILTER js %]";
    initialowners[[% count %]] = "[% comp.default_assignee.login FILTER js %]";
    default_bug_types[[% count %]] = "[% comp.default_bug_type FILTER js %]";
    desc_templates[[% count %]] = "[% comp.bug_description_template.replace('\\r', '') FILTER js %]";
    [% flag_list = [] %]
    [% FOREACH f = comp.flag_types.bug %]
      [% flag_list.push(f.id) %]
    [% END %]
    [% FOREACH f = comp.flag_types.attachment %]
      [% flag_list.push(f.id) %]
    [% END %]
    flags[[% count %]] = [[% flag_list.join(",") FILTER js %]];
    [% IF Param("useqacontact") %]
        initialqacontacts[[% count %]] = "[% comp.default_qa_contact.login FILTER js %]";
    [% END %]

    [% SET initial_cc_list = [] %]
    [% FOREACH cc_user = comp.initial_cc %]
      [% initial_cc_list.push(cc_user.login) %]
    [% END %]
    initialccs[[% count %]] = "[% initial_cc_list.join(', ') FILTER js %]";

    [% count = count + 1 %]
[%- END %]

function set_assign_to() {
    // Based on the selected component, fill the "Assign To:" field
    // with the default component owner, and the "QA Contact:" field
    // with the default QA Contact. It also selectively enables flags.
    var form = document.Create;
    var assigned_to = form.assigned_to.value;

[% IF Param("useqacontact") %]
    var qa_contact = form.qa_contact.value;
[% END %]

    var index = -1;
    if (form.component.type == 'select-one') {
        index = form.component.selectedIndex;
    } else if (form.component.type == 'hidden') {
        // Assume there is only one component in the list
        index = 0;
    }
    if (index != -1) {
        var owner = initialowners[index];
        var component = components[index];
        if (assigned_to == last_initialowner
            || assigned_to == owner
            || assigned_to == '') {
            form.assigned_to.value = owner;
            last_initialowner = owner;
        }

        if (!bug_type_specified) {
          form.bug_type.value = default_bug_types[index];
        }

        // Fill the Description field with the product- or component-specific
        // template if defined. Skip if the Description is edited by the user.
        const desc_template = desc_templates[index];
        if ((!desc_edited && form.comment.value !== desc_template) || !form.comment.value) {
          form.comment.value = desc_template;
        }

        document.getElementById('initial_cc').innerHTML = initialccs[index];
        document.getElementById('comp_desc').innerHTML = comp_desc[index];

        if (initialccs[index]) {
          showElementById('initial_cc_label');
          showElementById('initial_cc');
        } else {
          hideElementById('initial_cc_label');
          hideElementById('initial_cc');
        }

        [% IF Param("useqacontact") %]
            var contact = initialqacontacts[index];
            if (qa_contact == last_initialqacontact
                || qa_contact == contact
                || qa_contact == '') {
                  form.qa_contact.value = contact;
                  last_initialqacontact = contact;
            }
        [% END %]

        // We show or hide the available flags depending on the selected component.
        var flag_rows = YAHOO.util.Dom.getElementsByClassName('bz_flag_type', 'tbody');
        for (var i = 0; i < flag_rows.length; i++) {
            // Each flag table row should have one flag form select element
            // We get the flag type id from the id attribute of the select.
            var flag_select = YAHOO.util.Dom.getElementsByClassName('flag_select',
                                                                    'select',
                                                                    flag_rows[i])[0];
            var type_id = flag_select.id.split('-')[1];
            var can_set = flag_select.options.length > 1 ? 1 : 0;
            var show = 0;
            // Loop through the allowed flag ids for the selected component
            // and if we match, then show the row, otherwise hide the row.
            for (var j = 0; j < flags[index].length; j++) {
                if (flags[index][j] == type_id) {
                    show = 1;
                    break;
                }
            }
            if (show && can_set) {
                flag_select.disabled = false;
                YAHOO.util.Dom.removeClass(flag_rows[i], 'bz_default_hidden');
            } else {
                flag_select.disabled = true;
                YAHOO.util.Dom.addClass(flag_rows[i], 'bz_default_hidden');
            }
        }
    }
}

var status_comment_required = new Array();
[% FOREACH status = bug_status %]
  status_comment_required['[% status.name FILTER js %]'] =
    [% status.comment_required_on_change_from() ? 'true' : 'false' %]
[% END %]

TUI_alternates['expert_fields'] = 'Show Advanced Fields';
// Hide the Advanced Fields by default, unless the user has a cookie
// that specifies otherwise.
TUI_hide_default('expert_fields');
-->
</script>

<form name="Create" id="Create" method="post" action="[% basepath FILTER none %]post_bug.cgi"
      class="enter_bug_form" enctype="multipart/form-data"
      onsubmit="return validateEnterBug(this)">
<input type="hidden" name="filed_via" value="standard_form">
<input type="hidden" name="product" value="[% product.name FILTER html %]">
<input type="hidden" name="token" value="[% token FILTER html %]">
<input type="hidden" name="bug_ignored" value="[% bug_ignored ? "1" : "0" %]">

<table role="none">
<tbody>
  <tr>
    <td colspan="4">
    [%# Migration note: The following file corresponds to the old Param
      # 'entryheaderhtml'
      #%]
    [% PROCESS 'bug/create/user-message.html.tmpl' %]
    </td>
  </tr>

  <tr>
    <td colspan="2">
      <input type="button" id="expert_fields_controller"
             value="Hide Advanced Fields" onClick="toggleAdvancedFields()">
      [%# Show the link if the browser supports JS %]
      <script [% script_nonce FILTER none %]>
        YAHOO.util.Dom.removeClass('expert_fields_controller',
                                   'bz_default_hidden');
      </script>
    </td>
    <td colspan="2">&nbsp;</td>
  </tr>

  <tr>
    [% INCLUDE bug/field.html.tmpl
      bug = default, field = bug_fields.product, editable = 0,
      value = product.name %]
    <td colspan="2" id="required_marker">
      (<span class="required_star">*</span> =
      <span class="required_explanation">Required Field</span>)
    </td>
  </tr>

  [%# We can't use the select block in these two cases for various reasons. %]
  <tr>
    [% component_desc_url = BLOCK -%]
      [% basepath FILTER none %]describecomponents.cgi?product=[% product.name FILTER uri %]
    [% END %]
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.component editable = 1
      desc_url = component_desc_url
    %]
    <td id="field_container_component">
      <select name="component" id="component" onchange="set_assign_to();"
              aria-description="[% help_html.component FILTER txt FILTER collapse FILTER html %]"
              size="7" aria-required="true" class="required">
        [%# Build the lists of assignees and QA contacts if "usemenuforusers" is enabled. %]
        [% IF Param("usemenuforusers") %]
          [% assignees_list = user.get_userlist.clone %]
          [% qa_contacts_list = user.get_userlist.clone %]
        [% END %]

        [%- FOREACH comp = product.components %]
          [% NEXT IF NOT comp.is_active %]
          <option value="[% comp.name FILTER html %]"
                  id="v[% comp.id FILTER html %]_component"
            [% IF comp.name == default.component_ %]
              [%# This is for bug/field.html.tmpl, for visibility-related
                # controls. %]
              [% default.component_id = comp.id %]
              selected="selected"
            [% END %]>
            [% comp.name FILTER html -%]
          </option>
          [% IF Param("usemenuforusers") %]
            [% INCLUDE build_userlist default_user = comp.default_assignee,
                                      userlist = assignees_list %]
            [% INCLUDE build_userlist default_user = comp.default_qa_contact,
                                      userlist = qa_contacts_list %]
          [% END %]
        [%- END %]
      </select>

      <script [% script_nonce FILTER none %]>
       <!--
         [%+ INCLUDE "bug/field-events.js.tmpl"
                     field = bug_fields.component, product = product %]
       //-->
       </script>
    </td>

    <td colspan="2" id="comp_desc_container">
      [%# Enclose the fieldset in a nested table so that its width changes based
        # on the length on the component description. %]
      <table role="none">
        <tr>
          <td>
            <fieldset>
              <legend>Component Description</legend>
              <div id="comp_desc" class="comment">Select a component to read its description.</div>
            </fieldset>
          </td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.version editable = 1 rowspan = 3
    %]
    <td rowspan="3">
      <select name="version" id="version" size="5"
          aria-description="[% help_html.version FILTER txt FILTER collapse FILTER html %]">
        [%- FOREACH v = version %]
          [% NEXT IF NOT v.is_active %]
          <option value="[% v.name FILTER html %]"
            [% ' selected="selected"' IF v.name == default.version %]>[% v.name FILTER html -%]
          </option>
        [%- END %]
      </select>
    </td>

    [% INCLUDE bug/field.html.tmpl
      bug = default, field = bug_fields.bug_type, editable = 1, use_buttons = 1,
      value = default.bug_type, required = Param('require_bug_type') %]
  </tr>

  [% needs_extra_tr = 1 %]
  <tr>
    <th>
      Platform:
    </th>
    <td>
      <div>
        <span title="Hardware">
          [% INCLUDE bug/field.html.tmpl
            no_tds = 1, bug = default, field = bug_fields.rep_platform, editable = 1,
            value = default.rep_platform, aria_label = field_descs.rep_platform %]
        </span>
        <span title="Operating System">
          [% INCLUDE bug/field.html.tmpl
            no_tds = 1, bug = default, field = bug_fields.op_sys, editable = 1,
            value = default.op_sys, aria_label = field_descs.op_sys %]
        </span>
      </div>
      [% IF !cloned_bug_id %]
        <div class="comment">
          Update the <i>platform</i> field if this [% terms.bug %] is applicable to specific platforms.<br>
          <span id="rep_hw_os">
            (<a href="javascript:void(0)" role="button" aria-controls="rep_platform op_sys"
                onclick="$('#rep_platform').val('[% rep_platform FILTER js FILTER html %]');
                         $('#op_sys').val('[% rep_op_sys FILTER js FILTER html %]')">use my platform</a>)
            (<a href="javascript:void(0)" role="button" aria-controls="rep_platform op_sys"
                onclick="$('#rep_platform').val('All');
                         $('#op_sys').val('All')">applies to all platforms</a>)
          </span>
        </div>
        [% needs_extra_tr = 0 %]
      [% END %]
    </td>
  </tr>

  [% IF needs_extra_tr %]
    <tr>
      <td>&nbsp;</td>
    </tr>
  [% END %]
</tbody>

<tbody class="expert_fields">
  <tr>
    [% IF Param('usetargetmilestone') && Param('letsubmitterchoosemilestone') %]
      [% INCLUDE select field = bug_fields.target_milestone %]
    [% ELSE %]
      <td colspan="2">&nbsp;</td>
    [% END %]

    [% IF Param('letsubmitterchoosepriority') %]
      [% INCLUDE bug/field.html.tmpl
        bug = default, field = bug_fields.priority, editable = 1,
        value = default.priority %]
    [% ELSE %]
      <td colspan="2">&nbsp;</td>
    [% END %]
  </tr>

  <tr>
    [% INCLUDE bug/field.html.tmpl
      bug = default, field = bug_fields.bug_status,
      editable = (bug_status.size > 1), value = default.bug_status
      override_legal_values = bug_status %]
    [% INCLUDE bug/field.html.tmpl
      bug = default, field = bug_fields.bug_severity, editable = 1,
      value = default.bug_severity %]
  </tr>

  <tr>
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.assigned_to editable = 1
    %]
    <td>
      [% assigned_to_desc = help_html.assigned_to FILTER txt FILTER collapse %]
      [% INCLUDE global/userselect.html.tmpl
         id       => "assigned_to"
         name     => "assigned_to"
         value    => assigned_to
         disabled => assigned_to_disabled
         size     => 30
         emptyok  => 1
         custom_userlist => assignees_list
         aria_description => assigned_to_desc
      %]
      [% UNLESS assigned_to_disabled %]
        <span id="take_bug">
          <button title="Assign to yourself"
                  type="button" class="minor" aria-controls="assigned_to"
                  onclick="return take_bug('[% user.login FILTER js %]')">Take</button>
        </span>
      [% END %]
      <noscript>(Leave blank to assign to component's default assignee)</noscript>
    </td>

[% IF Param("useqacontact") %]
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.qa_contact editable = 1
    %]
    <td>
    [% qa_contact_desc = help_html.qa_contact FILTER txt FILTER collapse %]
    [% INCLUDE global/userselect.html.tmpl
       id       => "qa_contact"
       name     => "qa_contact"
       value    => qa_contact
       disabled => qa_contact_disabled
       size     => 30
       emptyok  => 1
       custom_userlist => qa_contacts_list
       aria_description => qa_contact_desc
     %]
      <noscript>(Leave blank to assign to default qa contact)</noscript>
    </td>
  </tr>
[% END %]

  <tr>
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.cc editable = 1
    %]
    <td>
      [% cc_desc = help_html.cc FILTER txt FILTER collapse %]
      [% INCLUDE global/userselect.html.tmpl
         id       => "cc"
         name     => "cc"
         value    => cc
         disabled => cc_disabled
         size     => 30
         multiple => 5
         aria_description => cc_desc
       %]
     </td>
     <th>
      <span id="initial_cc_label" class="bz_default_hidden">
        Default [% field_descs.cc FILTER html %]:
      </span>
    </th>
    <td>
      <span id="initial_cc"></span>
    </td>
  </tr>

  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>

[% IF Param("usebugaliases") %]
  <tr>
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.alias editable = 1
    %]
    <td colspan="2">
      <input id="alias" name="alias" size="30" maxlength="40" value="[% alias FILTER html %]"
             aria-description="[% help_html.alias FILTER txt FILTER collapse FILTER html %]">
    </td>
  </tr>
[% END %]
</tbody>

<tbody>
  <tr>
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.short_desc editable = 1
    %]
    <td colspan="3" class="field_value">
      <input name="short_desc" size="70" value="[% short_desc FILTER html %]"
             maxlength="255" spellcheck="true" aria-required="true"
             aria-description="[% help_html.short_desc FILTER txt FILTER collapse FILTER html %]"
             class="required text_input" id="short_desc">
    </td>
  </tr>

  [% IF feature_enabled('jsonrpc') AND !cloned_bug_id
        AND user.settings.possible_duplicates.value == 'on' %]
    <tr id="possible_duplicates_container" class="bz_default_hidden">
      <th>Possible<br>Duplicates:</th>
      <td colspan="3">
        <div id="possible_duplicates"></div>
        <script [% script_nonce FILTER none %]>
          var dt_columns = [
              { key: "id", label: "[% field_descs.bug_id FILTER js %]",
                formatter: YAHOO.bugzilla.dupTable.formatBugLink },
              { key: "summary",
                label: "[% field_descs.short_desc FILTER js %]",
                formatter: "text" },
              { key: "status",
                label: "[% field_descs.bug_status FILTER js %]",
                formatter: YAHOO.bugzilla.dupTable.formatStatus },
              { key: "update_token", label: '',
                formatter: YAHOO.bugzilla.dupTable.formatCcButton }
          ];
          YAHOO.bugzilla.dupTable.addCcMessage = "Add Me to the CC List";
          YAHOO.bugzilla.dupTable.init({
            container: 'possible_duplicates',
            columns: dt_columns,
            product_name: '[% product.name FILTER js %]',
            summary_field: 'short_desc',
            options: {
              MSG_LOADING: 'Searching for possible duplicates...',
              MSG_EMPTY:   'No possible duplicates found.',
              SUMMARY:     'Possible Duplicates'
            }
          });
        </script>
      </td>
    </tr>
  [% END %]

  <tr>
    <th><label for="comment">Description</label>:</th>
    <td colspan="3">

      [% defaultcontent = BLOCK %]
        [% IF cloned_bug_id %]
+++ This [% terms.bug %] was initially created as a clone of [% terms.Bug %] #[% cloned_bug_id %] +++


        [% END %]
        [%-# We are within a BLOCK. The comment will be correctly HTML-escaped
          # by global/textarea.html.tmpl. So we must not escape the comment here. %]
        [% comment FILTER none %]
      [%- END %]
      [% INCLUDE bug/comment.html.tmpl
         minrows        = 5
         maxrows        = 15
         cols           = constants.COMMENT_COLS
         defaultcontent = defaultcontent
       %]
      <br>
    </td>
  </tr>

<tbody class="expert_fields">
  <tr>
    [% INCLUDE "bug/field-label.html.tmpl"
      field = bug_fields.bug_file_loc editable = 1
    %]
    <td colspan="3" class="field_value">
      <input name="bug_file_loc" id="bug_file_loc" class="text_input"
             aria-description="[% help_html.bug_file_loc FILTER txt FILTER collapse FILTER html %]"
             size="40" value="[% bug_file_loc FILTER html %]" placeholder="https://">
    </td>
  </tr>
</tbody>

  <tr>
    <th>Attachment:</th>
    <td colspan="3">
      <div id="attachment_false" class="bz_default_hidden">
        <input type="button" value="Add an attachment" onClick="handleWantsAttachment(true)">
      </div>

      <div id="attachment_true">
        <input type="button" id="btn_no_attachment" value="Don't add an attachment"
               class="bz_default_hidden"  onClick="handleWantsAttachment(false)">
        <fieldset>
          <legend>Add an attachment</legend>
          <table role="none" class="attachment_entry">
            [% PROCESS attachment/createformcontents.html.tmpl
                       flag_types = product.flag_types.attachment
                       any_flags_requesteeble = 1
                       flag_table_id ="attachment_flags" %]
          </table>

          [% IF user.is_insider %]
            <input type="checkbox" id="comment_is_private" name="comment_is_private"
                   [% ' checked="checked"' IF comment_is_private %]
                   onClick="updateCommentTagControl(this, 'comment')">
            <label for="comment_is_private">
              Make this attachment and [% terms.bug %] description private (visible only
              to members of the <strong>[% Param('insidergroup') FILTER html %]</strong> group)
            </label>
          [% END %]
        </fieldset>
      </div>
    </td>
  </tr>
</tbody>

<tbody class="expert_fields">
  [% IF user.in_group('editbugs', product.id) %]
    <tr>
      [% INCLUDE "bug/field-label.html.tmpl"
        field = bug_fields.dependson editable = 1
      %]
      <td>
        <input id="dependson" name="dependson" accesskey="d" value="[% dependson FILTER html %]" size="30"
               aria-description="[% help_html.dependson FILTER txt FILTER collapse FILTER html %]">
      </td>
      [% INCLUDE "bug/field-label.html.tmpl"
        field = bug_fields.blocked editable = 1
      %]
      <td>
        <input id="blocked" name="blocked" accesskey="b" value="[% blocked FILTER html %]" size="30"
               aria-description="[% help_html.blocked FILTER txt FILTER collapse FILTER html %]">
      </td>
    </tr>

    [% IF Param('use_regression_fields') %]
      <tr>
        [% INCLUDE "bug/field-label.html.tmpl"
          field = bug_fields.regressed_by
          editable = 1
        %]
        <td>
          <input id="regressed_by" name="regressed_by" value="[% regressed_by FILTER html %]" size="30"
                 aria-description="[% help_html.regressed_by FILTER txt FILTER collapse FILTER html %]">
        </td>
        <td colspan="2">
          [%~# Regressions field is hidden from new bugs ~%]
        </td>
      </tr>
    [% END %]

    [% IF use_keywords %]
      <tr>
        [% INCLUDE bug/field.html.tmpl
           bug = default, field = bug_fields.keywords, editable = 1,
           value = keywords, desc_url = basepath _ "describekeywords.cgi",
           value_span = 3
        %]
      </tr>
    [% END %]

    <tr>
      <th><label for="status_whiteboard">Whiteboard</label>:</th>
      <td colspan="3" class="field_value">
        <input id="status_whiteboard" name="status_whiteboard" size="70"
               value="[% status_whiteboard FILTER html %]" class="text_input">
      </td>
    </tr>
  [% END %]

  [% IF user.is_timetracker %]
    <tr>
      [% INCLUDE "bug/field-label.html.tmpl"
        field = bug_fields.estimated_time editable = 1
      %]
      <td>
        <input name="estimated_time" size="6" maxlength="6" value="[% estimated_time FILTER html %]">
      </td>
      [% INCLUDE bug/field.html.tmpl
        bug = default, field = bug_fields.deadline, value = deadline, editable = 1
      %]
    </tr>
  [% END %]

  [% IF Param('use_see_also') %]
    <tr>
      [% INCLUDE bug/field.html.tmpl
         bug        = default
         field      = bug_fields.see_also
         editable   = 1
         value      = see_also
         value_span = 3
      %]
    </tr>
  [% END %]
</tbody>

<tbody>
[%# non-tracking flags custom fields %]
[% FOREACH field = Bugzilla.active_custom_fields(product=>product) %]
  [% NEXT IF field.type == constants.FIELD_TYPE_EXTENSION %]
  [% NEXT UNLESS field.enter_bug %]
  [% Hook.process('custom_field', 'bug/create/create.html.tmpl') %]
  [% NEXT IF field.hidden %]
  [% SET value = ${field.name}.defined ? ${field.name} : "" %]
  <tr [% 'class="expert_fields"' IF !field.is_mandatory %]>
    [% INCLUDE bug/field.html.tmpl
      bug = default, field = field, value = value, editable = 1,
      value_span = 3 %]
  </tr>
[% END %]
[% Hook.process('after_custom_fields') %]
</tbody>

[% display_flags = 0 %]
[% any_flags_requesteeble = 0 %]
[% FOREACH flag_type = product.flag_types.bug %]
  [% display_flags = 1 %]
  [% IF flag_type.is_requestable && flag_type.is_requesteeble %]
    [% SET any_flags_requesteeble = 1 %]
  [% END %]
  [% LAST IF display_flags && any_flags_requesteeable %]
[% END %]

[% IF tracking_flags.size || display_flags %]
  <tbody class="expert_fields">
    <tr>
      <th>Flags:</th>
      <td colspan="3">
        <div id="bug_flags_false" class="bz_default_hidden">
          <input type="button" value="Set [% terms.bug FILTER html %] flags" onClick="handleWantsBugFlags(true)">
        </div>

        <div id="bug_flags_true">
          <input type="button" id="btn_no_bug_flags" value="Don't set [% terms.bug %] flags"
                 class="bz_default_hidden"  onClick="handleWantsBugFlags(false)">

          <fieldset>
            <legend>Set [% terms.bug %] flags</legend>
            <table>
              <tr>
                [% Hook.process('bug_flags') %]
                [% IF display_flags %]
                  <td>
                    [% PROCESS "flag/list.html.tmpl" flag_types = product.flag_types.bug
                                                     any_flags_requesteeble = any_flags_requesteeble
                                                     flag_table_id = "bug_flags"
                    %]
                  </td>
                [% END %]
              </tr>
            </table>
          </fieldset>
        </div>
      </td>
    </tr>
  </tbody>
[% END %]

<tbody class="expert_fields">
  [%# BMO - exclude the default security from from the groups_available %]
  [%# list, as it will be added by the BMO extension %]
  [% groups_available = [] %]
  [% FOREACH group = product.groups_available %]
    [% NEXT IF group.name == product.default_security_group %]
    [% groups_available.push(group) %]
  [% END %]
  [% IF groups_available.size %]
  <tr>
    <th>&nbsp;</th>
    <td colspan="3">
        <strong>
          Only users in all of the selected groups can view this
          [%+ terms.bug %]:
        </strong>
      <br>
      <font size="-1">
        (Leave all boxes unchecked to make this a public [% terms.bug %].)
      </font>
      <br>

      <!-- Checkboxes -->
      <input type="hidden" name="defined_groups" value="1">
      [% FOREACH group = groups_available %]
        <input type="checkbox" id="group_[% group.id FILTER html %]"
               name="groups" value="[% group.name FILTER html %]"
               [% ' checked="checked"' IF default.groups.contains(group.name)
                                          OR group.is_default %]>
        <label for="group_[% group.id FILTER html %]">
          [%- group.description FILTER html_light %]</label><br>
      [% END %]
    </td>
  </tr>
  [% END %]
</tbody>

<tbody>
  [%# Form controls for entering additional data about the bug being created. %]
  [% Hook.process("form") %]

  <tr>
    <th>&nbsp;</th>
    <td colspan="3">
      <input type="submit" id="commit" value="Submit [% terms.Bug %]">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" name="maketemplate" id="maketemplate" class="secondary"
             value="Remember values as bookmarkable template"
             onclick="bz_no_validate_enter_bug=true" class="expert_fields">
    </td>
  </tr>
</tbody>
  [%# "whiteboard" and "qa contact" are the longest labels
    # add them here to avoid shifting the page when toggling advanced fields %]
  <tr>
    <th class="hidden_text">Whiteboard:</th>
    <td>&nbsp;</td>
    <th class="hidden_text">QA Contact:</th>
  </tr>
  </table>
  <input type="hidden" name="form_name" value="enter_bug">
</form>

[%# Links or content with more information about the bug being created. %]
[% Hook.process("end") %]

<div id="guided">
  <a id="guided_img" href="[% basepath FILTER none %]enter_bug.cgi?format=guided&amp;product=[% product.name FILTER uri %]">
    <img src="[% basepath FILTER none %]extensions/BMO/web/images/guided.png" width="16" height="16" alt="">
    Switch to the [% terms.Bugzilla %] Helper
  </a>
  | <a href="[% basepath FILTER none %]page.cgi?id=custom_forms.html">Custom [% terms.bug %] entry forms</a>
</div>

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

[%############################################################################%]
[%# Block for SELECT fields                                                  #%]
[%############################################################################%]

[% BLOCK select %]

  [% INCLUDE "bug/field-label.html.tmpl"
    field = field editable = 1
  %]
  <td>
    <select name="[% field.name FILTER html %]" id="[% field.name FILTER html %]"
            aria-description="[% help_html.${field.name} FILTER txt FILTER collapse FILTER html %]">
    [%- FOREACH x = ${field.name} %]
      [% NEXT IF NOT x.is_active %]
      <option value="[% x.name FILTER html %]"
        [% " selected=\"selected\"" IF x.name == default.${field.name} %]>
        [% display_value(field.name, x.name) FILTER html %]
      </option>
    [% END %]
    </select>
  </td>
[% END %]

[% BLOCK build_userlist %]
  [% user_found = 0 %]
  [% default_login = default_user.login %]
  [% RETURN UNLESS default_login %]

  [% FOREACH user = userlist %]
    [% IF user.login == default_login %]
      [% user_found = 1 %]
      [% LAST %]
    [% END %]
  [% END %]

  [% userlist.push({login    => default_login,
                    identity => default_user.identity,
                    visible  => 1})
     UNLESS user_found %]
[% END %]
