#@layout()
#define script()
<script>

    function trash(id) {
        ajaxGet("#(CPATH)/admin/article/doTrash/" + id);
    }


    function draft(id) {
        ajaxGet("#(CPATH)/admin/article/doDraft/" + id);
    }

    function normal(id) {
        ajaxGet("#(CPATH)/admin/article/doNormal/" + id);
    }

    function del(id) {
        if (confirm('确定要删除该文章吗？删除后不可恢复')) {
            ajaxGet("#(CPATH)/admin/article/doDel/" + id);
        }
    }

    $("#batchDel").click(function () {
        var ids = getSelectedIds();
        if (ids == "") {
            alert('您未选择任何内容');
            return
        }
        if (confirm('确定要删除该文章吗？删除后不可恢复')) {
            ajaxGet("#(CPATH)/admin/article/doDelByIds?ids=" + ids);
        }
    })
</script>

#end

#define content()
<div class="content-wrapper">

    <section class="content-header">
        <h1>
            文章管理
            <small>Article Management</small>
        </h1>
    </section>

    <section class="content-header text-tap">
        <a href="#(CPATH)/admin/article">全部 (#(totalCount ?? 0))</a> |
        <a href="?status=normal">已发布 (#(normalCount ?? 0))</a> |
        <a href="?status=draft">草稿 (#(draftCount ?? 0))</a> |
        <a href="?status=trash" style="color: #a00">垃圾箱 (#(trashCount ?? 0))</a>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-xs-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <form class="form-horizontal actionPanel" action="#(CPATH)/admin/article" method="get">
                            <input type="hidden" name="status" value="#para('status')">
                            <div class="row">
                                <div class="form-group col-lg-4">
                                    <label class="col-sm-3 control-label">标题</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="title" value="#para('title')">
                                    </div>
                                </div>
                                <div class="form-group col-lg-4">
                                    <label class="col-sm-3 control-label">分类</label>
                                    <div class="col-sm-9">
                                        <select class="form-control" name="categoryId">
                                            <option value="">全部分类</option>
                                            #for(category : categories)
                                            <option value="#(category.id ??)" #selectedIf(category.isCheck)>
                                                #(category.layerString)#(category.title ??)
                                            </option>
                                            #end
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group col-lg-4">
                                    <div class="col-sm-12">
                                        <button type="submit" class="btn btn-primary ">查询</button>
                                        <button type="reset" class="btn btn-default">重置</button>
                                        <a class="btn"> 更多<i class="fa fa-fw fa-angle-down"></i> </a>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-body -->
                        </form>

                        <div class="row actionPanel">
                            <div class="col-xs-12">
                                <a href="#(CPATH)/admin/article/write" class="btn btn-primary "> <i
                                        class="fa fa-fw fa-plus"></i> 新建</a>
                                <button type="button" id="batchDel" class="btn btn-default checkAction"> 批量删除</button>
                            </div>
                        </div>

                    </div>
                    <!-- /.box-header -->
                    <div class="box-body ">

                        <table class="table table-striped">
                            <tbody>
                            <tr>
                                <th style="width: 10px">
                                    <input name="dataItem" onchange="checkAll(this)" type="checkbox" value="0"/>
                                </th>
                                <th style="width: 350px">标题</th>
                                <th style="width: 50px">作者</th>
                                <th>分类</th>
                                <th>标签</th>
                                <th style="width: 50px"><i class="fa fa-commenting"></i></th>
                                <th style="width: 90px">发布时间</th>
                            </tr>

                            #for(article : page.list)
                            <tr class="jp-actiontr">
                                <td><input class="dataItem" type="checkbox" value="#(article.id)"/>
                                </td>
                                <td>
                                    <strong>
                                        <a href="#(CPATH)/admin/article/write/#(article.id)">#(article.title ??)</a>
                                        #if(article.isDraft())
                                        （草稿）
                                        #end
                                    </strong>
                                    <div class="jp-actionblock">
                                        #if(article.isNormal())
                                        <div class="jp-actionitem">
                                            <a href="#(CPATH)/admin/article/write/#(article.id)">编辑</a> |
                                            <a href="javascript:;" onclick="draft('#(article.id??)')">草稿</a>
                                            |
                                            <a href="javascript:;" onclick="trash('#(article.id??)')"
                                               class="red-action">垃圾箱</a> |
                                            <a href="#(article.url ??)" target="_blank" class="red-action">查看</a>
                                        </div>
                                        #elseif(article.isDraft())
                                        <div class="jp-actionitem">
                                            <a href="#(CPATH)/admin/article/write/#(article.id)">编辑</a> |
                                            <a href="javascript:;" onclick="trash('#(article.id??)')"
                                               class="red-action">垃圾箱</a>
                                        </div>
                                        #else
                                        <div class="jp-actionitem">
                                            <a href="javascript:;" onclick="draft('#(article.id??)')">还原</a>
                                            |
                                            <a href="javascript:;" onclick="del('#(article.id??)')" class="red-action">永久删除</a>
                                        </div>
                                        #end
                                    </div>

                                </td>
                                <td>
                                    <a href="#(article.user.detailUrl ??)">
                                        #(article.user.nickname ??)
                                    </a>
                                </td>
                                <td>
                                    #articleCategories(article.id,"category")
                                    #for(category : categories)
                                    <a href="#(category.url ??)" target="_blank">#(category.title ??)</a>
                                    #if(!for.last) , #end
                                    #end
                                    #end
                                </td>
                                <td>
                                    #articleCategories(article.id,"tag")
                                    #for(category : categories)
                                    <a href="#(category.url ??)" target="_blank">#(category.title ??)</a>
                                    #if(!for.last) , #end
                                    #end
                                    #end
                                </td>
                                <td>
                                    <a href="#(CPATH)/admin/article/comment?articleId=#(article.id)">
                                    #(article.comment_count ??)
                                    </a>
                                </td>
                                <td>#date(article.created)</td>
                            </tr>
                            #end

                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <div class="row">
                            <div class="col-sm-12">
                                #@_paginate()
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.box -->
            </div>
        </div>

    </section>


</div>
#end
