<!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">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-client-add">
            <input name="status"  type="hidden" id="status" value='2'/>
			<input name="clientType"  type="hidden" id="clientType" value='0'/>
            <input name="remark"  type="hidden" id="remark" value=''/>
			<div class="form-group">	
				<label class="col-sm-3 control-label">客户端名称：</label>
				<div class="col-sm-8">
					<input id="clientName" name="clientName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">客户端IP：</label>
				<div class="col-sm-8">
					<input id="clientIp" name="clientIp" 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="checkinterval" name="checkinterval" class="form-control" type="text" value="30">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-11 control-label" style="color:#f7a54a">客户端有多个测试驱动路径时，以 ; 做分隔</label>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">驱动路径：</label>
				<div class="col-sm-8">
					<textarea id="clientPath" rows="5" name="clientPath" class="form-control" type="text" value="/TestDriven">/TestDriven</textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">应用项目：</label>
				<div class="col-sm-8">
					<!--/*@thymesVar id="projects" type="com.luckyframe.project.system.client.controller"*/-->
					<label th:each="project:${projects}" class="check-box">
						<input name="project" type="checkbox" th:value="${project.projectId}" th:text="${project.projectName}">
					</label>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/client"
		$("#form-client-add").validate({
			rules:{
				clientName:{
        			required:true,
        			minlength: 2,
        			maxlength: 20,
                    remote: {
                        url: ctx + "system/client/checkClientNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            name: function () {
                                return $.common.trim($("#clientName").val());
                            }
                        },
                        dataFilter: function (data, type) {
                        	return $.validate.unique(data);
                        }
                    }
				},
				clientIp:{
        			required:true,
        			isIp:true,
                    remote: {
                        url: ctx + "system/client/checkIpUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            name: function () {
                                return $.common.trim($("#clientIp").val());
                            }
                        },
                        dataFilter: function (data, type) {
                        	return $.validate.unique(data);
                        }
                    }
				},
				checkinterval:{
        			required:true,
        			isIntGtZero:true,
        			isInteger:true,
        			min:10,
        			max:60
				},
				clientPath:{
        			required:true,
        			minlength: 2,
        			maxlength: 500,
				},
			},
        	messages: {
                "clientName": {
                    remote: "客户端名称已经存在"
                },
        		"clientIp": {
                    remote: "客户端IP已经存在"
                }
            }
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }

        function add() {
        	var clientName = $("input[name='clientName']").val();
        	var clientIp = $("input[name='clientIp']").val();
        	var checkinterval = $("input[name='checkinterval']").val();
        	var clientPath = $("textarea[name='clientPath']").val();
        	var remark = $("input[name='remark']").val();
        	var status = $("input[name='status']").val();
			var clientType = $("input[name='clientType']").val();
        	var projectIds = $.form.selectCheckeds("project");
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "system/client/add",
        		data : {
        			"clientName": clientName,
        			"clientIp": clientIp,
        			"checkinterval": checkinterval,
        			"clientPath": clientPath,
        			"remark": remark,
        			"status": status,
					"clientType": clientType,
        			"projectIds": projectIds
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.successCallback(data);
        		}
        	});
        }
	</script>
</body>
</html>
