{% extends "skeleton.html" %}

{% block title %}Datastore Editor - {% if key %}Edit Entity{% else %}New Entity{% endif %}{% endblock %}

{% block page_head %}
  <script>{% include "datastore_edit.js" %}</script>
{% endblock %}

{% block body %}
<div id="datastore-viewer">
  <h3>{% if key %}Edit &quot;{{ kind }}&quot; Entity{% else %}New &quot;{{ kind }}&quot; Entity{% endif %}</h3>

  <form action="{{ request.path }}" method="post">
    <input type="hidden" name="xsrf_token" value="{{ xsrf_token }}"/>
    <input type="hidden" name="next" value="{{ next }}"/>
    {% if key and namespace %}
      <div class="ae-settings-block">
        <label>Namespace</label>
        <div>{{ namespace }}</div>
      </div>
    {% endif %}
    <div class="ae-settings-block">
      <label>Entity Kind</label>
      <div>
        {{ kind }}
        <input type="hidden" name="kind" value="{{ kind }}"/>
      </div>
    </div>
    {% if key %}
      <div class="ae-settings-block">
        <label>Entity Key</label>
        <div>
          {{ key }}
          <input type="hidden" name="key" value="{{ key }}"/>
        </div>
      </div>
    {% endif %}
    {% if key_name %}
      <div class="ae-settings-block">
        <label>Key Name</label>
        <div>
          {{ key_name }}
        </div>
      </div>
    {% endif %}
    {% if key_id %}
      <div class="ae-settings-block">
        <label>ID</label>
        <div>
          {{ key_id }}
        </div>
      </div>
    {% endif %}
    {% if parent_key %}
      <div class="ae-settings-block">
        <label>Parent</label>
        <div>
          {{ parent_key }}<br />
          <a href="/datastore/edit/{{parent_key}}?next={{ request.uri }}">{{ parent_key_string }}</a>
        </div>
      </div>
    {% endif %}
    {% if not key %}
      {% if namespace %}
        <div class="ae-settings-block">
          <label>Namespace ({{ namespace }})</label>
          <div><input type="text" name="namespace" value="{{ namespace }}"/></div>
        </div>
      {% endif %}
    {% endif %}
    <div class="ae-settings-block ae-settings-block"></div>
    {% for field in fields %}
      <div class="ae-settings-block">
        <label>
          {{ field.0 }}&nbsp;({{ field.1 }})
        </label>
        <div>{{ field.2|safe }}</div>
      </div>
    {% endfor %}
    <div class="ae-settings-block">
      <div>
        <input class="ae-button ae-button-submit" type="submit" value="Save Changes"/>
        {% if key %}
          <input id="delete_button" class="ae-button" type="submit" name="action:delete" value="Delete"/>
        {% endif %}
      </div>
    </div>
  </form>
</div>
{% endblock %}
