<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: njc
  Date: 2022/5/8
  Time: 18:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<script type="text/javascript">
    /**
     * 发布博客
     */
    function submitData() {
        var title = $("#title").val();
        var blogTypeId = $("#blogTypeId").combobox("getValue");
        var content = UE.getEditor('editor').getContent();
        var keyWord = $("#keyWord").val();
        if (title == null || title === '') {
            $.messager.alert("系统提示", "请输入标题！");
        } else if (blogTypeId == null || blogTypeId === '') {
            $.messager.alert("系统提示", "请输入内容！")
        } else if (content == null || content === '') {
            $.messager.alert("系统提示", "请输入内容！");
        } else {
            $.post("${pageContext.request.contextPath}/admin/blog/save.do", {
                'id': '${param.id}',
                'title': title,
                'blogType.id': blogTypeId,
                'content': content,
                'summary': UE.getEditor('editor').getContentTxt().substr(0, 155),
                'keyWord': keyWord
            }, function (result) {
                if (result.success) {
                    $.messager.alert("系统提示", "博客发布成功！");
                } else {
                    $.messager.alert("系统提示", "博客发布失败！");
                }
            }, "json");
        }
    }
</script>
<div id="p" class="easyui-panel" title="修改博客" style="padding: 10px">
    <table cellspacing="20px">
        <tr>
            <td width="80px">博客标题</td>
            <td><input type="text" id="title" name="title" style="width: 400px;"/></td>
        </tr>
        <tr>
            <td>所属类别：</td>
            <td>
                <select class="easyui-combobox" id="blogTypeId" name="blogType.id" style="width: 154px;"
                        editable="false" panelHeight="auto">
                    <option value="">请选择博客类别...</option>
                    <c:forEach var="blogType" items="${blogTypeCountList}">
                        <option value="${blogType.id}">${blogType.typeName}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td>博客内容：</td>
            <td>
                <script id="editor" type="text/plain" style="width: 100%;height: 500px;"></script>
            </td>
        </tr>
        <tr>
            <td>关键字：</td>
            <td><input type="text" id="keyWord" name="keyWord" style="width: 400px;"/></td>
        </tr>
        <tr>
            <td></td>
            <td><a href="javascript:submitData()" class="easyui-lunkbutton"
                   data-options="iconCls:'icon-submit'">提交修改</a></td>
        </tr>
    </table>
</div>

<script type="text/javascript">
    // 实例化编辑器
    var ue = UE.getEditor("editor");
    ue.addListener("ready", function () {
        // 通过ajax请求数据
        UE.ajax.request("${pageContext.request.contextPath}/admin/blog/findById.do",
            {
                method: "post",
                asyc: false,
                data: {"id": "${param.id}"},
                onsuccess: function (result) {
                    result = eval("(" + result.responseText + ")");
                    $("#title").val(result.title);
                    $("#keyWord").val(result.keyWord);
                    $("#blogTypeId").combobox("setValue", result.blogType.id);
                    UE.getEditor("editor").setContent(result.content);
                }
            }
        );
    });
</script>