[%# 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.
  #
  # Contributor(s): Frédéric Buclin <LpSolit@gmail.com>
  #%]

[%# INTERFACE:
  # field: Bugzila::Field; the current field being edited
  #%]

[% title = BLOCK %]
  Edit the [% "Custom" IF field.custom %] field '[% field.name FILTER html %]' ([% field.description FILTER html %])
[% END %]

[% javascript = BLOCK %]
  [% INCLUDE "admin/custom_fields/cf-js.js.tmpl" %]
[% END %]

[% PROCESS global/header.html.tmpl
           title = title
           onload = field.custom ? "toggleCheckbox(document.getElementById('enter_bug'), 'new_bugmail');" : ""
           doc_section = "custom-fields.html#edit-custom-fields"
%]

<p>
  Descriptions are a very short string describing the field and will be used as
  the label for this field in the user interface.
</p>

<form id="edit_field" action="editfields.cgi" method="GET">
  <table border="0" cellspacing="0" cellpadding="5">
    <tr>
      <th align="right">Name:</th>
      <td>[% field.name FILTER html %]</td>

      [% IF field.custom %]
      <th align="right">
        <label for="enter_bug">Can be set on [% terms.bug %] creation:</label>
      </th>
      <td><input type="checkbox" id="enter_bug" name="enter_bug" value="1"
                 [%- " checked" IF field.enter_bug %]
                 onchange="toggleCheckbox(this, 'new_bugmail');" /></td>
      [% END %]
    </tr>
    [% IF field.custom %]
    <tr>
      <td colspan="2"></td>
      <th align="right">
        <label for="clone_bug">Is copied into the cloned [% terms.bug %]:</label>
      </th>
      <td><input type="checkbox" id="clone_bug" name="clone_bug" value="1"
                 [%- " checked" IF field.clone_bug %] /></td>
    </tr>
    [% END %]
    <tr>
      <th align="right"><label for="desc">Description:</label></th>
      <td><input type="text" id="desc" name="desc" size="40"
                 value="[% field.description FILTER html %]"></td>

      <th align="right">
        <label for="new_bugmail">Displayed in [% terms.bug %]mail for new [% terms.bugs %]:</label>
      </th>
      <td><input type="checkbox" id="new_bugmail" name="new_bugmail" value="1"
                 [%- " checked" IF field.mailhead %]></td>
    </tr>
    <tr>
      <th align="right">Type:</th>
      <td>[% field_types.${field.type} FILTER html %]</td>

      <th align="right"><label for="obsolete">Is obsolete:</label></th>
      <td><input type="checkbox" id="obsolete" name="obsolete" value="1"
                 [%- " checked" IF field.obsolete %]></td>
    </tr>
    <tr valign="top">
      <th align="right"><label for="sortkey">Sortkey:</label></th>
      <td>
        <input type="text" id="sortkey" name="sortkey" size="6" maxlength="6"
               value="[% field.sortkey FILTER html %]">
      </td>

      [% IF field.custom %]
      <th align="right">
        <label for="visibility_field_id">Field only appears when:</label>
      </th>
      <td valign="top">
        <select name="visibility_field_id" id="visibility_field_id"
                onchange="onChangeVisibilityField()">
          <option></option>
          [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
            [%# FIXME now, fields with non-unique value name is not allowed %]
            [% NEXT IF sel_field.id == field.id || sel_field.name == "component" ||
                sel_field.name == "version" || sel_field.name == "target_milestone" %]
            <option value="[% sel_field.id FILTER html %]"
             [% ' selected="selected"' 
                IF sel_field.id == field.visibility_field.id %]>
              [% sel_field.description FILTER html %]
              ([% sel_field.name FILTER html %])
            </option>
          [% END %]
        </select>
        <label for="visibility_value_id"><strong>&nbsp;is set to one of:</strong></label>
      </td>
      <td rowspan="2">
        <select style="min-width: 100px" id="visibility_value_id"
          name="visibility_value_id" size="7" multiple="multiple">
          [% FOREACH value = field.visibility_field.legal_values %]
          <option value="[% value.id FILTER html %]"[% ' selected="selected"' IF field.has_visibility_value(value.id) %]>
              [% value.name FILTER html %]
            </option>
          [% END %]
        </select>
      </td>
      [% END %]
    </tr>
    [% IF field.is_select AND field.name != 'product' %]
    <tr>
      <th>&nbsp;</th>
      <td>
        <a href="editvalues.cgi?field=[% field.name FILTER url_quote %]">Edit
          legal values for this field</a>.
      </td>

    [% IF field.custom %]
      <th>
        <label for="value_field_id">
          Field that controls the values<br>
          that appear in this field:
        </label>
      </th>

      <td>
        <select name="value_field_id" id="value_field_id">
          <option></option>
          [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
            [% NEXT IF sel_field.id == field.id %]
            <option value="[% sel_field.id FILTER html %]"
             [% ' selected="selected"' 
                IF sel_field.id == field.value_field.id %]>
              [% sel_field.description FILTER html %]
              ([% sel_field.name FILTER html %])
            </option>
          [% END %]
        </select>
      </td>
    [% END %]
    </tr>
    [% END %]

    [% IF field.type == constants.FIELD_TYPE_BUG_ID %]
    <tr>
      <th><label for="add_to_deps">Add to dependency tree:</label></th>
      <td valign="top">
        <select name="add_to_deps" id="add_to_deps">
          <option value="no" [% ' selected="selected"' IF !field.add_to_deps %]>Do not add</option>
          <option value="blocked" [% ' selected="selected"' IF field.add_to_deps == constants.BUG_ID_ADD_TO_BLOCKED %]>Add to blocked</option>
          <option value="dependson" [% ' selected="selected"' IF field.add_to_deps == constants.BUG_ID_ADD_TO_DEPENDSON %]>Add to blockers</option>
        </select>
      </td>
    </tr>
    [% END %]

    [% IF field.type == constants.FIELD_TYPE_EXTURL %]
    <tr valign="top">
      <th>
        <label for="url" id="url_title">
          URL template:<br />($1 = target ID)
        </label>
      </th>
      <td>
        <input id="url_field" name="url" type="text" size="40" value="[% field.url | html %]" />
      </td>
    </tr>
    [% END %]
  </table>
  <input type="hidden" name="action" value="update">
  <input type="hidden" name="name" value="[% field.name FILTER html %]">
  <input type="hidden" name="token" value="[% token FILTER html %]">
  <input type="submit" id="edit" value="Submit">
</form>

[% IF field.obsolete AND field.custom %]
<p>
  <a href="editfields.cgi?action=del&amp;name=[% field.name FILTER html %]">Remove
    this custom field from the database.</a><br>
  This action will only be successful if the custom field has never been used
  in [% terms.abug %].<br>
</p>
[% END %]

<p>
  <a href="editfields.cgi">Back to the list of existing fields</a>
</p>

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