<%@ 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>Client 선택</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css_custom.jsp"/>
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>
</head>
<script language="javascript">
	var url = '<c:url value="/onl/admin/authserver/clientMan.json" />';
	$(document).ready(function() {
		var gridPostData = getSearchForJqgrid("cmd","POPUP_LIST");
		$('#grid').jqGrid({
			datatype: "json",
			mtype: 'POST',
			url: url,
			postData: gridPostData,
			colNames: ['클라이언트명', '클라이언트ID', '스코프', 'GRANT타입', 'TOKEN유효시간(초)'],
			colModel: [
				{ name: 'CLIENTNAME', align: 'left', sortable: false },
				{ name: 'CLIENTID', align: 'left', sortable: false },
				{ name: 'SCOPE', align: 'left', sortable: false },
				{ name: 'GRANTTYPES', align: 'left', sortable: false },
				{ name: 'ACCESSTOKENVALIDITYSECONDS', align: 'center', sortable: false }
			],
			jsonReader: {
				repeatitems: false
			},
			pager : $('#pager'),
			page : '${param.page}',
			rowNum: '${rmsDefaultRowNum}',
			autoheight: true,
			height: 'auto',
			autowidth: true,
			viewrecords: true,
			shrinkToFit: true,
			rowList: eval('[${rmsDefaultRowList}]'),
			ondblClickRow: function(rowid) {
				var rowData = $(this).getRowData(rowid);
				var clientId = rowData['CLIENTID'];
				if (window.opener && typeof window.opener.selectClient === "function") {
					window.opener.selectClient(clientId);
					window.close();
				} else if (window.parent && typeof window.parent.selectClient === "function") {
					window.parent.selectClient(clientId);
					window.parent.closeModal();
				}
			}
		});

		resizeJqGridWidth('grid', 'popup_box', '100%');

		$("#btn_search").click(function(){
			var postData = getSearchForJqgrid("cmd","POPUP_LIST");
			$("#grid").setGridParam({ postData: postData, page: 1 }).trigger("reloadGrid");
		});

		$("#btn_close").click(function(){
			if (window.parent && typeof window.parent.closeModal === "function") {
				window.parent.closeModal();
			} else {
				window.close();
			}
		});

		$("input[name^=search]").keydown(function(key){
			if (key.keyCode == 13){
				$("#btn_search").click();
			}
		});
	});
</script>
<body>
		<div class="popup_box" >
			<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>
				<button type="button" class="cssbtn" id="btn_close" level="R"><i class="material-icons">cancel</i> <%= localeMessage.getString("button.close") %></button>
			</div>
			<div class="title">Client 선택</div>

			<table class="search_condition" cellspacing="0">
				<tr>
					<th>클라이언트명</th>
					<td><input type="text" name="searchClientName" value="${param.searchClientName}"></td>
					<th>클라이언트ID</th>
					<td><input type="text" name="searchClientId" value="${param.searchClientId}"></td>
				</tr>
			</table>
			<!-- grid -->
			<table id="grid"></table>
			<div id="pager"></div>
		</div><!-- end popup_box -->
	</body>
</html>