{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% load tz %}

{% block title %}Change Workout {% endblock %}

{% block content %}
<div id="workouts" class="grid_6 alpha">

  {% if form.errors %}
  <p style="color: red;">
    Please correct the error{{ form.errors|pluralize }} below.
  </p>
  {% endif %}

  <h1>Edit Workout Interval Data</h1>
  <div class="grid_6 alpha">
    <div class="grid_2 alpha">
      <p>
	<a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit</a>
      </p>
    </div>
    <div class="grid_2">
      <p>
	<a class="button gray small" href="/rowers/workout/{{ workout.id }}/export">Export</a>
        
      </p>
    </div>
    <div class="grid_2 omega tooltip">
      <p>
	<a class="button gray small" href="/rowers/workout/{{ workout.id }}/advanced">Advanced</a>
      </p>
      <span class="tooltiptext">Advanced Functionality (More interactive Charts)</span>
	
    </div>
  </div>

  
  {% localtime on %}

  <p>
  <form enctype="multipart/form-data" action="/rowers/workout/{{ workout.id }}/split" method="post">
    <table width=100%>
      {{ form.as_table }}
    </table>
    {% csrf_token %}
    <div id="formbutton" class="grid_1 prefix_4 suffix_1">
      <input class="button green" type="submit" value="Split">
    </div>
  </form>
  </p>
  <h1>Workout Split</h1>
  <p>Split your workout in half at the given time using the form above.
    Use the chart on
  the right to find the point where you want to split.</p>
  <p>Use any of the following formats:
    <ul>
      <li>H:MM:SS.d, e.g. 1:45:00.0 for one hour and 45 minutes</li>
      <li>H:MM:SS, e.g. 1:45:00 for one hour and 45 minutes</li>
      <li>MM:SS.d, e.g. 30:00.0 for thirty minutes</li>
      <li>MM, e.g. 30 for thirty minutes</li>
    </ul>
  </p>
  <p>Warning: If you deselect, "Keep Original", the original workout
    cannot be restored afterwards.</p>
  
</div>

<div id="advancedplots" class="grid_6 omega">
  <div class="grid_6 alpha">
    
    <script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
    <script async="true" type="text/javascript">
      Bokeh.set_log_level("info");
    </script>
    
    {{ thescript |safe }}
    
    <script>
      // Set things up to resize the plot on a window resize. You can play with
      // the arguments of resize_width_height() to change the plot's behavior.
      var plot_resize_setup = function () {
      var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot
      var plot = Bokeh.index[plotid];
      var plotresizer = function() {
      // arguments: use width, use height, maintain aspect ratio
      plot.resize_width_height(true, true, true);
      };
      window.addEventListener('resize', plotresizer);
      plotresizer();
      };
      window.addEventListener('load', plot_resize_setup);
    </script>
    <style>
      /* Need this to get the page in "desktop mode"; not having an infinite height.*/
      html, body {height: 100%; margin:5px;}
    </style>
    
    
    <div id="interactiveplot" class="grid_6 omega">
      {{ thediv |safe }}
    </div>

      <table width=100%>
    <tr>
      <th>Date/Time:</th><td>{{ workout.startdatetime }}</td>
    </tr><tr>
      <th>Distance:</th><td>{{ workout.distance }}m</td>
    </tr><tr>
      <th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
    </tr><tr>
      <th>Public link to this workout</th>
      <td>
	<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
      <td>
    </tr><tr>
      <th>Public link to interactive chart</th>
      <td>
	<a href="/rowers/workout/{{ workout.id }}/interactiveplot">https://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot</a>
      <td>
    </tr>
  </table>
  {% endlocaltime %}
        

  </div>
</div>


{% endblock %}
