{# vim: set ts=2 et sts=2 sw=2: #}
{#

Base template for creating a new or editing an existing question. The cases for
showing uneditable product and category names are handled here. Fancier
behaviors like editing them can be provided by overriding blocks.

If there's a `form`, we also expect `current_product` and `current_category` so
we can compute the edit-title URL.

#}
{% extends "questions/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor %}
{% set classes = 'new-question' %}

{% block content %}
  <article class="main">
    <div id="ask-question">
      <h1>{% block headline %}Do Something to a Question{% endblock %}</h1>
      <div class="inner-wrap">

        {% block product %}
          {% if current_product %}
            <div class="selected">
              <label>{{ _('Firefox Product') }}:</label>
              <span>{{ current_product.name }}</span>
              {% block product_changer %}
              {% endblock %}
            </div>
          {% endif %}
        {% endblock %}

        {% block category %}
          {% if current_product and current_category %}
            <div class="selected">
              <label>Category:</label>
              <span>{{ current_category.name }}</span>
              {% block category_changer %}
              {% endblock %}
            </div>
          {% endif %}
        {% endblock %}

        {% block articles_and_search_results %}
        {% endblock %}

        {% if form %}
          <form id="question-form" action="" method="post">
            {{ csrf() }}
            {% block major_detail_instructions %}
              <h2>Do some stuff.</h2>
            {% endblock %}
            <h3>{{ _('The more information you can provide, the better the chance your question will be answered.') }}</h3>
            {{ errorlist(form) }}
            {% for field in form.hidden_fields() %}
              {{ field|safe }}
            {% endfor %}
            <ol>
              {% set li_class='' %}
              {% for field in form.visible_fields() %}

                {% if field.name == 'ff_version' %}
                  <li class="system-details-info show">
                    <p>
                      {{ _("We've made some educated guesses about your current browser and operating system.") }}
                      <a href="#show-details" class="show">{{ _('Show details &raquo;')|safe }}</a>
                      <a href="#hide-details" class="hide">{{ _('Hide details &raquo;')|safe }}</a>
                    </p>
                  </li>
                  {% set li_class='details' %}
                {% endif %}

                <li class="{{ li_class }} {% if field.errors %}invalid{% endif %}">
                  {{ field.label_tag()|safe }}

                  {% if field.name == 'title' and not request.GET.edit_title %}
                    <div id="title-val">
                      <span title="{{ _('Click to change your question') }}">
                        {% if form.initial %}{{ form.initial.title }}{% else %}{{ form.title.data }}{% endif %}
                      </span>
                      <a href="{{ ''|urlparams(product=current_product.key, category=current_category.key, showform=1, search=request.GET.search, edit_title=1) }}#question-form">edit</a>
                      {{ field.as_hidden()|safe }}
                    </div>
                  {% elif field.name == 'content' %}
                    {{ content_editor(field) }}
                  {% else %}
                    {{ field|safe }}
                  {% endif %}

                  {% if field.help_text %}
                    <p class="help-text">{{ field.help_text|safe }}</p>
                  {% endif %}
                </li>

              {% endfor %}

              <li class="submit">
                <input type="submit" class="btn btn-important" value="{% block submit_button_value %}Save Question{% endblock %}" />
                {% block more_submit_buttons %}{% endblock %}
              </li>
            </ol>
          </form>
        {% endif %}

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

{% block side %}
{% endblock %}