<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ 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 url      = '<c:url value="/common/acl/user/userLoginHistoryMan.json" />';
var url_view = '<c:url value="/common/acl/user/userLoginHistoryMan.view" />';


$(document).ready(function() {	
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:['번호',
                  '<%= localeMessage.getString("user.name") %>',
                  '<%= localeMessage.getString("login.userId") %>',
                  '<%= localeMessage.getString("user.name") %>',
                  '<%= localeMessage.getString("user.roleName") %>',
                  '<%= localeMessage.getString("userLoginHistory.loginDttm") %>'
                  ],
		colModel:[
				{ name : 'rowNum'   , align:'center', width:"40"	,sortable:false  },
				{ name : 'loginLogId' , align:'center' , hidden:true , formatter:'integer'},
				{ name : 'userId' , align:'center'  },
				{ name : 'username' , align:'center'  },
				{ name : 'roleidnfiname' , align:'center'  },
				{ name : 'loginDttm' , align:'center'  }
				],
        jsonReader: {
             repeatitems:false
        },	          
		pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			var rowData = $(this).getDataIDs();
			
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
			for(var i = 0 ; i< rowData.length; i++){
				$(this).jqGrid('setCell', rowData[i], 'rowNum', i+1);
			}
		
		},		
		loadError: function (jqXHR, textStatus, errorThrown) {
       		if(jqXHR.status == 401) {
        		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,"");
		var now = new Date();
		
		if(start > getToday()){
			alert("시작일이 오늘 이후입니다. 시작일을 확인해주세요.");
			$("input[name=searchStartYYYYMMDD]").focus();
			return false;
		}
		if(start > end){
			alert("조회기간 종료일은 시작일보다 커야합니다.");
			$("input[name=searchEndYYYYMMDD]").focus();
			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();
	
	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_search" level="R"><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>
				</div>
				<div class="title"><%= localeMessage.getString("userLoginHistory.title") %></div>
				
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:10%; min-width:100px;"><%= localeMessage.getString("login.userId") %></th>
							<td><input type="text" name="searchUserId" value="${param.searchUserId}"></td>
							<th style="width:10%; min-width:100px;"><%= localeMessage.getString("user.name") %></th>
							<td><input type="text" name="searchUserName" value="${param.searchUserName}"></td>
						</tr>
						<tr>
							<th style="width:180px;"><%= localeMessage.getString("userLoginHistory.searchDate") %></th>
							<td colspan="3">
								<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" readonly="readonly" value="" size="10" style="width:20%; border:1px solid #ebebec;">
								~ 
								<input type="text" name="searchEndYYYYMMDD" value="" id="endDatepicker" size="10" readonly="readonly" style="width:20%; 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>
				
				<table id="grid" ></table>
				<div id="pager"></div>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

