{% extends g.theme.master %}

{% block title %}{{neighborhood.name}} / Award Administration{% endblock %}

{% block header %}Award Administration for {{neighborhood.name}}{% endblock %}

{% block nav_menu %}
{% include 'allura:templates/jinja_master/neigh_nav_menu.html' %}
{% endblock %}

{% block top_nav %}
{% include 'allura:templates/jinja_master/neigh_top_nav.html' %}
{% endblock %}

{% block content %}
          {% if awards_count > 0 %}
          <p>
          <a href="awards/"><h3>Current Awards</h3></a>
            <div id="award_list">
              <table>
                <thead>
                  <tr>
                    <th>Icon</th>
                    <th>Abbreviation</th>
                    <th>Description</th>
                    <th>Delete?</th>
                  </tr>
                </thead>
                <tbody>
                  {% for award in awards %}
                    <tr>
                      <td>
                        <py:if test="award.icon">
                          <img class="award_icon" src="awards/{{award.url()}}/icon" alt=""/>
                        </py:if>
                      </td>
                      <td><a href="{{award.longurl()}}">{{award.short}}</a></td>
                      <td>{{award.full}}</td>
                      <td><a href="{{award.longurl()}}/delete">[X]</a></td>
                    </tr>
                  {% endfor %}
                </tbody>
              </table>
            </div>
          </p>
          {% endif %}

          <h3>Create an Award</h3>
          <form enctype="multipart/form-data" method="POST" action="awards/create">
            <table>
              <thead>
                <tr>
                  <th>Icon</th>
                  <th>Abbreviation</th>
                  <th>Description</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <input type="file" id="icon" name="icon" class="text" />
                  </td>
                  <td>
                    <input name="short" type="text"/>
                  </td>
                  <td>
                    <input name="full" type="text"/>
                  </td>
                  <td>
                    <input type="submit" value="Create"/>
                  </td>
                </tr>
              </tbody>
            </table>
          </form>

          {% macro neighborhood_project_select(n, projects) %}
            <optgroup label="{{n.name}}">
            {% for p in projects %}
              <option value="{{p.name}}">{{p.name}}</option>
            {% endfor %}
            </optgroup>
          {% endmacro %}

          {% if awards_count > 0 %}
          <p>
            <h3>Grant an Award</h3>
            <form method="POST" action="awards/grant">
              <table>
                <thead>
                  <tr>
                    <th>Award</th>
                    <th>Recipient</th>
                    <th></th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>
                      <select name="grant">
                        {% for assign in assigns %}
                          <option value="{{assign.short}}">{{assign.short}}</option>
                        {% endfor %}
                      </select>
                    </td>
                    <td>
                      <select name="recipient">
                      {% for n, projects in neigh_projects %}
                        {{neighborhood_project_select(n, projects)}}
                      {% endfor %}
                      </select>
                    </td>
                    <td>
                      <input type="submit" value="Grant"/>
                    </td>
                  </tr>
                </tbody>
              </table>
            </form>
          </p>
          {% endif %}
          
          {% if grants_count > 0 %}
          <p py:if="">
            <h3>Current Grants</h3>
            <div id="grant_list">
              <table>
                <thead>
                  <tr>
                    <th>Award</th>
                    <th>Recipient</th>
                    <th>Delete?</th>
                  </tr>
                </thead>
                <tbody>
                  {% for grant in grants %}
                    <tr>
                      <td><a href="{{grant.longurl()}}">{{grant.award.short}}</a></td>
                      <td><a href="{{grant.granted_to_project.url()}}">{{grant.granted_to_project.shortname}}</a></td>
                      <td><a href="{{grant.longurl()}}/revoke">[X]</a></td>
                    </tr>
                  {% endfor %}
                </tbody>
              </table>
            </div>
          </p>
          {% endif %}
{% endblock %}
