{% extends "metadata_base.html" %}
{% load i18n %}
{% load bootstrap_tags %}
{% load base_tags %}
{% load guardian_tags %}

{% block head %}
  {% include "geonode/ext_header.html" %}
  {{ block.super }}
{% endblock %}

{% block title %}{{ document.alternate }} — {{ block.super }}{% endblock %}

{% block body_class %}data{% endblock %}

{% block body_outer %}

{{ block.super }}

<div class="page-header">
  <a href="{% url "document_browse" %}" class="btn btn-primary pull-right">{% trans "Explore Documents" %}</a>
  <h2 class="page-title">{% trans "Edit Metadata" %}</h2>
</div>
<div class="row">
  <div class="col-md-8">
    <p class="lead">
        {% trans "Editing details for" %} {{ document.title }}
    </p>
    <form id="metadata_update" class="form-horizontal" action="{% url "document_metadata" document.id %}" method="POST">
      {% if document_form.errors or category_form.errors or author_form.errors or poc.errors %}
        <p class="bg-danger">{% blocktrans %}Error updating metadata.  Please check the following fields: {% endblocktrans %}</p>
        <ul class="bg-danger">
        {% if author_form.errors %}
          <li>{% trans "Metadata Author" %}</li>
          {{ author_form.errors }}
        {% endif %}
        {% if poc_form.errors %}
          <li>{% trans "Point of Contact" %}</li>
          {{ poc_form.errors }}
        {% endif %}
        {% for field in document_form %}
            {% if field.errors %}
                <li>{{ field.label }}</li>
            {% endif %}
        {% endfor %}

        {% if category_form.errors %}
            <li>{{ category_form.errors.as_ul }}</li>
        {% endif %}
        </ul>
      {% endif %}
        <div class="form-actions">
          <input type="submit" id="btn_upd_md_up" class="btn btn-primary" value="{% trans "Update" %}"/>
        </div>
      {% csrf_token %}
      <div class="form-controls">
        {{ document_form|as_bootstrap }}
      </div>


        <div class="row">
          <div class="col-md-12">
            <label class="control-label required-field">{% trans "Category" %}</label>
            <fieldset id="category_form">
              {% autoescape off %}
              {% for choice in category_form.category_choice_field.field.choices %}
              <div class="col-md-6">
                <label class="fancy-checkbox">
                    <input type="radio" name="category_choice_field" value="{{ choice.0 }}"
                      {% ifequal category_form.initial choice.0 %} checked="checked" {% endifequal %} />
                    {{ choice.1 }}
                </label>
              </div>
              <!-- div class="radio col-md-6">
                <input type="radio" name="category_choice_field" value="{{ choice.0 }}"
                  {% ifequal category_form.initial choice.0 %} checked="checked" {% endifequal %}>
                  {{ choice.1 }}
                </input>
              </div -->
              {% endfor %}
              {% endautoescape %}
            </fieldset>
          </div>

          <div class="col-md-12 grid-spacer">
              <fieldset class="form-controls modal-forms modal hide fade" id="poc_form" >
                <h2>{% trans "Point of Contact" %}</h2>
                {{ poc_form|as_bootstrap }}
                <button type='button' class="modal-cloose-btn btn btn-primary">Done</button>
              </fieldset>
              <fieldset class="form-controls modal-forms modal hide fade" id="metadata_form">
                <h2>{% trans "Metadata Provider" %}</h2>
                  {{ author_form|as_bootstrap }}
                <button type='button' class="modal-cloose-btn btn btn-primary">Done</button>
              </fieldset>
              <div class="form-actions">
                <input type="submit" id="btn_upd_md_dwn" class="btn btn-primary" value="{% trans "Update" %}"/>
              </div>
          </div>
        </div>
      </form>
  </div>
</div>
{% endblock %}

{% block extra_script %}
{{ block.super }}
<script type="text/javascript">
    $("#id_resource-links").select2({
        placeholder: "Select an option",
        allowClear: true
    });
</script>
<style>
  #s2id_id_resource-links {
    width: '100%';
    height: 100%;
  }
</style>
{% endblock extra_script %}
