{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% set active_menu = 'support' %}
{% block meta_title %}News{% endblock %}

{% block content %}
<div class="widget simpleTabs nomargin">

    <ul class="tabs">
        <li><a href="#tab-index">{% trans 'News and announcements' %}</a></li>
        <li><a href="#tab-new">{% trans 'New announcement' %}</a></li>
    </ul>

    <div class="tabs_container">

        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-index">

        {{ mf.table_search }}
        <table class="tableStatic wide">
            <thead>
                <tr>
                    <td colspan="2">{% trans 'Title' %}</td>
                    <td>{% trans 'Active' %}</td>
                    <td>{% trans 'Date' %}</td>
                    <td style="width: 13%">&nbsp;</td>
                </tr>
            </thead>

            <tbody>
            {% set posts = admin.news_get_list({"per_page":30, "page":request.page}|merge(request)) %}
            {% for i, post in posts.list %}
            <tr>
                <td>{{ post.id }}</td>
                <td>{{ post.title }}</td>
                <td>{{ mf.status_name(post.status) }}</td>
                <td>{{ post.created_at|date('Y-m-d') }}</td>
                <td class="actions">
                    <a class="bb-button btn14" href="{{ '/news/post'|alink }}/{{post.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                    <a class="bb-button btn14 bb-rm-tr api-link" data-api-confirm="Are you sure?" href="admin/news/delete?id={{post.id}}" data-api-redirect="news"><img src="images/icons/dark/trash.png" alt=""></a>
                </td>
            </tr>
            </tbody>

            {% else %}
            <tbody>
                <tr>
                    <td colspan="5">
                        {% trans 'The list is empty' %}
                    </td>
                </tr>
            </tbody>
            {% endfor %}

            {% if posts.pages > 1 %}
            <tfoot>
                <tr>
                    <td colspan="5">
                        {% include "partial_pagination.phtml" with {'list': posts, 'url':'news/index'} %}
                    </td>
                </tr>
            </tfoot>
            {% endif %}
        </table>
        </div>

        <div class="tab_content nopadding" id="tab-new">

            <form method="post" action="admin/news/create" class="mainForm api-form" data-api-redirect="news">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Status' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="status" value="draft"checked="checked"/><label>{% trans 'Draft' %}</label>
                            <input type="radio" name="status" value="active"/><label>{% trans 'Active' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Content' %}</label>
                        <div class="formRight">
                            <textarea name="content" cols="5" rows="10">{{ request.content }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

    </div>
</div>

{% endblock %}
