<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="admin.html" />
  <head>
    <title>${_('Manage Custom Fields')}</title>
    <script type="text/javascript">
/* <![CDATA[ */
    function custom_field_validate( ){
      function show( id ){
        $('#addcf [name="' + id + '"], #addcf label[for="'+id+'"]').show();
      }
      function hide( id ){
        $('#addcf [name="' + id + '"], #addcf label[for="'+id+'"]').hide();
      }
      switch($('#type').val()) {
        case 'text':            
          hide('options'); hide('cols'); hide('rows'); break;
        case 'select':
          show('options'); hide('cols'); hide('rows'); break;
        case 'checkbox':
          hide('options'); hide('cols'); hide('rows'); break;
        case 'radio':
          show('options'); hide('cols'); hide('rows'); break;
        case 'textarea':
          hide('options'); show('cols'); show('rows'); break;
      }
    }
    $(function() {
      custom_field_validate();
      $('#type').change(custom_field_validate);
    });
/* ]]> */
    </script>
  </head>

  <body>

    <h2>${_('Manage Custom Fields')}</h2>

    <!--! Detail view -->
    <form py:if="cfadmin.display=='detail'" class="mod" id="addcf" method="POST">
      <fieldset>
        <legend>${_('Modify Custom Field')}:</legend>
        <div class="field">
          <label>${_('Name')} (${_('cannot modify')}): <strong>${cfadmin.customfield.name}</strong></label>
        </div>
        <input name="name" value="${cfadmin.customfield.name}" type="hidden" />
        <input name="order" value="${cfadmin.customfield.order}" type="hidden" />
        <div class="field">
          <label>${_('Type')}:<br />
            <select name="type" id="type">
              <option value="text" selected="${cfadmin.customfield.type=='text' and 'selected' or None}">
                ${_('Text')}</option>
              <option value="select" selected="${cfadmin.customfield.type=='select' and 'selected' or None}">
                ${_('Select')}</option>
              <option value="checkbox" selected="${cfadmin.customfield.type=='checkbox' and 'selected' or None}">
                ${_('Checkbox')}</option>
              <option value="radio" selected="${cfadmin.customfield.type=='radio' and 'selected' or None}">
                ${_('Radio')}</option>
              <option value="textarea" selected="${cfadmin.customfield.type=='textarea' and 'selected' or None}">
                ${_('Textarea')}</option>
            </select>
          </label>
        </div>
        <div class="field">
          <label>${_('Label')}:<br />
            <input type="text" name="label" value="${cfadmin.customfield.label}" />
          </label>
        </div>
        <div class="field">
          <label>${_('Default value')} (regular text for Text, Textarea, Radio or Select):<br />
            <input type="text" name="value" value="${cfadmin.customfield.value}" />
          </label>
        </div>
        <div class="field">
          <fieldset class="iefix">
            <label for="options">
              ${_('Options for Radio or Select (for Select, empty first line makes field optional)')}:
            </label>
            <p>
              <textarea id="options" name="options" rows="5" cols="30">${cfadmin.customfield.options}</textarea>
            </p>
          </fieldset>
        </div>
        <div class="field">
          <label for="cols">${_('Size of Textarea for entry (Textarea only)')}:<br />
            ${_('Columns')}: <input type="text" name="cols" id="cols" size="5" value="${cfadmin.customfield.width}" />
            ${_('Rows')}: <input type="text" size="5" name="rows" id="rows" value="${cfadmin.customfield.height}" /></label>
        </div>
        <div class="buttons">
          <input type="submit" name="cancel" value="Cancel" />
          <input type="submit" name="save" value="Save" />
        </div>
      </fieldset>
    </form>

    <form py:if="cfadmin.display=='list'" class="addnew" id="addcf" method="POST">
      <fieldset>
        <legend>${_('Add Custom Field')}:</legend>
        <div class="field">
          <label>${_('Name')}:<br />
            <input type="text" name="name" id="name" />
          </label>
        </div>
        <div class="field">
          <label>${_('Type')}:<br />
            <select name="type" id="type">
              <option py:for="value in ['text', 'select', 'checkbox', 'radio', 'textarea']"
                  value="${value}">${value.capitalize()}</option>
            </select>
          </label>
        </div>
        <div class="field">
          <label>${_('Label')}:<br />
            <input type="text" name="label" id="label" />
          </label>
        </div>
        <div class="field">
          <label for="value">${_('Default value')}:<br />
            <input type="text" name="value" id="value" />
          </label>
        </div>
        <div class="field">
          <fieldset class="iefix">
            <label for="options">${_('Options')}:</label>
            <p>
              <textarea id="options" name="options" rows="4" cols="17"></textarea>
            </p>
          </fieldset>
        </div>
        <div class="field">
          <label for="cols">${_('Size of Textarea')}:<br />
            ${_('Cols')}: <input type="text" name="cols" id="cols" size="2" />
            ${_('Rows')}: <input type="text" size="2" name="rows" id="rows" />
          </label>
        </div>
        <div class="buttons">
          <input type="submit" name="add" value="Add" />
        </div>
      </fieldset>
    </form>

    <div py:if="cfadmin.display=='list'" py:strip="">
      <p py:if="not len(cfadmin.customfields)" class="help">
        ${_('No Custom Fields defined for this project')}.
      </p>
      <form py:if="len(cfadmin.customfields)" id="customfields" method="POST">
        <table class="listing" id="cflist">
          <thead>
            <tr>
              <th class="sel">&nbsp;</th>
              <th>${_('Name')}</th>
              <th>${_('Type')}</th>
              <th>${_('Label')}</th>
              <th>${_('Order')}</th>
            </tr>
          </thead>
          <tbody>
            <tr py:for="cf in cfadmin.customfields">
              <td><input type="checkbox" name="sel" value="${cf.name}" /></td>
              <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}">
                  <option py:for="other in cfadmin.customfields"
                      selected="${other.order==cf.order and 'selected' or None}">
                      ${other.order}
                  </option>
                </select>
              </td>
            </tr>
          </tbody>
        </table>
        <div class="buttons">
          <input type="submit" name="remove" value="Remove selected items" />
          <input type="submit" name="apply" value="Apply changes" />
        </div>
      </form>
    </div>
    <div id="help">
        <strong>Note:</strong>
        if you want to know more see <a href="${req.href('agilo-help', 'admin/FieldAdmin')}">Fields Admin</a> in
        the Agilo help. 
    </div>
  </body>

</html>

