{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "kbforums/base.html" %}
{# L10n: {d} is the name of the document. #}
{% set title = _('{d} Discussion | Knowledge Base')|f(d=document.title) %}
{% set crumbs = [(url('wiki.category', document.category), document.get_category_display()),
                 (document.get_absolute_url(), document.title),
                 (None, _('Discuss'))] %}

{% block content %}
<article id="threads" class="main">
  <h1>{{ _('{d} Discussion')|f(d=document.title) }}</h1>
  <div class="badges">
    {% if is_watching_forum %}<span class="watching">{{ _('Watching') }}</span>{% endif %}
  </div>
  <div class="forum-actions">
    {% if user.is_authenticated() %}
      <form action="{{ url('wiki.discuss.watch_forum', document.slug) }}" method="post">
        {{ csrf() }}
        {% if is_watching_forum %}
          {% set watch = _('Stop watching') %}
          <input type="hidden" name="watch" value="no" />
        {% else %}
          {% set watch = _('Watch this forum') %}
          <input type="hidden" name="watch" value="yes" />
        {% endif %}
        <input type="image" alt="{{ watch }}" title="{{ watch }}" src="{{ MEDIA_URL }}img/forums/watch.png"/>
      </form>
    {% endif %}
    <a id="new-thread" href="{{ url('wiki.discuss.new_thread', document_slug=document.slug) }}">{{ _('Post a new thread') }}</a>
  </div>
  <ol class="threads-columns {% if not desc_toggle %}desc{% endif %}">
    <li class="type"><a href="{{ url('wiki.discuss.threads', document.slug) }}">{{ _('Type') }}</a></li>
    <li class="title">{{ _('Title') }}</li>
    <li class="author{% if sort == 3 %} sort{% endif %}"><a href="{{ request.path|urlparams(sort=3, desc=desc_toggle) }}">{{ _('Author') }}</a></li>
    <li class="replies{% if sort == 4 %} sort{% endif %}"><a href="{{ request.path|urlparams(sort=4, desc=desc_toggle) }}">{{ _('Replies') }}</a></li>
    <li class="last-post{% if sort == 5 %} sort{% endif %}"><a href="{{ request.path|urlparams(sort=5, desc=desc_toggle) }}">{{ _('Last Post') }}</a></li>
  </ol>
  {% if threads.object_list %}
    <ol class="threads">
    {% for thread in threads.object_list %}
      <li>
        <div class="type">
          {% if thread.is_locked %}
            <img src="{{ MEDIA_URL }}img/forums/type/locked.png" alt="{{ _('Locked', 'thread_type') }}" title="{{ _('Locked', 'thread_type') }}"/>
          {% endif %}
          {% if thread.is_sticky %}
            <img src="{{ MEDIA_URL }}img/forums/type/sticky.png" alt="{{ _('Sticky', 'thread_type') }}" title="{{ _('Sticky', 'thread_type') }}"/>
          {% endif %}
        </div>
        <div class="title"><a href="{{ url('wiki.discuss.posts', document.slug, thread.id) }}">{{ thread.title }}</a></div>
        <div class="author"><a class="username" href="{{ profile_url(thread.creator) }}">{{ thread.creator.username }}</a></div>
        <div class="replies">{{ thread.replies }}</div>
        <div class="last-post">
          <a href="{{ thread.last_post.get_absolute_url() }}">
            {{ datetimeformat(thread.last_post.created) }}
          </a><br/>
          {{ _('by <a class="username" href="{profile_url}">{username}</a>')|fe(profile_url=profile_url(thread.last_post.creator), username=thread.last_post.creator.username) }}
        </div>
      <hr/>
      </li>
    {% endfor %}
    </ol>

    {{ threads|paginator }}
  {% else %}
    <p>{{ _('There are no threads. Maybe you should create some!') }}</p>
  {% endif %}
</article>
{% endblock %}
