{% extends 'base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}

{% block title %}Manage Posts{% endblock %}

{% block content %}
<div class="page-header">
    <h1>文章
        <small class="text-muted">{{ pagination.total }}篇</small>
        <span class="float-right"><a class="btn btn-primary btn-sm"
                                     href="{{ url_for('.new_post') }}">新文章</a></span>
    </h1>
</div>
{% if posts %}
<table class="table table-striped">
    <thead>
    <tr>
        <th>次序</th>
        <th>标题</th>
        <th>分类</th>
        <th>日期</th>
        <th>评论数</th>
        <th>字数</th>
        <th>操作</th>
    </tr>
    </thead>
    {% for post in posts %}
    <tr>
        <td>{{ loop.index + ((page - 1) * config.BLUELOG_MANAGE_POST_PER_PAGE) }}</td>
        <td><a href="{{ url_for('blog.show_post', post_id=post.id) }}">{{ post.title }}</a></td>
        <td><a href="{{ url_for('blog.show_category', category_id=post.category.id) }}">{{ post.category.name }}</a>
        </td>
        <td>{{ moment(post.timestamp).format('LL') }}</td>
        <td><a href="{{ url_for('blog.show_post', post_id=post.id) }}#comments">{{ post.comments|length }}</a></td>
        <td>{{ post.body|striptags|length }}</td>
        <td>
            <form class="inline" method="post"
                  action="{{ url_for('.set_comment', post_id=post.id, next=request.full_path) }}">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                <button type="submit" class="btn btn-outline-warning btn-sm">
                    {% if post.can_comment %}不可{% else %}可{% endif %} 评论
                </button>
            </form>
            <a class="btn btn-outline-primary btn-sm" href="{{ url_for('.edit_post', post_id=post.id) }}">编辑</a>
            <form class="inline" method="post"
                  action="{{ url_for('.delete_post', post_id=post.id, next=request.full_path) }}">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                <button type="submit" class="btn btn-outline-danger btn-sm" onclick="return confirm('Are you sure?');">删除
                </button>
            </form>
        </td>
    </tr>
    {% endfor %}
</table>
<div class="page-footer">{{ render_pagination(pagination) }}</div>
{% else %}
<div class="tip"><h5>没有文章</h5></div>
{% endif %}
{% endblock %}