<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <title>修改服务器</title>
    <%--    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.css">--%>
    <link rel="stylesheet" href="${ctx}/css/plugin/metroStyle/metroStyle.css">
    <link rel="stylesheet" href="${ctx}/js/plugin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/css/plugin/datatables/buttons.dataTables.min.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrapSwitch/bootstrap-switch.min.css">
    <link rel="stylesheet" href="${ctx}/css/basic.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/iconfont/iconfont.css">
    <style>
        .td {
            text-align: center;
            height: 48px;
            line-height: 48px
        }

        #vdlist {
            width: 1720px;
            min-width: 1720px;
        }

        body {
            overflow: hidden;
        }

        .table > tbody > tr > td {
            padding: 3px;
            line-height: 1.42857143;
            vertical-align: top;
            border-top: 1px solid #ddd;
        }
    </style>
</head>
<body class="mbody pdt5 pdb5" style="text-align: center">
<div class="layui-form-item">
    <label style="width: 26%;">服务器名称:</label>
    <input type="text" id="serverName" placeholder="请输入名称"
           autocomplete="off" style="margin-top: 10px;height: 30px">
    <label style="width: 26%;">前置类型:</label>
    <select type="text" id="type"
            autocomplete="off" style="width:142px;margin-top: 10px;height: 30px"></select>
</div>
<div class="layui-form-item">
    <label style="width: 26%;margin-left: 13px">系统版本:</label>
    <select type="text" id="version"
            autocomplete="off" style="width:142px;margin-top: 10px;height: 30px"></select>
    <label style="width: 26%;">硬件信息:</label>
    <input type="text" id="hardware" placeholder="请输入硬件信息"
           autocomplete="off" style="margin-top: 10px;height: 30px">
</div>
<div class="layui-form-item">
    <label style="width: 26%;">用户名:</label>
    <input type="text" id="userName" placeholder="请输入用户名"
           autocomplete="off" style="margin-top: 10px;height: 30px">
    <label style="width: 26%;">密码:</label>
    <input type="password" id="password"
           autocomplete="off" style="margin-top: 10px;height: 30px">
</div>
<div class="layui-form-item" id="ok">
    <label style="width: 26%;" class="ml10">网络参数:</label>
    <input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')"
           onafterpaste="this.value=this.value.replace(/\D/g,'')" id="ipEnd1" autocomplete="off" maxlength="3"
           style="width: 13.5%;margin-top: 12px;height:30px;">.
    <input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')"
           onafterpaste="this.value=this.value.replace(/\D/g,'')" id="ipEnd2" maxlength="3" autocomplete="off"
           style="width: 13.5%; margin-top: 10px;height: 30px">.
    <input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')"
           onafterpaste="this.value=this.value.replace(/\D/g,'')" id="ipEnd3" autocomplete="off" maxlength="3"
           style="width:13.5%; margin-top: 10px;height: 30px">.
    <input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')"
           onafterpaste="this.value=this.value.replace(/\D/g,'')" id="ipEnd4" autocomplete="off" maxlength="3"
           style="width:13.5%; margin-top: 10px;height: 30px">
</div>
<div>
    <button type="button" class="layui-btn themeBGColor"
            id="updateServer"
            style="margin-top: 10px;">提交
    </button>
    <button type="reset" class="layui-btn cancleBGColor"
            style="margin-left: 10%; margin-top: 10px"
            id="close">取消
    </button>
</div>
</body>
<input type="hidden" id="middIndex">
<script src="${ctx}/js/plugin/jquery.min.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.core.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap.min.js"></script>
<script src="${ctx}/js/plugin/layui/layer.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/js/plugin/bootstrapSwitch/bootstrap-switch.min.js"></script>
<script src="${ctx}/js/basic.js"></script>
<script src="${ctx}/js/color.js"></script>
<script src="${ctx}/jspJS/utils/timeControl.js"></script>
<script src="${ctx}/js/plugin/xss/xss.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script>
    var sevIndex = parent.$("#sevIndex").val();
    $(document).ready(function () {
        //查询服务器的信息
        $.ajax({
            type: "POST",
            url: "/pqs9900/serverstate/selectServer",
            data: {
                sevIndex: sevIndex
            },
            success: function (data) {

                $("#serverName").val(data.name);
                $("#hardware").val(data.hardware);
                $.each(data.getSystemType, function (i, item) {
                    var option = $("<option value='" + item.dicIndex + "'>" + item.dicName + "</option>");
                    $("#version").append(option);
                })

                systemType = data.version;
                if (systemType === "") {
                    $("#version").val("");
                } else {
                    $("#version").val(systemType);
                }

                $.each(data.getType, function (i, item) {
                    var option = $("<option value='" + item.dicIndex + "'>" + item.dicName + "</option>");
                    $("#type").append(option);
                })

                type = data.type;
                if (type === "") {
                    $("#type").val("");
                } else {
                    $("#type").val(type);
                }
                $("#userName").val(data.userName);
                $("#password").val(data.password)
                var ipEnd = data.ip;
                ipEnd = ipEnd.split(".");
                $("#ipEnd1").val(ipEnd[0]);
                $("#ipEnd2").val(ipEnd[1]);
                $("#ipEnd3").val(ipEnd[2]);
                $("#ipEnd4").val(ipEnd[3]);
            }
        })
    })
    $("#updateServer").click(function () {
        var serverName = $("#serverName").val();
        serverName = serverName.replace(/(^\s*)|(\s*$)/g, '');
        serverName = filterXSS(serverName);
        var re = middNames;// 只能输入中文
        if (!re.test(serverName)) {
            layer.tips('名称格式错误', '#serverName', {
                tips: [1, 'red'], time: 2000
            });
            $("#serverName").val("");
        } else {
            var ipEnd1 = $("#ipEnd1").val();
            var ipEnd2 = $("#ipEnd2").val();
            var ipEnd3 = $("#ipEnd3").val();
            var ipEnd4 = $("#ipEnd4").val();
            var ipEnd = ipEnd1 + "." + ipEnd2 + "." + ipEnd3 + "." + ipEnd4;
            ipEnd = ipEnd.replace(/(^\s*)|(\s*$)/g, '');
            ipEnd = filterXSS(ipEnd);
            var re = ipz;
            if (!re.test(ipEnd)) {
                layer.tips('ip地址格式不正确', "#ipEnd4",
                    {tips: [2, 'red']});
                $("#ipEnd1").val("");
                $("#ipEnd2").val("");
                $("#ipEnd3").val("");
                $("#ipEnd4").val("");
            } else {
                var type = $("#type").val();
                var version = $("#version").val();
                var hardware = $("#hardware").val();
                var userName = $("#userName").val();
                var password = $("#password").val();
                $.ajax({
                    type: "POST",
                    url: "/pqs9900/serverstate/updateServer",
                    dataType: "text",
                    data: {
                        sevIndex:sevIndex,
                        serverName: serverName,
                        type:type,
                        version:version,
                        hardware:hardware,
                        userName:userName,
                        password:password,
                        ip: ipEnd
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg(info.message,
                                {
                                    icon: 6,
                                    time: 2000
                                }, function () {
                                    parent.layer.closeAll();
                                    parent.getTree();
                                    parent.getServerRunDetails();
                                });
                        } else {
                            layer.msg(info.message,
                                {
                                    icon: 5,
                                    time: 2000
                                }
                            );
                        }
                    }
                });
            }
        }
    })
    $("#close").click(function () {
        parent.layer.closeAll();
    })
</script>
</html>
