{% extends "base.html" %}
{% set currentPage = "allProjects" %}

{% block body %}

<h1> Projects Summary </h1>
<!--Menu-->
<ul class="nav nav-tabs">
  {% for menuItem in cfg["committee"] %}
    <li role="presentation"><a href="{{menuItem['link']}}">{{menuItem['title']}}</a></li>
  {% endfor %}
</ul>
<p></p>

<div class = "row">
    <table class = "table table-striped table-hover table-sm">
      <tr>
        <th>Vote</th>
       
        <th>Faculty/Proj. Title</th>
        {% for column in cfg["allProjectsTable"] %}
        <th>
          {{column["title"]}}
        </th>
        {% endfor %}
      </tr>
      {% if fac is not none %}
      {% for person in fac %} <!-- See allBudgets for a better way of doing this -->
        <tr id="row{{loop.index0}}">
          <td>
            <a href="/committee/castVote/{{person.pID.pID}}">
              <button type="button" class="btn btn-default btn-md {% if prev[person.pID.pID] %} btn-success {% endif %}">
                  <span class="glyphicon glyphicon-check" aria-hidden="true"></span> Vote
              </button>
            </a>
          </td>
          <td>
            <a onclick="getProjects('{{person.username.username}}')">{{person.username.firstname}} {{person.username.lastname}}</a>
            {% if collab is not none %}
              {% for c in collab %}
                {% if person.pID == c.pID %}
                  ; <a onclick="getProjects('{{c.username.username}}')">{{c.username.firstname}} {{c.username.lastname}}</a>
                {% endif %}
              {% endfor %}
            {% endif %}
            <span class = "small">({{person.programID.name}})</span>
            <br />
            <span class = "small">{{person.pID.title|truncate(50, True)}}</span>
          </td>
          {% for column in cfg["allProjectsTable"] %}
            <td name = "rowValue" class = "{{column['fieldName']}}" id="col{{loop.index0}}">
              <!--Handle dates-->
              {% if column['fieldName'] == "startDate" or column['fieldName'] == "createdDate" or column['fieldName'] == "endDate"%}  
                {% if person.pID[column['fieldName']] %}{{person.pID[column['fieldName']].strftime('%m-%d-%Y')}}{% endif %}
              <!--Handle Booleans-->
              {% elif column['fieldName'] == "isServiceToCommunity" or column['fieldName'] == "hasCommunityPartner"%}   
                {% if person.pID[column['fieldName']] %} Yes {% else %} No {% endif %}
              <!--Everything else-->
              {% elif column['fieldName'] == "status" %}
                {% if person.pID[column['fieldName']] != cfg["projectStatus"]["incomplete"] %}
                  <select class="form-control" id = "{{person.pID.pID}}-status" onchange = "updateStatus({{person.pID.pID}});">
                    <option value = "pending" {% if person.pID.status == "pending" %}selected{% endif%}>{{cfg["projectStatus"]["pending"]}}</option>
                    <option value = "withdrawn"{% if person.pID.status == "withdrawn" %}selected{% endif%}>{{cfg["projectStatus"]["withdrawn"]}}</option>
                    <option value = "reject"{% if person.pID.status == "reject" %}selected{% endif%}>{{cfg["projectStatus"]["reject"]}}</option>
                    <option value = "accept"{% if person.pID.status == "accept" %}selected{% endif%}>{{cfg["projectStatus"]["accept"]}}</option>
                  </select>
                {% else %}{{person.pID[column['fieldName']]}}{% endif %}
              {% else %}  
                {{person.pID[column['fieldName']]}}
              {% endif %}
            </td>
          {% endfor %}
        </tr>
      {% endfor %}
      {% endif %}
    </table>
  </form>
</div>
{% include "snips/projectsModal.html" %}
<script>
  function updateStatus(projectID) {
    var postValue = {};
    postValue[projectID] = $("#" + projectID + "-status").val();
    $.post("/committee/allProjects/updateStatus", postValue, function(result){
    });
  };
</script>

{% endblock %}