{% extends "spirit/_base.html" %}

{% load spirit_tags i18n %}

{% block title %}{% trans "Publish topic" %}{% endblock %}

{% block head-extra %}
    <script>

	$( document ).ready(function() {

		$( "textarea" ).store( "topic_publish_comment" );

        $( ".js-poll-add" ).on( 'click', function( e ) {
            $( this ).closest( 'dd' ).hide();
            $( ".js-poll-form" ).show();
            e.preventDefault();
            e.stopPropagation();
        });

	});

	</script>
{% endblock %}

{% block content %}

    <h1 class="headline">{% trans "Publish topic" %}</h1>

    <form action="." method="post" class="js-reply">
        {% csrf_token %}

        {# topic #}
        {% include "spirit/_form.html" %}

        {# poll #}
        <dl class="preference">
            <dt class="preference-label">{% trans "Poll" %}:</dt>

            {% if not pform.errors and not pformset.has_errors %}
                <dd class="preference-desc"><a class="js-poll-add" href="#"><i class="fa fa-bar-chart-o"></i> {% trans "Add poll" %}</a></dd>
            {% endif %}
        </dl>

        <div class="js-poll-form" style="{% if not pform.errors and not pformset.has_errors %}display:none;{% endif %}margin-left:20px;">
            {% include "spirit/_form.html" with form=pform %}
            {% include "spirit/_formset.html" with formset=pformset %}
        </div>

        {# comment #}
        <div class="topic-publish-comment">
            {% include "spirit/_form.html" with form=cform %}
        </div>

        <div class="container">
            {% include "spirit/comment/_editor.html" %}

            <input class="button reply-button" type="submit" value="{% trans "Publish" %}" />
        </div>
    </form>

{% endblock %}
