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

{% block meta %}
{% leaflet_js %}
{% leaflet_css %}
{% endblock %}
{% load tz %}


{% get_current_timezone as TIME_ZONE %}

{% block title %}{{ workout.name }}{% endblock %}
{% block og_title %}{{ workout.name }}{% endblock %}
{% block description %}{{ workout.name }}
{{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %}
{% block og_description %}{{ workout.name }}
{{ workout.date }} - {{ workout.distance }}m - {{ workout.duration |durationprint:"%H:%M:%S.%f" }}{% endblock %}

{% block scripts %}
{% include "monitorjobs.html" %}
<script type='text/javascript'
        src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>

<script>
$( document ).ready(function() {
$('#id_workouttype').on('change', function(){
        if (
            $(this).val() == 'water'
            || $(this).val() == 'coastal'
            || $(this).val() == 'c-boat'
            || $(this).val() == 'churchboat'
        ) {
            $('#id_boattype').toggle(true);
        } else {
            $('#id_boattype').toggle(false);
            $('#id_boattype').val('1x');
}
        if (
            $(this).val() == 'rower'
            || $(this).val() == 'dynamic'
            || $(this).val() == 'slides'
        ) {
            $('#id_dragfactor').toggle(true);
        } else {
            $('#id_dragfactor').toggle(false);
            $('#id_dragfactor').val('0');
}

});
$('#id_workouttype').change();
});
</script>
{% endblock %}

{% block main %}

<p>
  {% if workout|previousworkout:rower.user %}
  <a href="/rowers/workout/{{ workout|previousworkout:rower.user }}/edit/"
     title="Jump to preceding workout"><em>Previous</em></a>&nbsp;
  {% endif %}
  {% if workout|nextworkout:rower.user %}
  <a href="/rowers/workout/{{ workout|nextworkout:rower.user }}/edit/"
     title="Jump to following workout"><em>Next</em></a>
  {% endif %}
</p>

<h1>Edit Workout {{ workout.name }}</h1>
<ul class="main-content">
  <li class="grid_4">
    <p>
      <div class="fb-share-button"
           data-href="https://rowsandall.com/rowers/workout/{{ workout.id|encode }}/"
           data-layout="button" data-size="small" data-mobile-iframe="false">
        <a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://rowsandall.com/rowers/workout/{{ workout.id|encode }}">Share</a>
      </div>
    </p>
    <p>
      <a class="twitter-share-button"
         href="https://twitter.com/intent/tweet"
         data-url="https://rowsandall.com/rowers/workout/{{ workout.id|encode }}/"
         data-text="@rowsandall #rowingdata">Tweet</a>
    </p>
    <table width=100%>
      <tr>
        {% localtime on %}
        {% if workout.user.user != user %}
        <th>Rower:</th><td>{{ rower.user.first_name }} {{ rower.user.last_name }}</td>
      </tr><tr>
        {% endif %}
        <th>Date/Time:</th><td>{{ workout.startdatetime|localtime}}</td>
        {% endlocaltime %}
      </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>Source:</th><td>{{ workout.workoutsource }}</td>
      </tr><tr>
        <th>Public link to this workout:</th>
        <td>
	  <a href="/rowers/workout/{{ workout.id|encode }}/">https://rowsandall.com/rowers/workout/{{ workout.id|encode }}/</a>
        </td>
      </tr>
    </table>
  </li>
  <li class="grid_2">
    {% if form.errors %}
    <p style="color: red;">
      Please correct the error{{ form.errors|pluralize }} below.
    </p>
    {% endif %}


    <form id="importantform"
          enctype="multipart/form-data" action="" method="post">
      <table width=100%>
        {{ form.as_table }}
      </table>
      {% csrf_token %}
      <input type="submit" value="Save">
    </form>
  </li>
  <li class="grid_2">

    <h1>Workout Summary</h1>

    <p>
      <pre>
        {{ workout.summary }}
      </pre>
    </p>
  </li>
  {% if indoorraces %}
  <li class="grid_4">
    <h1>Racing</h1>
    {% for race in indoorraces %}
    <p>
      <a href="/rowers/virtualevent/{{ race.id }}/submit/{{ workout.id|encode }}/">Submit this to Indoor Challenge {{ race.name }}</a>
    </p>
    {% endfor %}
  </li>
  {% endif %}
  {% if mapdiv %}
  <li class="grid_2">
    <script src="https://cdn.pydata.org/bokeh/release/bokeh-1.0.4.min.js"></script>
    <script async="true" type="text/javascript">
      Bokeh.set_log_level("info");
    </script>



    <div class="mapdiv">
    {{ mapdiv|safe }}
    </div>

    {{ mapscript|safe }}

  </li>
  {% endif %}
  {% for graph in graphs %}
  <li>
    <a href="/rowers/graph/{{ graph.id }}/">
    <img src="/{{ graph.filename }}"
	 onerror="this.src='/static/img/rowingtimer.gif'"
	 alt="{{ graph.filename }}" width="120" height="100">
    </a>
  </li>
  {% endfor %}
	{% for video in videos %}
	<li>
		<div>{{ video.name }}</div>
		<a href="/rowers/video/{{ video.id|encode }}/">
			<img src="https://img.youtube.com/vi/{{ video.video_id }}/hqdefault.jpg"/>
		</a>
	</li>
	{% endfor %}
</ul>

{% endblock %}

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