<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg" onload="initClient()">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-clientConfig-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">客户端：</label>
				<div class="col-sm-8">
					<select id="clientId" name="clientId" class="form-control m-b">
						<option></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">客户端配置名称：</label>
				<div class="col-sm-8">
					<input id="configKey" name="configKey" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">客户端配置值：</label>
				<div class="col-sm-8">
					<input id="configValue" name="configValue" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/clientConfig";
		var clientPrefix = ctx + "system/client";

		$("#form-clientConfig-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-clientConfig-add').serialize());
	        }
	    }

	    function initClient() {
			var url =clientPrefix + "/all";
			var options = "";
			var data=null;
			$.ajax({
				type: "POST",
				url: url,
				data: data,
				cache: false,
				contentType: false,
				processData: false,
				dataType: 'json',
				success: function(result) {
					/*清空原有客户端列表*/
					while($("#clientId").length>1){
						$("#clientId option").remove();
					}
					let json=JSON.stringify(result);
					/*设置新的客户端列表*/
					$.each(result, function(i, node){
						options +=  "<option value='"+node.clientId+"'>"+node.clientName+"("+node.clientIp+")"+"</option>";
					});
					$("#clientId").append(options);
				},
				error: function(error) {
					$.modal.alertWarning("获取客户端信息失败。");
				}
			});
		}


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