<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	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 url      = '<c:url value="/onl/statistics/management/statisticsMan.json" />';
var url_view = '<c:url value="/onl/statistics/management/statisticsMan.view" />';
var url_excel= '<c:url value="/onl/statistics/management/statisticsMan.excel"/>';

function dateFormater(cellvalue, options, rowObject){
	if (cellvalue==null|| cellvalue==undefined) return "";
	if (cellvalue.trim().length < 8) return "";
	var display = "";
	display=display+cellvalue.substr(0,4)+"-";
	display=display+cellvalue.substr(4,2)+"-";
	display=display+cellvalue.substr(6,2)+"";
	return display;
}	

function dateFormater2(cellvalue, options, rowObject){
	if (cellvalue==null|| cellvalue==undefined) return "";
	if (cellvalue.trim().length < 16) return "";
	var display = "";
	display=display+cellvalue.substr(0,4)+"-";
	display=display+cellvalue.substr(4,2)+"-";
	display=display+cellvalue.substr(6,2)+" ";

	display=display+cellvalue.substr(8,2)+":";
	display=display+cellvalue.substr(10,2)+":";
	display=display+cellvalue.substr(12,2)+".";
	display=display+cellvalue.substr(14,3);
	
	return display;
}	


function init(callback)
{
	$.ajax({
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=searchJobTypeCd]")).setNoValueInclude(true).setNoValue("","전체").setData(json.jobTypeCdRows).setFormat(codeName3OptionFormat).rendering();
			if (typeof callback === 'function') {
				callback();
			}
		
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}
	
function search(_page){
	var page = "${param.page}";
	if(_page == "1") page = "1";
	var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
	var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"");
	if(start > end){
		alert("조회기간을 확인해주세요.");
		return false;
	}
	
	$("input[name=searchStart]").val(start);
	$("input[name=searchEnd]").val(end);
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$("#grid").setGridParam({ url:url,postData: postData ,page:1 }).trigger("reloadGrid");
	
}

$(document).ready(function() {

	$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
	
	if(!("${param.searchStart}"&&"${param.searchEnd}")) {
		$("input[name=searchStartYYYYMMDD]").each(function(){
			if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
				$(this).val(getBeforeDay('7'));
			}
		});
		
		$("input[name=searchEndYYYYMMDD]").each(function(){
			if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
				$(this).val(getToday());
			}
		});
	}else{
		$("input[name=searchStartYYYYMMDD]").val("${param.searchStartYYYYMMDD}");
		$("input[name=searchEndYYYYMMDD]").val("${param.searchEndYYYYMMDD}");
	}
	
	init(search);
	
	var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
	var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"");
	$("input[name=searchStart]").val(start);
	$("input[name=searchEnd]").val(end);
		
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$('#grid').jqGrid({
		datatype : "json",
		mtype : 'POST',
  		url : url,
  		postData : gridPostData,
		colNames : [ '통계작업일',
		             '통계작업구분코드',
		             '통계작업구분',
		             '통계작업시작시각',
		             '통계작업종료시각',
		             '작업시간(단위:초)',
		             '성공여부코드',
		             '성공여부'
		              ],
		colModel : [ { name : 'STATCJOBYMD'			, align : 'center'	, width:'70'	,sortable:false ,formatter: dateFormater},
		             { name : 'STATCJOBCYCLDSTCD'	, hidden: true},
		             { name : 'STATCJOBCYCLDSTNM'	, align : 'center'	, width:'70' },
		             { name : 'STATCJOBSTARTHMS'	, align : 'center'	, width:'70' ,formatter: dateFormater2},
		             { name : 'STATCJOBENDHMS'		, align : 'center'	, width:'70' ,formatter: dateFormater2},
		             { name : 'STATCJOBHMS'			, align : 'center'	, width:'70'},
		             { name : 'SUCSSYN'				, hidden: true},
		             { name : 'SUCSSYNNM'			, align : 'center'	, width:'70'}
		           ],
		jsonReader : {
			repeatitems : false
		},
		pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),
		loadComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});
			}
		},
		ondblClickRow: function(rowId) {
			var rowData = $(this).getRowData(rowId); 
            var statcjobymd = rowData['STATCJOBYMD'];
            statcjobymd = statcjobymd.replace(/-/gi,"");
            var statcjobcycldstcd = rowData['STATCJOBCYCLDSTCD'];
            
            var url = '<c:url value="/onl/statistics/management/statisticsMan.view" />';
            url = url + '?cmd=DETAIL';
            url = url + '&page='+$(this).getGridParam("page");
            url = url + '&returnUrl='+getReturnUrl();
            url = url + '&menuId='+'${param.menuId}';
			//검색값
            url = url + '&'+getSearchUrl();
            //key값
            url = url + '&statcjobymd='+statcjobymd + '&statcjobcycldstcd='+statcjobcycldstcd;
            goNav(url);
            
        }		
	});
	
	resizeJqGridWidth('grid','content_middle','1000');

	$("#btn_search").click(function(){
		search();
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	$("#btn_excel").click(function(event) {
        event.stopPropagation(); // Do not propagate the event.
        // Create an object that will manage to download the file.
        var target = "excelDown" ; // iframe의 name
        //(url,cmd,gridObj,formObject,fileName,merge)
		gridToExcelSubmit2(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'통계자료 생성 현황');
		return false;
	});	
	

	buttonControl();
	
	$("#startDatepicker").datepicker();
	$("#endDatepicker").datepicker();
	
});
 
</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" id="content_middle">
				<div class="search_wrap">
					<img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" level="W"/>
					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />	
				</div>
				<div class="title">통계자료 생성 현황</span></div>
				<form id="ajaxForm"  onsubmit="return false;">
					<table class="search_condition" cellspacing=0;>
						<tbody>
							<tr>
								<th style="width:180px;">통계자료 생성 일자</th>
								<td>
								<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" readonly="readonly" value="" size="10" style="width:80px; border:1px solid #ebebec;">
								~ 
								<input type="text" name="searchEndYYYYMMDD" value="" id="endDatepicker" size="10" readonly="readonly" style="width:80px; border:1px solid #ebebec;">
								<input type="hidden" name="searchStart" value="" style="width:0px;">
								<input type="hidden" name="searchEnd" value="" style="width:0px;">
								</td>
								<th class="search_td_title" width="150px">작업구분</th>
								<td><select name="searchJobTypeCd" value="${param.searchJobTypeCd}" style="width:100%" /></td>
							</tr>	
										
						</tbody>
					</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

