{% extends base %}
{% from 'macro.html' import breadcrumbs with context %}
{% block content %}
<div class="row">
    <div class="span12">
        {{- breadcrumbs([[url_for('author.info'), 'Кабинет автора']]) }}
    </div>

    <div class="span12"{% if not story_add %} id="story_{{ story.id }}"{% endif %}>
        {% include 'includes/story_control_buttons.html' %}
        <h1>
            {{ page_title }}
        </h1>
        {% if story_add %}
{{ html_block('story_add') }}
        {% endif %}
        {% if saved %}<div class="alert-mini green">Изменения сохранены</div>{% endif %}

        <form method="POST" enctype="multipart/form-data" class="form-horizontal">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
            <fieldset>
                <legend>Параметры рассказа</legend>

                <!-- Название -->
                <div class="control-group{% if form.title.errors %} error{% endif %}">
                    {{ form.title.label(class_='control-label') }}
                    <div class="controls">{{ form.title }}
                        {% if form.title.errors %}
                            {% for error in form.title.errors %}
                        <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.title.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Жанры -->
                <div class="control-group{% if form.categories.errors %} error{% endif %}">
                    {{ form.categories.label(class_='control-label', for=False) }}
                    <div class="controls genres-select">
                        {% if form.categories.errors %}
                            {% for error in form.categories.errors %}
                            <span class="help-block">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-block small">{{ form.categories.description }}</span>
                        {% endif %}
                          {{ form.categories }}
                     </div>
                </div>
                <!-- Персонажи -->
                <div class="control-group{% if form.characters.errors %} error{% endif %}">
                    {{ form.characters.label(class_='control-label', for=False) }}
                    <div class="controls characters-select">
                        {% if form.characters.errors %}
                            {% for error in form.characters.errors %}
                        <span class="help-block">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-block small">{{ form.characters.description }}</span>
                        {% endif %}
                          {{ form.characters }}
                      </div>
                </div>
                <!-- Общее описание -->
                <div class="control-group{% if form.summary.errors %} error{% endif %}">
                    {{ form.summary.label(class_='control-label') }}
                    <div class="controls">{{ form.summary }}
                        {% if form.summary.errors %}
                            {% for error in form.summary.errors %}
                            <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.summary.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Заметки к рассказу -->
                <div class="control-group{% if form.notes.errors %} error{% endif %}">
                    {{ form.notes.label(class_='control-label', for='id_notes') }}
                    <div class="controls">{{ form.notes }}
                        {% if form.notes.errors %}
                            {% for error in form.notes.errors %}
                                <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.notes.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Источник -->
                <div class="control-group{% if form.source_link.errors %} error{% endif %}">
                    {{ form.source_link.label(class_='control-label') }}
                    <div class="controls">{{ form.source_link }}
                        {% if form.source_link.errors %}
                            {% for error in form.source_link.errors %}
                        <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.source_link.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <div class="control-group{% if form.source_title.errors %} error{% endif %}">
                    {{ form.source_title.label(class_='control-label') }}
                    <div class="controls">{{ form.source_title }}
                        {% if form.source_title.errors %}
                            {% for error in form.source_title.errors %}
                        <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.source_title.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Рейтинг -->
                <div class="control-group{% if form.rating.errors %} error{% endif %}">
                    {{ form.rating.label(class_='control-label', for=False) }}
                    <div class="controls bootstrap radio">{{ form.rating }}
                        {% if form.rating.errors %}
                            {% for error in form.rating.errors %}
                                <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.rating.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Оригинал/перевод -->
                <div class="control-group{% if form.original.errors %} error{% endif %}">
                    {{ form.original.label(class_='control-label', for=False) }}
                    <div class="controls bootstrap radio">{{ form.original }}
                        {% if form.original.errors %}
                            {% for error in form.original.errors %}
                                <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.original.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Заморожен/активен -->
                <div class="control-group{% if form.freezed.errors %} error{% endif %}">
                    {{ form.freezed.label(class_='control-label', for=False) }}
                    <div class="controls bootstrap radio">{{ form.freezed }}
                        {% if form.freezed.errors %}
                            {% for error in form.freezed.errors %}
                                <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.freezed.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- Закончен/не закончен -->
                <div class="control-group{% if form.finished.errors %} error{% endif %}">
                    {{ form.finished.label(class_='control-label', for=False) }}
                    <div class="controls bootstrap radio">{{ form.finished }}
                        {% if form.finished.errors %}
                            {% for error in form.finished.errors %}
                                <span class="help-inline">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-inline small">{{ form.finished.description }}</span>
                        {% endif %}
                      </div>
                </div>
                <!-- События -->
                <div class="control-group{% if form.classifications.errors %} error{% endif %}">
                    {{ form.classifications.label(class_='control-label', for=False) }}
                    <div class="controls events">
                        {% if form.classifications.errors %}
                            {% for error in form.classifications.errors %}
                            <span class="help-block">{{ error }}</span>
                            {% endfor %}
                        {% else %}
                            <span class="help-block small">{{ form.classifications.description }}</span>
                        {% endif %}
                          {{ form.classifications }}
                      </div>
                </div>
                <!-- Действия -->
                  <div class="form-actions">
                {% if story_edit %}
                    <button type="submit" class="btn btn-primary" name="act" value="save_story">Сохранить рассказ</button>
                {% else %}
                    <button type="submit" class="btn btn-primary" name="act" value="save_story">Добавить рассказ</button>
                {% endif %}
                  </div>

              </fieldset>

        </form>

        {% if story_edit %}
        {% if story.bl.can_edit_contributors(current_user) %}
            {%- include 'includes/story_edit_contributors_form.html' with context %}
        {% endif %}

        <form method="POST" enctype="multipart/form-data" class="form-horizontal">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
              <fieldset>
                      <legend>Главы</legend>
                      <div class="control-group">
                        <div class="controls events">
                            <ul id="sortable_chapters" class="chapters-control" data-story="{{ story.id }}">
                                {% for chapter in chapters %}
                                      <li id="chapter_{{ chapter.id }}" data-chapter="{{ chapter.id }}" class="btn btn-large">
                                        {{ chapter.autotitle }}
                                        <div class="btn-group">
                                            <a class="btn btn-mini js-btn-publish-chapter{% if chapter.draft %} btn-primary{% endif %}" href="{{ url_for('chapter.publish', pk=chapter.id) }}">
                                                {{ 'опубликовать' if chapter.draft else 'в черновики' }}
                                            </a>
                                            <a class="btn btn-warning btn-mini" href="{{ url_for('chapter.edit', pk=chapter.id) }}">править</a>
                                            <a class="btn btn-danger btn-mini chapter_delete" href="{{ url_for('chapter.delete', pk=chapter.id) }}">удалить</a>
                                        </div>
                                    </li>
                                {% endfor %}
                            </ul>
                            <a href="{{ url_for('chapter.add', story_id=story.id) }}" class="btn btn-success">Добавить главу</a>
                        </div>
                    </div>
              </fieldset>
        {% endif %}
        </form>
      </div>

    <div class="span12">
        {{- breadcrumbs([[url_for('author.info'), 'Кабинет автора']]) }}
      </div>
</div>
{% endblock %}
