{% extends "sakai/base.html" %}{% load molly_utils %}{% load i18n %}

{% block pagetitle %}{% trans "Meetings" %}{% endblock %}

{% block content %}

<div class="section">
    <div class="header">
    <h2>{% trans "Available Events" %}</h2>
    </div>

{% if events %}

{% regroup events by start|date:"W" as weeks %}
<table class="content">
{% for event in events %}

{% ifchanged event.start|date:"WY" %}
<tr class="sub-section-divider"><th colspan='3'>
    {% blocktrans with event.start|date:"W" as week_number and event.start|date:"Y" as year %}Week {{ week_number }}, {{ year }}{% endblocktrans %}
</th></tr>
{% endifchanged %}
<tr><td class="center tutorial-date">
    {% ifequal event.start|date:"dMY" event.end|date:"dMY" %}
      {# 1. If start and end time are on the same day #}

      <big>{{ event.start|date:"D"}}</big>
      <br />
       <small>
      {# Date - Month #}
      {{ event.start|date:"j M"}}
      {# Only show year if start date is not in this year #}
       {% ifnotequal event.start|date:"Y" now|date:"Y"%}
         {{ event.start|date:"Y"}}
       {% endifnotequal %}
      <br />

      {# Day - Time #}

      {% ifequal event.start|date:"A" event.end|date:"A"  %}
          {# If start and end times are both am or pm #}
          {{ event.start|date:"g:i"|lower }}-{{ event.end|date:"g:iA"|lower }}
          {% else %}
          {{ event.start|date:"g:iA"|lower }}-{{ event.end|date:"g:iA"|lower }}
      {% endifequal %}
       </small>
      {# 1. END #}

    {% else %}
      {# Handle the rare occurence that tutorials start and end on different days #}
        {% ifequal event.start|date:"Y" event.end|date:"Y" %}
            {% ifequal event.start|date:"Y" now|date:"Y" %}
            {# Event starts this year and finishes this year #}
                {{ event.start|date:"j M" }}, <small>{{ event.start|date:"g:iA"|lower}}</small>-
                <br />{{ event.end|date:"j M" }}, <small>{{ event.end|date:"g:iA"|lower}}</small>
            {% else %}
            {# Event starts in a different year but finishes in that year too #}
                {{ event.start|date:"j M y" }}, <small>{{ event.start|date:"g:iA"|lower}}</small>-
                <br />{{ event.end|date:"j M y" }}, <small>{{ event.end|date:"g:iA"|lower}}</small>
            {% endifequal %}
        {% else %}
            {{ event.start|date:"j M y" }}, <small>{{ event.start|date:"g:iA"|lower}}</small>-
            <br />{{ event.end|date:"j M y" }}, <small>{{ event.end|date:"g:iA"|lower}}</small>
        {% endifequal %}
    {% endifequal %}

    </td>
    <td>
        {{ event.title }}
    </td>
    {% if 1 or event.permission.update %}
    <td><div class="button"><a href="{% url sakai:signup-event site,event.id %}">{% trans "View" %}</a></div></td>
    {% else %}
    {% if event.permission.attend %}
    <td><div class="button"><a href="{% url sakai:signup-event site,event.id %}">{% trans "Book" %}</a></div></td>
    {% endif %}
    {% endif %}
  </tr> {% endfor %}


</table>

{% else %}

<div class="section-content">
  {% trans "There are currently no available sign-ups for this site." %}
</div>

{% endif %}

</div>
{% endblock %}

