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

{% block title %}Advanced Features {% endblock %}

{% block content %}
<div id="workouts" class="grid_6 alpha">
  <div class="grid_6 alpha">
    <h1>Wind Editor</h1>
  </div>
  <div class="grid_6 alpha">
    <div class="grid_2 alpha">
      <p>
        <a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a>
      </p>
    </div>
    <div class="grid_2">
      <p>
        <a class="button gray small" href="/rowers/workout/{{ workout.id }}/advanced">Advanced Edit</a>
      </p>
      
    </div>
    <div class="grid_2 omega tooltip">
      <p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/otwsetpower">OTW Power</a></p>
      <span class="tooltiptext">Run calculations to get power values for your row.</span>
      
    </div>
  </div>
  <div class="grid_6 alpha">
    <div class="grid_2 prefix_4 alpha">
      <p><a class="button blue small" href="/rowers/workout/{{ workout.id }}/stream">Stream Edit</a></p>
    </div>
  </div>
  <div class="grid_6  alpha">
    <p>
      Update wind between distance 1 and distance 2. Submit wind strength
      and direction at start and end of segment. Blank the form for values 
      you want to keep intact.
    </p>
    
    <p>
      Check <a href="https://www.wunderground.com">www.wunderground.com</a> 
      to find historical weather data from an on-line weather station near
      the location of your row. 
    </p>
    
    <div class="grid_4 alpha">
      <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
        {% if form.errors %}
        <p style="color: red;">
          Please correct the error{{ form.errors|pluralize }} below.
        </p>
        {% endif %}
	
        <table>
          {{ form.as_table }}
        </table>
        {% csrf_token %}
        
    </div>
    <div class="grid_2 omega">
      <p>Closest Airport Weather: {{ airport }}
        ({{ airportdistance | floatformat:-1 }} km)
	<a class="button green small" href="/rowers/workout/{{ workout.id }}/metar/{{ airport }}">Airport Data</a></p>
      <p>
	<a class="button green small" href="/rowers/workout/{{ workout.id }}/darkskywind">Dark Sky Data</a>
      <p>
	Download wind speed and bearing from <a href="http://forecast.io/">The Dark Sky</a>
      </p>
    </div>
    <div class="grid_2 omega">
      <input class="button green small" type="submit" value="Submit Form">
      <p>
	Manual update of the wind data from the form.
      </p>
    </div>
    </form>
    <img src="http://cliparts.co/cliparts/rTn/KaR/rTnKaRrxc.gif" width="400">
  </div>
</div>
<div id="advancedplots" class="grid_6 omega">
  
  <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>
  
  {{ interactiveplot |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">
    <div class="grid_6 alpha">
      {{ the_div |safe }}
    </div>
  </div>
  
  <div id="interactiveplot" class="grid_6 omega">
    <div class="grid_6 alpha">

      {{ gmapdiv |safe }}
      {{ gmap |safe }}
    </div>
  </div>
  
{% endblock %}
