{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}

{% block title %}Rowsandall Training Plans{% endblock %}

{% block scripts %}

{% endblock %}

{% block main %}
<h1>Manage Training Targets and Plan for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<ul class="main-content">
  <li class="grid_2">
    <h2>Training Targets</h2>

    {% if targets %}
    <table width="100%" class="listtable shortpadded">
      <thead>
        <tr>
          <th>Target Date</th>
          <th>Name</th>
          <th>Notes</th>
        </tr>
      </thead>
      <tbody>
        {% for target in targets %}
        <tr>
          <td> {{ target.date }}</td>
          <td> {{ target.name }}</td>
          <td> {{ target.notes|linebreaks }}</td>
          <td> <a href="/rowers/edittarget/{{ target.id }}">Edit</a>
          <td> <a href="/rowers/deletetarget/{{ target.id }}">Delete</a>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% if old_targets %}
    <p>Old Targets</p>
    <table width="100%" class="listtable shortpadded">
      <thead>
	<tr>
	  <th>Target Date</th>
	  <th>Name</th>
	  <th>Notes</th>
	</tr>
      </thead>
      <tbody>
	{% for target in old_targets %}
        <tr>
          <td> {{ target.date }}</td>
          <td> {{ target.name }}</td>
          <td> {{ target.notes|linebreaks }}</td>
          <td> <a href="/rowers/edittarget/{{ target.id }}">Edit</a>
          <td> <a href="/rowers/deletetarget/{{ target.id }}">Delete</a>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% endif %}
    {% elif old_targets %}
    <p>Old Targets</p>
    <table width="100%" class="listtable shortpadded">
      <thead>
	<tr>
	  <th>Target Date</th>
	  <th>Name</th>
	  <th>Notes</th>
	</tr>
      </thead>
      <tbody>
	{% for target in old_targets %}
        <tr>
          <td> {{ target.date }}</td>
          <td> {{ target.name }}</td>
          <td> {{ target.notes|linebreaks }}</td>
          <td> <a href="/rowers/edittarget/{{ target.id }}">Edit</a>
          <td> <a href="/rowers/deletetarget/{{ target.id }}">Delete</a>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% else %}
    No training targets found
    {% endif %}
  </li>
  <li class="grid_2">
    <h2>Add a target</h2>

    <form id="newplanform"
          enctype="multipart/form-data" action="" method="post">
      <table width=100%>
        {{ targetform.as_table }}
      </table>
      {% csrf_token %}
      <input class="button green" type="submit" value="Save">
    </form>
      
  </li>
  <li class="grid_2">
    <h2>Plans</h2>
    
    {% if plans %}
    <table width="100%" class="listtable shortpadded">
      <thead>
        <tr>
          <th> Start Date</th>
          <th> End Date</th>
          <th> Name</th>
          <th> Status</th>
        </tr>
      </thead>
      <tbody>
        {% for plan in plans %}
        <tr>
          <td> {{ plan.startdate }} </td>
          <td> {{ plan.enddate }}</td>
          <td><a href="/rowers/plan/{{ plan.id }}">{{ plan.name }}</a></td>
          <td> {% if plan.status %} active {% else %} inactive {% endif %}</td>
          <td>
            {% if request.user.rower == plan.manager %}
            <a href="/rowers/editplan/{{ plan.id }}">Edit</a>
            {% endif %}
          </td>
          <td> <a href="/rowers/plan/{{ plan.id }}">Plan</a></td>
          <td>
            {% if request.user.rower == plan.manager %}
            <a href="/rowers/deleteplan/{{ plan.id }}">Delete</a>
            {% endif %}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% else %}
    <p> No plans found </p>
    {% endif %}

  </li>
  <li class="grid_2">
    <h2>Add a plan</h2>
    
    <form id="newplanform"
          enctype="multipart/form-data" action="" method="post">
      <table width=100%>
        {{ form.as_table }}
      </table>
      {% csrf_token %}
      <input class="button green" type="submit" value="Save">
      
  </li>
</ul>


  {% endblock %}

{% block sidebar %}
{% include 'menu_plan.html' %}
{% endblock %}
