<!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-edit" th:object="${clientConfig}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<input id="currentClientId"  th:field="*{currentClientId}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">客户端：</label>
				<div class="col-sm-8">
					<select id="clientId" name="clientId" th:field="*{clientId}" class="form-control m-b" style="float:left">
					</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" th:field="*{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" th:field="*{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-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-clientConfig-edit').serialize());
	        }
	    }
		function initClient() {
			var url =clientPrefix + "/list";
			var options = "";
			var data=null;
			$.ajax({
				type: "POST",
				url: url,
				data: data,
				cache: false,
				contentType: false,
				processData: false,
				dataType: 'json',
				success: function(result) {
					var id=$("#currentClientId").val();
					var current="";
					/*清空原有客户端列表*/
					while($("#clientId").length>1){
						$("#clientId option").remove();
					}
					let json=JSON.stringify(result);
					/*设置新的客户端列表*/
					$.each(result.rows, function(i, node){
						if($.trim(node.clientId) == $.trim(id))
						{
							current +=  "<option value='"+node.clientId+"'>"+node.clientName+"("+node.clientIp+")"+"</option>";

						}
						else{
							options +=  "<option value='"+node.clientId+"'>"+node.clientName+"("+node.clientIp+")"+"</option>";
						}
					});
					current+=options;

					$("#clientId").append(current);
					$("#clientId").val(id);
				},
				error: function(error) {
					$.modal.alertWarning("获取客户端信息失败。");
				}
			});
		}
		/*选择客户端*/
		function selectClient(){
			var clientId = $("#clientId").val();
			if($.common.isEmpty(clientId)) return;
			console.log(clientId);
		}
	</script>
</body>
</html>
