{% extends 'IMDCTerpTubeBundle:Base:base.html.twig' %}

{% block title %}Edit Forum{% endblock %}

{% block header %}
    {{ parent() }}

    <script type="text/javascript">
        require([
            'bootstrap',
            'model/forumModel', 'controller/forumController', 'views/forum/editView',
            'main'
        ], function(bootstrap, ForumModel, ForumController, ForumView) {
            bootstrap(
                    new ForumModel({{ forum|serialize('json')|raw }}),
                    ForumController,
                    ForumView,
                    {
                        container: $('body')
                    }
            );
        });
    </script>
{% endblock header %}

{% block sidebarlinks_forums %}class="active"{% endblock %}

{% block content %}
    <div class="col-md-offset-2 col-md-8">
        <div class="row">
            <div class="col-md-12">
                <img class="img-responsive center-block" src="" />
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                {{ form_start(form) }}
                {{ form_errors(form) }}
                {{ form_widget(form.titleMedia) }}
                {{ form_row(form.titleText) }}
                {{ form_row(form.description) }}
                {{ form_row(form.accessType) }}
                {% if form.group is defined %}
                    {{ form_row(form.group) }}
                {% endif %}
                <div class="row">
                    <div class="col-md-6">
                        <button class="btn btn-success forum-submit" data-loading-text="<i class=&quot;fa fa-spinner fa-spin&quot;></i> Saving..."><i class="fa fa-check"></i> Save</button>
                        <a class="btn btn-default" onclick="history.back();"><i class="fa fa-times"></i> Cancel</a>
                    </div>
                    <div class="col-md-6 text-right">
                        <a class="btn btn-danger" data-toggle="modal" data-target=".forum-delete-modal"><i class="fa fa-trash-o"></i> Delete this forum</a>
                        <div class="modal fade forum-delete-modal">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                        <h4 class="modal-title">Delete this forum</h4>
                                    </div>
                                    <div class="modal-body text-center">
                                        {% set postCount = 0 %}
                                        {% for thread in forum.getThreads %}
                                            {% set postCount = postCount + thread.getPosts|length %}
                                        {% endfor %}
                                        <div class="alert alert-info" role="alert">
                                            This forum contains <span class="badge">{{ forum.getThreads|length }}</span> topic{% if forum.getThreads|length != 1 %}s{% endif %} with a total of <span class="badge">{{ postCount }}</span> post{% if postCount != 1 %}s{% endif %}.<br />
                                        </div>
                                        <p>
                                            Are you sure you want to delete this forum?<br />
                                            Deleting this forum will delete <strong>all</strong> topics and <strong>all</strong> posts!<br />
                                            This action <strong>cannot</strong> be undone!
                                        </p>
                                    </div>
                                    <div class="modal-footer">
                                        <a class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Cancel</a>
                                        <a class="btn btn-danger forum-delete" data-loading-text="<i class=&quot;fa fa-spinner fa-spin&quot;></i> Deleting..."><i class="fa fa-trash-o"></i> Delete</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                {{ form_end(form) }}
            </div>
        </div>
    </div>
{% endblock %}
