{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "kbforums/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor %}
{# L10n: {d} is the name of the document. #}
{% set title = _('Create a new thread | {d} | Knowledge Base')|f(d=document.title) %}
{% set crumbs = [(url('wiki.category', document.category), document.get_category_display()),
                 (document.get_absolute_url(), document.title),
                 (url('wiki.discuss.threads', document.slug), _('Discuss')),
                 (None, _('Create a new thread'))] %}

{% block content %}
<article id="new-thread" class="main">
  <h1>{{ _('Create a new thread') }}</h1>

  <form action="{{ url('wiki.discuss.new_thread', document.slug) }}" method="post" class="new-thread">
    {{ csrf() }}
    {{ errorlist(form) }}

    {% for field in form %}
      <div class="form-widget{% if field.errors %} invalid{% endif %}">
        {{ field.label_tag()|safe }}
        {% if field.name == 'content' %}
          {{ content_editor(field) }}
        {% else %}
          {{ field|safe }}
        {% endif %}
      </div>
    {% endfor %}

    <div class="form-widget submit">
      <input type="submit" name="preview" value="{{ _('Preview') }}" />
      <input type="submit" value="{{ _('Post') }}" />
      <a href="{{ url('wiki.discuss.threads', document.slug) }}">{{ _('Cancel') }}</a>
    </div>

    {% if post_preview %}
      <div id="post-preview">
        <h3>{{ _('Post Preview:') }}</h3>
        <ol class="posts">
          <li>
            {% set post = post_preview %}
            {% include "kbforums/includes/post.html" %}
          </li>
        </ol>
      </div>
    {% endif %}
  </form>
</article>
{% endblock %}
