{% extends 'layout/page.html' %}

{% block head_title %}
  {% if context.id %}
    {% trans %}User{% endtrans %} {{ context.id }} - {{ config.TRACKER_NAME }}
  {% else %}
    {% trans %}New User{% endtrans %} - {{ config.TRACKER_NAME }}
  {% endif %}
{% endblock %}

{% block page_header %}
  {% if not (context.id or context.is_edit_ok()) %}
    {% trans %}New User{% endtrans %}
  {% elif not context.id and context.is_edit_ok() %}
    {% trans %}New User Editing{% endtrans %}
  {% elif context.id and not context.is_edit_ok() %}
    {% trans %}User{% endtrans %} {{ context.id }}
  {% elif context.id and context.is_edit_ok() %}
    {% trans %}User{% endtrans %} {{ context.id }} {% trans %}editing{% endtrans %}
  {% endif %}
{% endblock %}

{% block content %}

  {% include 'layout/permission.html' %}

  {% if context.is_view_ok() %}
    <form class="pb-5" method="POST"
          name="itemSynopsis"
          enctype="multipart/form-data"
          action="{{ context.designator() }}">
      <table>
        <tr>
          <th>{% trans %}Name{% endtrans %}</th>
          <td>
            <input class="form-control" type='text' name="realname" value='{{ context.realname.plain()|u }}'>
          </td>
        </tr>
        <tr>
          <th>{% trans %}Login Name{% endtrans %}</th>
          <td>
            <input class="form-control" type='text' name='username' value='{{ context.username.plain()|u }}'>
          </td>
        </tr>
        {% if context.is_edit_ok() %}
          <tr>
            <th>{% trans %}Login Password{% endtrans %}</th>
            <td>
              <input class="form-control" spellcheck='false' type='password' name='password'>
            </td>
          </tr>
          <tr>
            <th>{% trans %}Confirm Password{% endtrans %}</th>
            <td>
              <input class="form-control" spellcheck='false' type='password' name='@confirm@password'>
            </td>
          </tr>
        {% endif %}
        {% if request.user.hasPermission('Web Roles') %}
          <tr>
            <th>{% trans %}Roles <br>(comma separated){% endtrans %}</th>
            <td>
              <input class="form-control" type='text' name='roles' value='{{ context.roles.plain()|u }}'>
            </td>
          </tr>
        {% endif %}
        <tr>
          <th>{% trans %}Phone{% endtrans %}</th>
          <td>
            <input class="form-control"  type='text' name='phone' value='{{ context.phone.plain()|u }}'>
          </td>
        </tr>
        <tr>
          <th>{% trans %}Organisation{% endtrans %}</th>
          <td>
            <input class="form-control"  type='text' name='organisation' value='{{ context.organisation.plain()|u }}'>
          </td>
        </tr>
        {% if context.timezone %}
          <tr>
            <th>{% trans %}Timezone{% endtrans %}</th>
            <td>
              <input class="form-control"  type='text' name='timezone' value='{{ context.timezone.plain()|u }}'>
            </td>
          </tr>
        {% endif %}
        <tr>
          <th>{% trans %}Email{% endtrans %}</th>
          <td>
            <input class="form-control"  type='text' name='address' value='{{ context.address.plain()|u }}'>
          </td>
        </tr>
        <tr>
          <th>{% trans %}Alternate email address <br>One address per line{% endtrans %}</th>
          <td>
            {{ context.alternate_addresses.multiline(class="form-control")|u|safe }}
          </td>
        </tr>
        {% if context.is_edit_ok() %}
          <tr class="form-actions">
            <td>
            <input type="hidden" name="@template" value="item">
            {{ context.submit(html_kwargs={ 'class': 'btn btn-success' })|u|safe }}
            </td>
          </tr>
        {% endif %}
      </table>
    </form>
  {% endif %}

  {{ context.history()|u|safe }}

{% endblock %}
