{% extends "base.html" %}

{% load wagtailcore_tags %}
{% load static %}

{% block body_class %}template-learning_unit{% endblock %}

{% block content %}

  <learning_unit>
    {% if not page.contents %}
      <div> O0ps, in dieser Lerneinheit wurde kein Inhalt erfasst.</div>
    {% endif %}

    {% for block in page.contents %}

      {% if block.block_type == 'video' %}
        <h1>{{ block.block_type }}</h1>
        <div class="video">
          <h1>{{ block.value.title }}</h1>
          <div>{{ block.value.description }}</div>

          <video width="50%"  controls>
            <source src={{ block.value.url }} type="video/mp4">
            Your browser does not support the video tag.
          </video>
        </div>
      {% endif %}

       {% if block.block_type == 'web_based_training' %}
         <div> Loading web based training...</div>
         <a class="font-bold" href="javascript:open_web_based_training('{{ block.value.url }}');">Click me!</a>

      {% endif %}

    {% endfor %}
  </learning_unit>


  <script>
  function open_web_based_training(url){
    var realUrl = {% get_media_prefix %} + url
    console.log("Loading wbt", realUrl)
    window.location.href = realUrl;
  }
  </script>
{% endblock %}

