<!DOCTYPE html>
<html lang="zh-CN">
<head>
    {{template "widgets/head.html" .}}
</head>
<body>
<div class="manual-reader">
    {{template "widgets/header.html" .}}
    <div class="container manual-body">
        <div class="row">
            <div class="page-left">
                {{template "manager/menu.html" .}}
            </div>
            <div class="page-right">
                <div class="m-box">
                    <div class="box-head">
                        <strong class="box-title">附件管理</strong>
                    </div>
                </div>
                <div class="box-body">
                    <div class="attach-list" id="attachList">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>#</th>
                                <th>附件名称</th>
                                <th>书籍名称</th>
                                <th>文件大小</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {{range $index,$item := .Lists}}
                            <tr>
                                <td>{{$item.AttachmentId}}</td>
                                <td>
                                    {{if and (ne $item.BookIdentify "") (ne $item.DocIdentify "") }}
                                        <a href="{{urlfor "DocumentController.Read" ":key" $item.BookIdentify ":id" $item.DocIdentify}}" class="text-primary" target="_blank">{{$item.FileName}}</a>
                                    {{else}}
                                        {{$item.FileName}}
                                    {{end}}
                                </td>
                                <td>
                                    {{if ne $item.BookIdentify ""}}
                                        <a class="text-primary" href="{{urlfor "DocumentController.Index" ":key" $item.BookIdentify}}" target="_blank">{{$item.BookName}}</a>
                                    {{else}}
                                        {{$item.BookName}}
                                    {{end}}
                                </td>
                                <td>{{$item.FileShortSize}}</td>
                                <td>
                                    <a href="{{urlfor "ManagerController.AttachDelete"}}?attach_id={{$item.AttachmentId}}" class="btn btn-danger btn-sm ajax-get confirm">删除</a>
                                    <a href="{{urlfor "ManagerController.AttachDetailed" ":id" $item.AttachmentId}}" class="btn btn-success btn-sm">详情</a>
                                </td>
                            </tr>
                            {{else}}
                            <tr><td>暂无数据</td></tr>
                            {{end}}
                            </tbody>
                        </table>
                        <nav class="pagination-container">
                            {{.PageHtml}}
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


{{/*<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>*/}}
<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>
{{/*<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>*/}}
<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="{{$.StaticDomain}}/static/js/jquery.form.js" type="text/javascript"></script>
<script src="{{$.StaticDomain}}/static/layer/layer.js" type="text/javascript"></script>
<script src="{{$.StaticDomain}}/static/js/toast.script.js" type="text/javascript"></script>
<script src="/static/js/main.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $("#attachList").on("click","button[data-method='delete']",function () {
            var id = $(this).attr("data-id");
            var $this = $(this);
            $(this).button("loading");
            $.ajax({
                url : "{{urlfor "ManagerController.AttachDelete"}}",
                data : { "attach_id" : id },
                type : "post",
                dataType : "json",
                success : function (res) {
                    if(res.errcode === 0){
                        $this.closest("tr").remove().empty();
                    }else {
                        layer.msg(res.message);
                    }
                },
                error : function () {
                    layer.msg("服务器异常");
                },
                complete : function () {
                    $this.button("reset");
                }
            });
        });
    });
</script>
</body>
</html>