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


$(document).ready(function() {	
	$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
	
	$("input[name=searchStartYYYYMMDD]").each(function(){
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
			$(this).val(getToday());
		}
	});
	
	$("input[name=searchEndYYYYMMDD]").each(function(){
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
			$(this).val(getToday());
		}
	});
	
    var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
    
    var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
	var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"");
	
	gridPostData["searchStartDate"] = start;
	gridPostData["searchEndDate"] = end;
	
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:['<%= localeMessage.getString("controlService.bizCode") %>',
                  '<%= localeMessage.getString("controlService.bizCodeName") %>',
                  '<%= localeMessage.getString("controlService.serviceCode") %>',
                  '<%= localeMessage.getString("controlService.serviceCodeDesc") %>',
                  '<%= localeMessage.getString("controlService.cnt") %>'
                  ],
		colModel:[
				{ name : 'EAIBZWKDSTCD'  , align:'left'	,sortable:false },
				{ name : 'BZWKDSTICNAME' , align:'left' },
				{ name : 'EAISVCNAME'    , align:'left' },
				{ name : 'EAISVCDESC'    , align:'left' },
				{ name : 'CNT'           , align:'center' ,formatter:'integer' }
				],
        jsonReader: {
             repeatitems:false
        },	          
		pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),
		ondblClickRow: function(rowId) {
        },
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		
		},loadError: function (jqXHR, textStatus, errorThrown) {
        	
			var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	}	        
	});
	
	
	resizeJqGridWidth('grid','content_middle','1000');

	$("#btn_search").click(function(){
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
		var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
		var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"");
		
		if(start > end){
			alert("조회기간을 확인해주세요.");
			return false;
		}
		$("input[name=searchStartDate]").val(start);
		$("input[name=searchEndDate]").val(end);
		
		postData["searchStartDate"] = start;
		postData["searchEndDate"] = end;
		
		$("#grid").setGridParam({ postData: postData ,page : "1" }).trigger("reloadGrid");
	});

	
	$("input[name*=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	//검색조건 달력
	$("#startDatepicker").datepicker();
	$("#endDatepicker").datepicker();
	
	$("#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();
	
});
 
</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">
					<button type="button" class="cssbtn" id="btn_excel" level="W"><i class="material-icons">table_view</i> <%= localeMessage.getString("button.excel") %></button>
					<button type="button" class="cssbtn" id="btn_search" level="R"><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>
<%-- 					<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"><%= localeMessage.getString("controlService.title") %></div>
				<form id="ajaxForm"  onsubmit="return false;">
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:180px;"><%= localeMessage.getString("controlService.search") %></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="searchStartDate" value="" style="width:0px;">
								<input type="hidden" name="searchEndDate" value="" style="width:0px;">
							</td>							
						</tr>						
					</tbody>
				</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

