<!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-projectCaseParams-add">
            <div class="form-group">	
				<label class="col-sm-3 control-label">项目名称：</label>
				<div class="col-sm-8">
					<select id="projectId" name="projectId" class="form-control m-b" th:with="type=${projects}" onchange="resetValidateForm()">
					    <option value="0">所有项目</option>
	                    <option th:each="projects : ${type}" th:text="${projects.projectName}" th:value="${projects.projectId}" th:selected="${projects.projectId == defaultProjectId}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">参数名称：</label>
				<div class="col-sm-8">
					<input id="paramsName" name="paramsName" 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="paramsValue" name="paramsValue" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control" rows="8"></textarea>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "testmanagmt/projectCaseParams";
		
		$.validator.setDefaults({
			ignore:":hidden:not(select)",
			submitHandler : function() {
				save();
			}
		});
		
		$("#form-projectCaseParams-add").validate({
			rules:{
				projectId:{
					required:true,
				},
				paramsName:{
					required:true,
        			maxlength: 50,
                    remote: {
                        url: prefix + "/checkProjectCaseParamsNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            name: function () {
                                return $.common.trim($("#paramsName").val());
                            },
                            projectId: function () {
                                return $.common.trim($("#projectId").val());
                            }
                        },
                        dataFilter: function (data, type) {
                        	return $.validate.unique(data);
                        }
                    }
				},
				paramsValue:{
					required:true,
					maxlength:500
				},
				remark:{
					maxlength:200
				}
			},
        	messages: {
                "paramsName": {
                    remote: "参数名称已经存在"
                }
            }
		});
		
		/*重新初始化表单验证*/
		function resetValidateForm() {
			$.validate.resetForm();
			$.validate.form();
		}
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-projectCaseParams-add').serialize());
	        }
	    }
	</script>
</body>
</html>
