# extends 'admin.html'
<!DOCTYPE html>
<html>
  <head>
    <title>
      # block admintitle
      ${dgettext(domain, "Manage Custom Fields")}
      # endblock
    </title>
    # block head
    ${ super() }
    # endblock head
  </head>

  <body>
    # block adminpanel
    <h2>${dgettext(domain, "Manage Custom Fields")}</h2>

    <!--! Detail view -->
    # if cf_display=='detail':
    <form class="mod" id="addcf" method="POST">
      ${jmacros.form_token_input()}
      <fieldset>
        <legend>${dgettext(domain, "Modify Custom Field:")}</legend>
        <div class="field">
          <label>${dgettext(domain, "Name (cannot modify):")} <strong>${cfield.name}</strong></label>
        </div>
        <input name="name" value="${cfield.name}" type="hidden" />
        <input name="order" value="${cfield.order}" type="hidden" />
        <div class="field">
          <label>${dgettext(domain, "Type:")}<br />
            <select name="type" id="type">
              # for value in field_types:
              <option
                  value="${value}" ${{'selected': cfield.type==value and 'selected'}|htmlattr}>
                ${value.capitalize()}</option>
              # endfor
            </select>
          </label>
        </div>
        <div class="field">
          <label>${dgettext(domain, "Label:")}<br />
            <input type="text" name="label" value="${cfield.label}" />
          </label>
        </div>
        <div class="field">
          <label>
            ${dgettext(domain, "Default value
                  (regular text for Text, Textarea, Radio or Select):")}
            <br />
            <input type="text" name="value" value="${cfield.value}" />
          </label>
        </div>
        <div class="field">
          <label>${dgettext(domain, "Format (Text or Textarea):")}<br />
            <select name="format" id="format"></select>
          </label>
        </div>
        <div class="field">
          <fieldset class="iefix">
            <label for="options">
              ${dgettext(domain, "Options for Radio or Select (for Select, empty first line makes field optional):")}
            </label>
            <p>
              <textarea id="options" name="options"
                        rows="5" cols="30">${cfield.options}</textarea>
            </p>
          </fieldset>
        </div>
        <div class="field">
          <label>
            ${dgettext(domain, "Rows:")} <input type="text" size="5" name="rows" id="rows" value="${cfield.rows}" />
          </label>
        </div>
        <div class="buttons">
          <input type="submit" name="save" value="${dgettext(domain, 'Save')}" />
          <input type="submit" name="cancel" value="${dgettext(domain, 'Cancel')}" />
        </div>
      </fieldset>
    </form>
    # endif

    # if cf_display=='list':
    <form class="addnew" id="addcf" method="POST">
      ${jmacros.form_token_input()}
      <fieldset>
        <legend>${dgettext(domain, "Add Custom Field:")}</legend>
        <div class="field">
          <label>${dgettext(domain, 'Name:')}<br />
            <input type="text" name="name" id="name" />
          </label>
        </div>
        <div class="field">
          <label>${dgettext(domain, 'Type:')}<br />
            <select name="type" id="type">
              # for value in field_types:
              <option
                  value="${value}">${value.capitalize()}</option>
              # endfor
            </select>
          </label>
        </div>
        <div class="field">
          <label>${dgettext(domain, 'Label:')}<br />
            <input type="text" name="label" id="label" />
          </label>
        </div>
        <div class="field">
          <label for="value">${dgettext(domain, 'Default value:')}<br />
            <input type="text" name="value" id="value" />
          </label>
        </div>
        <div class="field">
          <label>${dgettext(domain, 'Format:')}<br />
            <select name="format" id="format">
            </select>
          </label>
        </div>
        <div class="field">
          <fieldset class="iefix">
            <label for="options">${dgettext(domain, 'Options:')}</label>
            <p>
              <textarea id="options" name="options"
                        rows="4" cols="17"></textarea>
            </p>
          </fieldset>
        </div>
        <div class="field">
          <label for="rows">
            ${dgettext(domain, 'Rows:')} <input type="text" size="2" name="rows" id="rows" />
          </label>
        </div>
        <div class="buttons">
          <input type="submit" name="add" value="${dgettext(domain, 'Add')}" />
        </div>
      </fieldset>
    </form>
    # endif
    # if cf_display=='list':
    <div>
      # if not len(cfields):
      <p class="help">
        ${('No Custom Fields defined for this project.')}
      </p>
      # endif
      # if len(cfields):
      <form method="POST">
        ${jmacros.form_token_input()}
        <table class="listing" id="cflist">
          <thead>
            <tr>
              <th class="sel">&nbsp;</th>
              <th>${dgettext(domain, 'Name')}</th>
              <th>${dgettext(domain, 'Type')}</th>
              <th>${dgettext(domain, 'Label')}</th>
              <th>${dgettext(domain, 'Order')}</th>
            </tr>
          </thead>
          <tbody>
          # for cf in cfields:
          <tr>
              # if not cf.registry:
              <td><input type="checkbox" name="sel"
                value="${cf.name}"/></td>
              # else:
              <td title="${dgettext(domain, 'Field cannot be deleted (declared in source code)')}"></td>
              # endif
              <td><a href="${cf.href}">${cf.name}</a></td>
              <td>${cf.type}</td>
              <td>${cf.label}</td>
              <td class="default">
                <select name="order_${cf.name}">
                  # set count = len(cfields)
                  # for num in range(1, count+1):
                  <option ${{'selected': num==cf.order and 'selected'}|htmlattr}>
                      ${num}
                  </option>
                  # endfor
                  <!--! Extra option in case value is outside regular range -->
                  # if cf.order not in range(1, count+1):
                    <option disabled="disabled">&mdash;</option>
                    <option title="Currently outside regular range"
                            selected="selected">${cf.order}</option>
                  # endif
                </select>
              </td>
          </tr>
          # endfor
          </tbody>
        </table>
        <div class="buttons">
          <input class="trac-disable-on-submit" type="submit" name="remove"
                 value="${dgettext(domain, 'Remove selected items')}" />
          <input type="submit" name="apply" value="${dgettext(domain, 'Apply changes')}" />
        </div>
      </form>
      # endif
    </div>
  # endif
  # endblock
  </body>
</html>
