{% extends base %}

{% block body %}
    {% init file_type = "group_list" %}
    {% init ungrouped_count = 0 %}
    {% init tools = [] %}
    {% init fixed_books = [] %}

    <div class="grid-row card book-list hidden">
        <h3 class="card-title">{{T("常用")}}
            <div class="float-right">
                <a class="inline-btn add-group-btn">+分组</a>
                <a class="inline-btn" href="{{_server_home}}/note/add">+笔记</a>
            </div>
        </h3>

        {% for item in tools %}
            <a href="{{_server_home}}{{item.url}}" class="fixed-book">
                <div class="book-item fixed-book-item">
                    <i class="fa {{item.icon}} orange"></i>
                    {% if item.priority > 0 %}
                        <i class="fa fa-thumb-tack black"></i>
                    {% end %}

                    {{item.name}}
                    {% if item.size != None %}<span class="black">({{item.size}})</span>{% end %}
                    <span class="book-size">
                        <i class="fa fa-chevron-right"></i>
                    </span>
                </div>
            </a>
        {% end %}
    </div>

    {% if len(fixed_books) > 0 %}
        <div class="grid-row card book-list">
            <h3 class="card-title">{{T("置顶")}}
                <div class="float-right">
                    <a class="inline-btn add-group-btn">+分组</a>
                    <a class="inline-btn" href="{{_server_home}}/note/add">+笔记</a>
                </div>
            </h3>

            {% for item in fixed_books %}
                <a href="{{_server_home}}{{item.url}}">
                <div class="book-item">
                    {% if item.type == "system" %}
                        <i class="icon-folder-system"></i>
                    {% else %}
                        <i class="fa fa-folder orange"></i>
                    {% end %}

                    {% if item.priority > 0 %}
                        <i class="fa fa-thumb-tack black"></i>
                    {% end %}
                    
                    <span>{{item.name}}</span>
                    {% if item.size!=None %}
                        <span class="black">({{item.size}})</span>
                    {% end %}
                    <span class="book-size">{{format_date(item.mtime).replace('-', '/')}}</span>
                </div>
                </a>
            {% end %}
        </div>
    {% end %}

    {% if len(files) > 0 %}
        <div class="grid-row card book-list">
            <h3 class="card-title">{{T("分组")}}</h3>
            {% for item in files %}
                <a href="{{_server_home}}{{item.url}}">
                <div class="book-item">
                    {% if item.type == "system" %}
                        <i class="icon-folder-system"></i>
                    {% else %}
                        <i class="fa fa-folder orange"></i>
                    {% end %}

                    {% if item.priority > 0 %}
                        <i class="fa fa-thumb-tack black"></i>
                    {% end %}
                    
                    <span>{{item.name}}</span>
                    <span class="black">({{item.size}})</span>
                    <span class="book-size">{{format_date(item.mtime).replace('-', '/')}}</span>
                </div>
                </a>
            {% end %}
        </div>
    {% end %}

<script type="text/javascript">
    $(function () {
        $(".add-group-btn").click(function () {
            xnote.prompt("新建分组", "", function (newValue) {
                $.post("/note/add", {type:"group", name:newValue, _format: "json"}, function (resp) {
                    var code = resp.code;
                    if (code != "success") {
                        alert("创建笔记本失败:" + resp.message);
                    } else {
                        window.location.reload();
                    }
                }).fail(function (e) {
                    alert("创建笔记失败:" + e);
                })
            })
        })
    })
</script>

{% end %}

{% block aside %}
    {% include note/component/mod_aside.html %}
{% end %}
