{% extends "page.html" %}

{% block styles %}
  {{ super() }}
  {% resource 'subscribe/subscribe.css' %}
{% endblock styles %}

{% block primary %}
<article class="module">
  <div class="module-content">

<h1>Manage subscriptions</h1>

<p>Email: {{ email }}</p>
<p>Subscriptions:</p>
{% if subscriptions %}
  <table id="subscriptions">
    {% for subscription in subscriptions %}
      <tr>
        <td>{{ subscription.object_type |capitalize }}</td>
        <td><a href="{{ subscription.object_link }}">{{ subscription.object_title }}</a></td>
        <td>
          {% if not subscription.verified %}Unverified{% endif %}
        </td>
        <td>
          {% if not subscription.verified %}
            <form method='post' action="{{ h.url_for(controller='ckanext.subscribe.controller:SubscribeController', action='signup') }}" id="subscribe-form" enctype="multipart/form-data" class="form-inline">
              <!-- (Bootstrap 3) <div class="form-group input-group-sm"> -->
                <input id="subscribe-email" type="hidden" name="email" value="{{ email }}" />
                <input id="subscribe-{{ subscription.object_type }}" type="hidden" name="{{ subscription.object_type }}" value="{{ subscription.object_name }}" />
              <!-- </div> -->
              <button type="submit" class="btn btn-default" name="save">{{ _('Resend verification email') }}</button>
            </form>
          {% endif %}
        </td>
        <td>
          {% if subscription.verified %}
            {% import 'macros/form.html' as form %}
            <form method='post' action="{{ h.url_for(controller='ckanext.subscribe.controller:SubscribeController', action='update') }}" id="frequency-form" enctype="multipart/form-data" class="form-inline">
              <input id="subscribe-code" type="hidden" name="code" value="{{ code }}" />
              <input id="subscribe-id" type="hidden" name="id" value="{{ subscription.id }}" />
              {{ form.select('frequency', label=_('Emails are sent'), options=frequency_options, selected=subscription.frequency, error=None) }}
              <button class="btn btn-primary" type="submit" name="submit" >
                {{ _('Save') }}
              </button>
            </form>
          {% endif %}
        </td>
        <td>
            <form method='post' action="{{ h.url_for(controller='ckanext.subscribe.controller:SubscribeController', action='unsubscribe') }}" id="unsubscribe-form" enctype="multipart/form-data" class="form-inline">
              <!-- (Bootstrap 3) <div class="form-group input-group-sm"> -->
                <input id="unsubscribe-code" type="hidden" name="code" value="{{ code }}" />
                <input id="unsubscribe-{{ subscription.object_type }}" type="hidden" name="{{ subscription.object_type }}" value="{{ subscription.object_name }}" />
              <!-- </div> -->
              <button type="submit" class="btn btn-default" name="save">{{ _('Unsubscribe') }}</button>
            </form>
          </td>
        </tr>
    {% endfor %}
  </table>

  <form method='post' action="{{ h.url_for(controller='ckanext.subscribe.controller:SubscribeController', action='unsubscribe_all') }}" id="unsubscribe-all" enctype="multipart/form-data" class="form-inline">
    <!-- (Bootstrap 3) <div class="form-group input-group-sm"> -->
      <input id="unsubscribe-code" type="hidden" name="code" value="{{ code }}" />
    <!-- </div> -->
    <button type="submit" class="btn btn-default" name="save">{{ _('Unsubscribe all') }}</button>
  </form>

{% else %}
  (None)
{% endif %}

  </div>
</article>
{% endblock %}

{% block secondary %}{% endblock %}
