<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>论坛-Quinn</title>
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/wangedit/css/wang.style.css}"/>
    <link rel="stylesheet" th:href="@{/css/backgroud.css}">
    <style>
        .nav-underline .nav-link {
            padding-top: .75rem;
            padding-bottom: .75rem;
            font-size: .875rem;
            color: #6c757d;
        }
    </style>
</head>
<body>

<!-- 导航栏 -->
<div th:replace="~{common/header::header(activeUrl='blog')}"></div>

<main role="main" class="container mt-3 p-3 bg-white rounded">
    <div class="row">
        <div class="col-md-12 blog-main">
            <div class="col-md-12 order-md-1">
                <h4 class="mb-3">发布文章</h4>

                <form id="editForm" class="needs-validation" th:action="@{/blog/write}" method="post">
                    <!-- 隐藏域 -->
                    <input type="hidden" name="authorId" th:value="${session.loginUser.getUid()}">
                    <input type="hidden" name="authorName" th:value="${session.loginUser.getUsername()}">
                    <div class="row">
                        <div class="col-md-10 mb-3">
                            <label for="title">文章标题</label>
                            <input type="text" name="title" maxlength="30" class="form-control" id="title" placeholder="请输入标题" required>
                        </div>

                        <div class="col-md-2 mb-3">
                            <label for="categoryId">权限</label>
                            <select name="categoryId" class="custom-select d-block w-100" id="categoryId" required>
                                <option th:each="category:${categoryList}"
                                        th:value="${category.getId()}" th:text="${category.getCategory()}">
                                </option>
                            </select>
                        </div>

                        <div class="col-md-12 mb-3">
                            <p>文章内容</p>
                            <div id="blog-content">
								<div id="editor-toolbar"></div>
								<div id="editor-text-area" style="height: 600px;border: 1px solid lightgrey"></div>
								<textarea id="content-textarea" name="content" style="display: none;"></textarea>
								<textarea id="contentText-textarea" name="contentJson" style="display: none;"></textarea>
                            </div>
                        </div>

                    </div>

                    <button class="btn btn-primary btn-lg btn-block" type="button" onclick="talkWith()" >发布文章</button>
                </form>
            </div>
        </div>
    </div>
</main>
<div th:replace="~{common/footer::footer}"></div>

<a class="to-top badge badge-light">返回顶部</a>
<script th:src="@{/js/jquery-3.5.1.min.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap.bundle.min.js}"></script>
<script th:src="@{/js/toTop.js}"></script>
<script th:src="@{/js/jquery-ui.min.js}"></script>
<script th:src="@{/live/js/addlive2d.js}"></script>

<script th:src="@{/wangedit/js/wang.min.js}"></script>
<script th:src="@{/wangedit/js/wang.init.js}"></script>
<script th:src="@{/layer/mobile/layer.js}"></script>
<script type="text/javascript">
    function talkWith(){
        var title = $('#title').val();
        var content = $('#content-textarea').val();
        var categoryId = $('#categoryId').val();
        if (!title){
            layer.open({ content: '请输入标题', skin: 'msg', time: 2 });
            return;
        }
        if(title.length>30){
            layer.open({ content: '标题过长', skin: 'msg', time: 2 });
            return;
        }
        if (!categoryId){
            layer.open({ content: '请选择博客分类', skin: 'msg', time: 2 });
            return;
        }
        console.log(content.length < 30);
        if (content.length < 30){
            layer.open({ content: '内容过短!请多表达一点思想吧?', skin: 'msg', time: 2 });
            return;
        }
        this.disabled = true;
        $('#editForm').submit();
    }
</script>
</body>
</html>
