<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/meta.jsp"%>
<base href="<%=basePath%>">
<title>流程通知提醒规则配置</title>
<link href="${ctx }/resource/js/plugins/loadmask/jquery.loadmask.css"
	rel="stylesheet" type="text/css">
<script type="text/javascript"
	src="${ctx }/resource/js/plugins/loadmask/jquery.loadmask.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var noticeScopes = '${noticeRemindConfig.noticeScopes}';
		var arr = new Array();
		arr = noticeScopes.split(',');
		for (var i = 0; i < arr.length; i++) {
			if (arr[i] == 'QC') {
				$('#noticeScopes1').attr("checked", "true");
			} else if (arr[i] == 'JB') {
				$('#noticeScopes2').attr("checked", "true");
			} else if (arr[i] == 'ZD') {
				$('#noticeScopes3').attr("checked", "true");
			}
		}

		var inp1 = $('#appManagerNames').get(0);
		var inp2 = $('#appManagerIds').get(0);
		var inp3 = $('#noticeScopes3').attr('checked');
		if (inp3) {
			inp1.setAttribute('readonly', 'true');
			inp1.removeAttribute('disabled')
			inp2.setAttribute('readonly', 'true');
			inp2.removeAttribute('disabled')
		} else {
			inp1.setAttribute('disabled', 'disabled');
			inp1.removeAttribute('readonly');
			inp2.setAttribute('disabled', 'disabled');
			inp2.removeAttribute('readonly');
		}
		$('#noticeScopes3').on('click', function() {
			var inp1 = $('#appManagerNames').get(0);
			var inp2 = $('#appManagerIds').get(0);
			var inp3 = $('#noticeScopes3').attr('checked');
			if (inp3) {
				inp1.setAttribute('readonly', 'true');
				inp1.removeAttribute('disabled')
				inp2.setAttribute('readonly', 'true');
				inp2.removeAttribute('disabled')
			} else {
				inp1.setAttribute('disabled', 'disabled');
				inp1.removeAttribute('readonly');
				inp2.setAttribute('disabled', 'disabled');
				inp2.removeAttribute('readonly');
			}
		});

		var inp4 = $('#activityDefNames').get(0);
		var inp5 = $('#activityDefIds').get(0);
		var inp6 = $('input:radio[name="noticeType"]:checked').val();
		if (inp6 == '2') {
			inp4.setAttribute('readonly', 'true');
			inp4.removeAttribute('disabled')
			inp5.setAttribute('readonly', 'true');
			inp5.removeAttribute('disabled')
		} else {
			inp4.setAttribute('disabled', 'disabled');
			inp4.removeAttribute('readonly');
			inp5.setAttribute('disabled', 'disabled');
			inp5.removeAttribute('readonly');
		}
		$(':radio').on('click', function() {
			var inp4 = $('#activityDefNames').get(0);
			var inp5 = $('#activityDefIds').get(0);
			var inp6 = $('input:radio[name="noticeType"]:checked').val();
			if (inp6 == '2') {
				inp4.setAttribute('readonly', 'true');
				inp4.removeAttribute('disabled')
				inp5.setAttribute('readonly', 'true');
				inp5.removeAttribute('disabled')
			} else {
				inp4.setAttribute('disabled', 'disabled');
				inp4.removeAttribute('readonly');
				inp5.setAttribute('disabled', 'disabled');
				inp5.removeAttribute('readonly');
			}
		});

		$("#submitButton").click(function() {
			var noticeDrafters = $('#noticeScopes1').attr('checked');
			var noticeOperator = $('#noticeScopes2').attr('checked');
			var noticeUser = $('#noticeScopes3').attr('checked');
			if (!noticeDrafters && !noticeOperator && !noticeUser) {
				alert("提醒用户必选一个");
				return false;
			}
			if (noticeUser) {
				var appManagerIds = $("#appManagerIds").val();
				if (appManagerIds == null || appManagerIds == '') {
					alert("指定用户不能为空");
					return false;
				}
			}
			var noticeType = $('input:radio[name="noticeType"]:checked').val();
			if (noticeType == null) {
				alert("提醒规则必选一个");
				return false;
			}
			if (noticeType == '2') {
				var activityDefIds = $('#activityDefIds').val();
				if (activityDefIds == null || activityDefIds == '') {
					alert("指定环节不能为空");
					return false;
				}
			}
			var noticeContent = $.trim($('#noticeContent').val());
			if (noticeContent == null || noticeContent == '') {
				alert("提醒内容不能为空");
				$('#noticeContent').focus();
				return false;
			}
			setMask("main-container");
			//用jquery中的ajax方法，向服务器提交请求 
			jQuery.ajax({
				type : "POST",
				url : "${ctx}/noticeRemindConfig/update.do",
				data : $('#myform').serialize(),
				success : function(resp) {
					alert(resp);
					$('#main-container').unmask();
					if (resp == '操作成功') {
						window.location.reload();
					}
				}
			});
		});
		//清空
		$("#refreshButton").click(function() {
			var procDefId = $("#procDefId").val();
			var noticeType = '${noticeRemindConfig.noticeType}';
			if(noticeType == null || noticeType == ''){
				refreshData();
				return false;
			}
			setMask("main-container");
			//用jquery中的ajax方法，向服务器提交请求 
			jQuery.ajax({
				type : "POST",
				url : "${ctx}/noticeRemindConfig/delete.do",
				data : {
					procDefId : procDefId
				},
				success : function(resp) {
					alert(resp);
					$('#main-container').unmask();
					window.location.reload();
				}
			});
		});
	});

	function createActUser(values, names) {
		$("#appManagerIds").val(values.replace(/USER#/g, ""));
		$("#appManagerNames").val(names);
	}

	function createActConfig(values, names) {
		$("#activityDefIds").val(values);
		$("#activityDefNames").val(names);
	}
	
	function refreshData(){
		$("#appManagerNames").val("");
		$("#appManagerIds").val("");
		$("#activityDefNames").val("");
		$("#activityDefIds").val("");
		$("#noticeContent").val("");
		$('input:checkbox[name=noticeScopes]').attr('checked', false);
		$('input:radio[name=noticeType]').attr('checked',false);
	}
</script>
</head>
<body style="font-size: 13px; font-family: 'Open Sans';">

	<form action="${ctx}/noticeRemindConfig/update.do" method="post"
		id="myform">
		<div class="main-container" id="main-container">
			<div class="panel panel-primary">
				<div class="panel-body">
					<input type="hidden" id="oldValue" /> <input type="hidden"
						id="procDefId" name="procDefId"
						value="${noticeRemindConfig.procDefId}" style="width: 200px;" />
					<input type="hidden" id="procDefKey" name="procDefKey"
						value="${noticeRemindConfig.procDefKey}" style="width: 200px;" />
					<table class='table table-bordered' border="0" cellspacing="0"
						cellpadding="0" id="myTable">

						<!-- 存放隐藏域的区域 -->
						<!-- 存放表单的区域 -->

						<tr>
							<td>提醒用户：</td>
							<td colspan="3">
								<!-- <div class="checkbox"> --> <label> <input
									class="ace input-lg" type="checkbox" name="noticeScopes"
									id="noticeScopes1" value="QC" /> <span class="lbl">通知起草人</span>
							</label> <label> <input class="ace input-lg" type="checkbox"
									name="noticeScopes" id="noticeScopes2" value="JB" /> <span
									class="lbl">流程经办人</span>
							</label> <label> <input class="ace input-lg" type="checkbox"
									name="noticeScopes" id="noticeScopes3" value="ZD" /> <span
									class="lbl">指定用户</span>
							</label> <input style="width: 400px" type="text" name="noticeUserNames"
								id="appManagerNames"
								value="${noticeRemindConfig.noticeUserNames }"
								disabled="disabled"
								onclick="showDiaLog('${ctx}/pages/user_org_select.jsp?showTreeType=USER&isMultiSelect=true&roleFlag=false&orgId=0', '指定用户', '800px', '500px');" />
								<input type="hidden" name="noticeUserIds" id="appManagerIds"
								disabled="disabled" value="${noticeRemindConfig.noticeUserIds }" />
								<!-- </div> -->
							</td>
						</tr>
						<tr>
							<td>提醒规则：</td>
							<td colspan="3">
								<!-- <div class="radio"> --> <label> <input
									class="ace input-lg" type="radio" name="noticeType"
									id="noticeType1" value="1"
									<c:if test="${noticeRemindConfig.noticeType == '1'}">checked="checked"</c:if> />
									<span class="lbl">办结提醒</span>
							</label> <label> <input class="ace input-lg" type="radio"
									name="noticeType" id="noticeType2" value="2"
									<c:if test="${noticeRemindConfig.noticeType == '2'}">checked="checked"</c:if> />
									<span class="lbl">指定环节提醒</span>
							</label> <input style="width: 400px" type="text" name="activityDefNames"
								id="activityDefNames"
								value="${noticeRemindConfig.activityDefNames }"
								disabled="disabled"
								onclick="showDiaLog('${ctx}/noticeRemindConfig/selectActInfoConfigs.do?processDefId=${noticeRemindConfig.procDefId}', '选择节点', '800px', '500px');" />
								<input type="hidden" name="activityDefIds" id="activityDefIds"
								value="${noticeRemindConfig.activityDefIds}" /> <!-- </div> -->
							</td>
						</tr>
						<tr>
							<td>提醒内容：</td>
							<td colspan="3"><span class="float_left"> <textarea
										preValue="${noticeRemindConfig.noticeContent}"
										onblur="moveout(this.id);" name="noticeContent"
										id="noticeContent" style="width: 800px;">${noticeRemindConfig.noticeContent}</textarea>
							</span></td>
						</tr>
					</table>
					<div class="col-md-offset-1 col-md-9" style="text-align: center;">
						<button type="button" class="btn btn-sm btn-primary"
							id="submitButton" />
						保存 <i class="ace-icon fa fa-save bigger-110"></i>
						</button>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button type="button" class="btn btn-sm btn-danger"
							id="refreshButton" />
						重置 <i class="ace-icon glyphicon glyphicon-refresh"></i>
						</button>
					</div>
				</div>
			</div>
		</div>
	</form>
	<jsp:include page="../../../pages/sysGlType/selectTypeTree.jsp"
		flush="false" />
</body>
</html>
