{% extends 'base.html' %}
{% from 'bootstrap/form.html' import render_form %}

{% block title %}Manage Links{% endblock %}

{% block content %}
    <div class="page-header">
        <h1>链接
            <small class="text-muted">{{ links|length }}个</small>
            <span class="float-right">
                <a class="btn btn-primary btn-sm" href="{{ url_for('.new_link') }}">新链接</a>
            </span>
        </h1>
    </div>
    {% if links %}
        <table class="table table-striped">
            <thead>
            <tr>
                <th>次序</th>
                <th>名字</th>
                <th>网址</th>
                <th>操作</th>
            </tr>
            </thead>
            {% for link in links %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td>{{ link.name }}</td>
                    <td><a href="{{ link.url }}" target="_blank">{{ link.url }}</a></td>
                    <td>
                        <a class="btn btn-outline-info btn-sm" href="{{ url_for('.edit_link', link_id=link.id) }}">编辑</a>
                        <form class="inline" method="post" action="{{ url_for('.delete_link', link_id=link.id) }}">
                            <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>
    {% else %}
        <div class="tip"><h5>没有链接</h5></div>
    {% endif %}
{% endblock %}
