<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>数据同步</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#source").change(function () {
                if ($("#source").val()==1) {
                    $(".sourceDiv").show();
                } 
                if($("#source").val()==2) {
                	$("#rootOrgId").attr("value", "");
                	$("#appId").attr("value", "");
                    $(".sourceDiv").hide();
                }
            });
			if ($("#source").val()==1) {
                $(".sourceDiv").show();
            } 
            if($("#source").val()==2) {
            	$("#rootOrgId").attr("value", "");
            	$("#appId").attr("value", "");
                $(".sourceDiv").hide();
            }
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/admin/exam/list">考试列表</a></li>
		<li class="active"><a href="##">数据同步</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="dataSync" action="${ctx}/admin/exam/data/sync/save" method="post" class="form-horizontal">
		<form:hidden path="examId"/>
		<tags:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">考试名称</label>
			<div class="controls">
				${exam.name}
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">同步来源</label>
			<div class="controls">
				<select class="input-small" name="source" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if> id="source">
	            	<c:forEach items="${sourceList}" var="item">
	                    <option value="${item.value}"
	                            <c:if test="${item.value==dataSync.source.value}">selected</c:if>>${item.name}</option>
	                </c:forEach>
            	</select>
			</div>
		</div>
		<div class="sourceDiv">
 		<div class="control-group">
			<label class="control-label">机构ID</label>
			<div class="controls">
				<input name="rootOrgId" id='rootOrgId' value="${dataSync.rootOrgId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">appId</label>
			<div class="controls">
				<input name="appId" id='appId' value="${dataSync.appId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
			</div>
		</div> 
		</div>
		<div class="control-group">
			<label class="control-label">密匙</label>
			<div class="controls">
				<input name="accessKey" value="${dataSync.accessKey }" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">密钥</label>
			<div class="controls">
				<input name="accessSecret" value="${dataSync.accessSecret }" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">考试ID</label>
			<div class="controls">
				<input name="cloudExamId" value="${dataSync.cloudExamId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">考生接口地址</label>
			<div class="controls">
				<textarea name="studentUrl" class="input-xxlarge required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>>${dataSync.studentUrl }</textarea>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">试卷结构接口地址</label>
			<div class="controls">
				<textarea name="subjectUrl" class="input-xxlarge required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>>${dataSync.subjectUrl }</textarea>
			</div>
		</div>
		<c:if test="${dataSync.cloudExamId!=null && dataSync.source=='EXAM_CLOUD'}">
		<div class="control-group">
			<label class="control-label">试卷结构</label>
			<div class="controls">
				<a href="${ctx}/admin/exam/data/sync/export?examId=${dataSync.examId }">下载</a>
			</div>
		</div>
		</c:if>
		<div class="control-group">
			<label class="control-label">试卷内容接口地址</label>
			<div class="controls">
				<textarea name="subjectPaperUrl" class="input-xxlarge required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>>${dataSync.subjectPaperUrl }</textarea>
			</div>
		</div>
		<div class="form-actions">
			<c:if test="${!dataSync.finished || running }">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="开始同步"/>
			</c:if>
			
			&nbsp;
			<a href="javascript:" onclick="history.go(-1);" class="btn"/>返回</a>
		</div>
	</form:form>
</body>
</html>
