<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ page import="com.eactive.eai.common.util.SystemUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>

<script language="javascript" >
var isDetail = false;


function isValid(){
	if($('input[name=roleId]').val() == ""){
		alert("<%= localeMessage.getString("role.checkRequired1") %>");
		return false;
	}else if($('input[name=roleName]').val() == ""){
		alert("<%= localeMessage.getString("role.checkRequired2") %>");
		return false;
	}else if($('select[name=useYn]').val() == ""){
		alert("<%= localeMessage.getString("combo.checkRequiredUsed") %>");
		return false;
	}else if($('input[name=roleScreen]').val() == ""){
		alert("<%= localeMessage.getString("menu.checkRequierd3") %>");  // 상위메뉴 ID를 입력하여 주십시요.
		return false;
	}
	return true;
}
function init(url,key,key2,callback){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=statcjobcycldstcd]")).setData(json.jobTypeCdRows).setFormat(codeName3OptionFormat).rendering();
			
			if(typeof callback === 'function') {
				callback(url,key,key2);
			}
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
function detail(url,key,key2){
	if (!isDetail)return;
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json", 
		data:{cmd: 'DETAIL', statcjobymd : key , statcjobcycldstcd : key2},
		success:function(json){
			var data = json;
// 			$("input[name=statcjobymd]").attr('readonly',true);
// 			$("input[name=statcjobstarthms]").attr('readonly',true);
// 			$("input[name=statcjobendhms]").attr('readonly',true);
 			$("select[name=statcjobcycldstcd]").attr("disabled",true);
			
			
			$("#ajaxForm input[type!=radio],#ajaxForm select,#ajaxForm textarea").each(function(){
				var name = $(this).attr("name");
				var tag  = $(this).prop("tagName").toLowerCase();
				$(this).attr('readonly',true);
				$(tag+"[name="+name+"]").val(data[name.toUpperCase()]);
			});
			
			$("input[name=statcjobymd]").inputmask("9999-99-99",{'autoUnmask':true});
			$("input[name=statcjobstarthms]").inputmask("9999-99-99 99:99:99 99",{'autoUnmask':true});
			$("input[name=statcjobendhms]").inputmask("9999-99-99 99:99:99 99",{'autoUnmask':true});
			
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
$(document).ready(function() {	
	var returnUrl = getReturnUrlForReturn();
	
	var url ='<c:url value="/onl/statistics/management/statisticsMan.json" />';
	var key ="${param.statcjobymd}";
	var key2 ="${param.statcjobcycldstcd}";
	
	if (key != "" && key !="null"){
		isDetail = true;
	}
	
	init(url,key,key2,detail);
	
	$("#btn_modify").click(function(){
		if (confirm("<%= localeMessage.getString("common.checkModify")%>") != true)
			return;
		
		if (!isValid()){
			return;
		}
		
		$("select[name=statcjobcycldstcd]").attr("disabled",false);
		var postData = $('#ajaxForm').serializeArray();
		if (isDetail){
			postData.push({ name: "cmd" , value:"UPDATE"});
		}else{
			postData.push({ name: "cmd" , value:"INSERT"});
		}
		$.ajax({
			type : "POST",
			url:url,
			data:postData,
			success:function(args){
				alert("<%= localeMessage.getString("common.saveMsg") %>");
				goNav(returnUrl);//LIST로 이동
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	});
	
	$("#btn_delete").click(function(){
		
		if(confirm("<%= localeMessage.getString("common.confirmMsg")%>")){  
			
			$("select[name=statcjobcycldstcd]").attr("disabled",false);
			var postData = $('#ajaxForm').serializeArray();
			postData.push({ name: "cmd" , value:"DELETE"});
			$.ajax({
				type : "POST",
				url:url,
				data:postData,
				success:function(args){
					alert("<%= localeMessage.getString("common.deleteMsg") %>");
					goNav(returnUrl);//LIST로 이동

				},
				error:function(e){
					alert(e.responseText);
				}
			}); 
		}else{
			return false;
		}
		
	
	});	
	$("#btn_previous").click(function(){
		goNav(returnUrl);//LIST로 이동
	});
	
	
	buttonControl(isDetail);
	titleControl(isDetail);
});
 
</script>
</head>
	<body>
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>					
				</ul>					
			</div><!-- end content_top -->
			<div class="content_middle">
				<div class="search_wrap">
						<img src="<c:url value="/img/btn_delete.png"/>" alt="" id="btn_delete" level="W" status="DETAIL"/>
<%-- 					<img src="<c:url value="/img/btn_modify.png"/>" alt="" id="btn_modify" level="W" status="DETAIL,NEW" />				 --%>
					<img src="<c:url value="/img/btn_previous.png"/>" alt="" id="btn_previous" level="R" status="DETAIL,NEW"/>	
				</div>
				<div class="title">통계자료 생성 현황</div>	
				
				<form id="ajaxForm">
					<table class="table_row" cellspacing="0">
					<input type="hidden" name="sucssyn"/>
						<tr>
							<th style="width:180px;">통계작업년월일</th>
							<td><input type="text" name="statcjobymd"/> </td>
							<th style="width:180px;">작업시간 (단위:초)</th>
							<td><input type="text" name="statcjobhms"/> </td>
						</tr>
						<tr>
							<th>통계작업시작시각</th>
							<td><input type="text" name="statcjobstarthms"/></td>
							<th>통계작업종료시각</td>
							<td><input type="text" name="statcjobendhms"/></td>
						</tr>
						<tr>
							<th>통계작업추가구분코드</th>
							<td><select name="statcjobcycldstcd"  style="width:100%" /></td>
							<th>성공유무</th>
							<td><input type="text" name="sucssynnm" readonly/></td>
						</tr>
						<tr height="100px">
							<th>에러메시지</th>
							<td colspan="3"><textarea  name="errmsg" style="width:100%;height:100px" ></textarea>
						</td>
						</tr>
					</table>
				</form>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->	
	</body>
</html>

