<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="fragment :: head(~{::title})">
    <title>发布帖子</title>
</head>

<body>

<!--导航-->
<nav th:replace="fragment :: menu(1)"></nav>

</nav>

<  <!--中间内容-->
<div  class="m-container m-padded-tb-big">
    <div class="ui container">
        <form id="forum-form" action="#" th:object="${forum}" th:action="@{/add}" method="post" class="ui form">
<!--            <input type="hidden" name="published" th:value="*{published}">  &lt;!&ndash;发布状态&ndash;&gt;-->
            <!--        <input type="hidden" name="id" th:value="*{id}">-->
            <div class="required field">
                <div class="ui left labeled input">
                    <div class="ui selection compact teal basic dropdown label">
                        <input type="hidden" value="原创" name="flag" th:value="*{flag}" >
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" placeholder="请输入标题" th:value="*{title}">
                </div>
            </div>
            <div class="required field">  <!--required表示必须要填-->
                <div class="ui left labeled input">
                    <label class="ui teal basic label">描述</label>
                    <input type="text" name="description" th:value="*{description}" placeholder="请对帖子就进行简单描述！">
                </div>
            </div>
            <!--        <div class="required field">-->
            <!--          <label class="ui compact teal basic label">描述</label>-->
            <!--          <div id="md-description" style="z-index: 1 !important;">-->
            <!--            <textarea name="description" th:text="*{description}" placeholder="帖子描述..." maxlength="300"></textarea>-->
            <!--          </div>-->
            <!--        </div>-->


            <div class=" field">
                <div class="ui left labeled action input">
                    <label class="ui compact teal basic label">模块</label>
                    <div class="ui fluid selection   dropdown">
                        <input type="hidden" name="tagIds" th:value="*{tagIds}" >
                        <i class="dropdown icon"></i>
                        <div class="default text">请输入模块</div>
                        <div class="menu">
                            <div th:each="tag : ${tags}" class="item" data-value="1" th:data-value="${tag.id}" th:text="${tag.name}">java</div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="required field">  <!--required表示必须要填-->
                <div class="ui left labeled input">
                    <label class="ui teal basic label">图片</label>
                    <input type="text" name="avatars" th:value="*{avatars}" placeholder="请输入图片地址">
                </div>
            </div>

            <div class="required field">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea name="content" th:utext="*{content}"  placeholder="请输入帖子内容..." maxlength="300"></textarea>
                </div>
            </div>




            <div class="inline fields">

                <div class="ui error message"></div>
                <div class="ui right aligned container">
                    <button type="button" id="publish-btn" class="ui teal button" style="background-color: #347382">发布</button>
                </div>
            </div>

        </form>
    </div>
</div>

<br>
<br>
<!--底部footer-->
<footer th:replace="fragment :: footer"></footer>

</footer>


<script>

    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            // path    : "/gues/forum/lib/editormd/lib/"
            path    : "/lib/editormd/lib/"
        });
    });

    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on : 'hover'
    });

    $('#save-btn').click(function () {     //点击保存，修改发布状态为false
        $('[name="published"]').val(false);
        $('#forum-form').submit();
    });


    $('#publish-btn').click(function () {   //点击发布，修改发布状态为true
        $('[name="published"]').val(true);
        $('#forum-form').submit();
    });



    $('.ui.form').form({    //表单元素非空验证
        fields : {
            title : {
                identifier: 'title',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入帖子标题'
                }]
            },
            content : {
                identifier: 'content',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入帖子内容'
                }]
            },
            avatars                                                                          : {
                identifier: 'avatars                                                                         ',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入帖子首图'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入帖子描述'
                }]
            }
        }
    });

</script>
</body>
</html>
