<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
				<div class="d-flex flex-row justify-content-end p-3">
					<div>
						<button id="btnAddActions" onclick="${infoPrefix}Control.addActions();" class="btn btn-primary">+ 추가</button>
						<button id="btnRemoveActions" onclick="removeActions();" class="btn btn-primary">- 제거</button>
					</div>
				</div>
				<table class="datatables-ajax table table-bordered dataTable no-footer" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
					<thead>
						<tr><th tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="text-align:center;"><input id="actionToggler" onchange="${infoPrefix}Control.actions.select(this.checked);" type="checkbox" class="form-check-input"></th>
							<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Email: activate to sort column ascending" style="">기능 그룹</th>
							<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Start date: activate to sort column ascending" style="">등록일자</th>
						</tr>
                    </thead>
                    <tbody id="authActions">
					</tbody>
                   	<template id="authActionRow">
                   	<tr data-key="{AUTH_ID}-{GRP_ID}">
                       <td style="text-align:center;"><input value="{AUTH_ID}-{GRP_ID}" onchange="${infoPrefix}Control.actions.select('{AUTH_ID}-{GRP_ID}', this.checked);" type="checkbox" class="form-check-input"></td>
                       <td onclick="${infoPrefix}Control.actions.setCurrent('{AUTH_ID}-{GRP_ID}')">{GRP_ID}</td>
                       <td onclick="${infoPrefix}Control.actions.setCurrent('{AUTH_ID}-{GRP_ID}">{REG_DT}</td>
                    </tr>
                    </template>
                   	<template id="actionNotFound">
					<tr class="odd">
						<td valign="top" colspan="3" class="dataTables_empty text-center">기능 그룹 정보를 찾지 못했습니다.</td>
					</tr>
                    </template>
                   	<template id="adminActions">
					<tr class="odd">
						<td valign="top" colspan="3" class="dataTables_empty text-center">{authority}는 모든 기능을 사용할 수 있습니다.</td>
					</tr>
                    </template>
				</table>
				<div class="d-flex flex-row p-3 justify-content-between">
					<label id="actionPagingInfo" class="dataTables_info" role="status" aria-live="polite"></label>
	                 <ul id="actionPaging" class="pagination pagination-primary">
	                 </ul>
				</div>
<c:set var="actionGroupFunc" scope="request">function removeActions() {
	dialog.alert({
		content:"선택한 기능그룹을 삭제하시겠습니까?",
		onOK:() => {
			${infoPrefix}Control.removeActions();
		}
	});
}

${infoPrefix}Control.onActionListChange = obj => {
	let authority = ${infoPrefix}Control.authorities.getCurrent();
	authority = authority ? authority.AUTH_NM : "";
	let ${infoPrefix}List = ${infoPrefix}Control.actions.dataset;
	let empty = ${infoPrefix}List.empty;
	
	let trs =
		${infoPrefix}Control.authorities.isAdmin() ? [document.getElementById("adminActions").innerHTML.replace(/{authority}/, authority)] :
		empty ?
		[document.getElementById("actionNotFound").innerHTML] : <%-- from template#${infoPrefix}NotFound --%>
		${infoPrefix}List.inStrings(document.getElementById("authActionRow").innerHTML); <%-- from template#${infoPrefix}Row --%>
	$("#authActions").html(trs.join());
	$("#actionToggler").prop("checked", false);

	$("#actionPaging").setPaging({
		list:${infoPrefix}Control.actions.dataset,
		prefix:${infoPrefix}Control.actions.prefix,
		start:obj.actionStart,
		totalSize:obj.actionTotal,
		fetchSize:obj.actionFetch,
		func:"${infoPrefix}Control.actions.load({index})"
	});
};

${infoPrefix}Control.onCurrentActionChange = item => {
	if (!item) return;
	
	let data = item.data;
	let key = data.AUTH_ID + "-" + data.GRP_ID;
	$("#authActions").setCurrentRow(key);
};

${infoPrefix}Control.onActionSelect = selected => {
	let ${infoPrefix}List = ${infoPrefix}Control.actions.dataset;
	let keys = selected.map(e => ${infoPrefix}List.getKey(e));
	$("#authActions input[type='checkbox']").each(function() {
		let checkbox = $(this);
		checkbox.prop("checked", keys.includes(checkbox.val()));
	});
	
	$("#btnRemoveActions").prop("disabled", keys.length < 1);
};</c:set>