<style>
    body {
        margin-top: 0 !important;
    }
</style>
<%include("/common/_head.html"){}%>
<link href="${ctxPath}/quill/quill.snow.css" rel="stylesheet">
<%
var user = c.currentUser(request, servlet.response);
var isLogin = false;
if(user != null){
isLogin=true;
}
%>
<div class=" fly-marginTop ">
    <div class="c-panel fly-panel-user detail-box">
        <div class="layui-row layui-col-space20">
            <div class="layui-col-md12">
                <table class="layui-hide" id="themeManage" lay-filter="theme"></table>
                <script type="text/html" id="bar">
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
                </script>
                <script type="text/html" id="headToolbar">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
                    </div>
                </script>
            </div>
        </div>
    </div>
</div>
<%include("/common/_scripts.html",{user:user}){}%>
<script src="${ctxPath}/quill/quill.min.js"></script>
<script>
    var moduleName = 'theme';
    layui.use(['table', 'fly', 'form'], function () {
        var table = layui.table
            , fly = layui.fly, form = layui.form, device = layui.device();
        table.render({
            elem: '#' + moduleName + 'Manage'
            , url: '/' + moduleName + '/list'
            , toolbar: '#headToolbar'
            , title: '友链数据表'
            , totalRow: true
            , cols: [[
                {field: 'id', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true},
                {field: 'title', title: '标题', width: 100, fixed: 'left', unresize: true, sort: true},
                {field: 'status', title: '状态', width: 100, fixed: 'left', unresize: true, sort: true},
                {field: 'userId', title: '用户id', width: 100, fixed: 'left', unresize: true, sort: true},
                {field: 'createTime', title: '创建时间', width: 160, fixed: 'left', unresize: false, sort: true},
                {fixed: 'right', width: 150, align: 'center', toolbar: '#bar'}
            ]]
            , page: true
            , response: {
                statusCode: '0000',
                msgName: 'message'
            }
            , id: moduleName + 'Reload'
            , parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.list
                };
            }
        });
        table.on('toolbar(' + moduleName + ')', function (obj) {
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 1
                        , id: 'fq_' + moduleName
                        , title: '新增更新日志'
                        , area: [($(window).width() + 'px'), ($(window).height() + 'px')]
                        , content: ['<ul class="layui-form" style="margin: 20px;">'
                            , '<li class="layui-form-item">'
                            , '<label class="layui-form-label">标题名称</label>'
                            , '<div class="layui-input-block">'
                            , '<input required name="title" lay-verify="required" placeholder="标题名称"  class="layui-input" maxlength="50">'
                            , '</div>'
                            , '</li>'
                            , '<li class="layui-form-item">'
                            , '<label class="layui-form-label">更新日志内容</label>'
                            , '<div class="layui-input-block">'
                            , '<div id="fq-editor"></div>'
                            , '</div>'
                            , '</li>'
                            , '<li class="layui-form-item">'
                            , '<div class="layui-input-block">'
                            , '<button type="button" lay-submit lay-filter="' + moduleName + '" class="layui-btn">保存</button>'
                            , '</div>'
                            , '</li>'
                            , '</ul>'].join('')
                        , success: function (layero, index) {
                            var quill = new Quill('#fq-editor', {
                                placeholder: '请开始奋笔疾书吧',
                                theme: 'snow'
                            });
                            form.on('submit(' + moduleName + ')', function (data) {
                                data.field.content = quill.container.firstChild.innerHTML;
                                fly.json('/' + moduleName + '/save', data.field, function (res) {
                                    layer.close(index);
                                    layer.msg('保存成功！', {
                                        icon: 1
                                    })
                                    table.reload(moduleName + 'Reload', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                });
                                return false;
                            })
                        }
                    });
                    break;
            }
            ;
        });
        table.on('tool(' + moduleName + ')', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除这个帖子么', function (index) {
                    fly.json('/' + moduleName + '/delete/' + data.id, {}, function (res) {
                        layer.msg('删除成功！');
                        table.reload(moduleName + 'Reload', {
                            page: {
                                curr: 1
                            }
                        });
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 1
                    , id: 'fq_' + moduleName
                    , title: '编辑帖子'
                    , area: (device.ios || device.android) ? ($(window).width() + 'px') : '660px'
                    , content: ['<ul class="layui-form" style="margin: 20px;">'
                        , '<li class="layui-form-item">'
                        , '<label class="layui-form-label">标题</label>'
                        , '<div class="layui-input-block">'
                        , '<input required name="title" lay-verify="required" placeholder="标题" value="' + data.title + '" class="layui-input">'
                        , '<input type="hidden" name="id" value="' + data.id + '">'
                        , '</div>'
                        , '</li>'
                        , '<li class="layui-form-item">'
                        , '<label class="layui-form-label">状态</label>'
                        , '<div class="layui-input-block">'
                        , '<input required name="status" placeholder="状态" value="' + data.status + '" class="layui-input">'
                        , '</div>'
                        , '</li>'
                        , '<li class="layui-form-item">'
                        , '<div class="layui-input-block">'
                        , '<button type="button" lay-submit lay-filter="' + moduleName + '" class="layui-btn">保存</button>'
                        , '</div>'
                        , '</li>'
                        , '</ul>'].join('')
                    , success: function (layero, index) {
                        form.on('submit(' + moduleName + ')', function (data) {
                            fly.json('/' + moduleName + '/pubTheme', data.field, function (res) {
                                layer.close(index);
                                layer.msg('保存成功！', {
                                    icon: 1
                                })
                                table.reload(moduleName + 'Reload', {
                                    page: {
                                        curr: 1
                                    }
                                });
                            });
                            return false;
                        })
                    }
                });
            }
        });
    });
</script>
</html>