<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: njc
  Date: 2022/5/9
  Time: 11:24
  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" %>
<body>
<script type="text/javascript">
    /**
     * 提交博主信息
     */
    function submitData() {
        var nickName = $("#nickName").val();
        var sign = $("#sign").val();
        var proFile = UE.getEditor("editor").getContent();
        console.log(proFile);
        if (nickName == null || nickName === "") {
            $.messager.alert("系统提示", "请输入昵称！");
        } else if (sign == null || sign === "") {
            $.messager.alert("系统提示", "请输入个性签名！");
        } else if (proFile == null || proFile === "") {
            $.messager.alert("系统提示", "请输入简介！");
        } else {
            $("#profile").val(proFile);
            $("#form1").submit();
        }
    }
</script>
<div id="p" class="easyui-panel" title="修改个人信息" style="padding: 10px">
    <form id="form1" action="${pageContext.request.contextPath}/admin/blogger/save.do" method="post"
          enctype="multipart/form-data">
        <input type="hidden" id="id" name="id" value="${currentUser.id}"/>
        <input type="hidden" id="profile" name="profile"/>
        <table cellspacing="20px">
            <tr>
                <td width="80px">用户名:</td>
                <td><input type="text" id="title" name="title" style="width: 200px;" value="${currentUser.userName}"
                           readonly="readonly"/></td>
            </tr>
            <tr>
                <td>昵称:</td>
                <td><input type="text" id="nickName" name="nickName" style="width: 200px;"
                           value="${currentUser.nickName}"/></td>
            </tr>
            <tr>
                <td>个性签名:</td>
                <td><input type="text" id="sign" name="sign" style="width: 400px;" value="${currentUser.sign}"/></td>
            </tr>
            <tr>
                <td>个人头像:</td>
                <td><input type="file" id="imageFile" name="imageFile" style="width: 400px;"/></td>
            </tr>
            <tr>
                <td>个人简介:</td>
                <td>
                    <script id="editor" type="text/plain" style="width: 100%;height: 500px;"></script>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><a href="javascript:submitData()" class="easyui-linkbutton"
                       data-options="iconCls:'icon-submit'">确认修改</a></td>
            </tr>
        </table>
    </form>
</div>

<script type="text/javascript">
    // 实例化编辑器
    var ue = UE.getEditor("editor");
    ue.addListener("ready", function () {
        // 通过axaj获取数据
        UE.ajax.request("${pageContext.request.contextPath}/admin/blogger/find.do",
            {
                method: "post",
                async: false,
                data: {},
                onsuccess: function (result) {
                    result = eval("(" + result.responseText + ")");
                    UE.getEditor("editor").setContent(result.profile);
                }
            }
        );
    });
</script>
</body>
