<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<style id="actionGroupMainCss">
	#actionGroupMainCss+div tr[data-key='userAction'] > td:nth-child(n+2):nth-child(-n+3),
	#actionGroupMainCss+div tr[data-key='anonymousAction'] > td:nth-child(n+2):nth-child(-n+3) {
		color: red;
	}
</style>
<c:set var="prefixName" scope="request">기능 그룹</c:set>
              <!-- Page Body -->
    <div class="d-flex flex-column flex-grow-1">
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper dt-bootstrap5 no-footer">
        
			<div class="d-flex flex-row justify-content-evenly">
				<div style="width:49%;">
				<h5 class="mt-3">기능 그룹</h5>
				<div class="d-flex flex-row justify-content-between p-3">
					<div>
						<div class="input-group" id="${infoPrefix}-query">
							<select id="${infoPrefix}by" onchange="document.getElementById('${infoPrefix}term').focus();" aria-controls="DataTables_Table_0" class="form-select">
								<option value="${infoPrefix}Name">이름</option>
								<option value="${infoPrefix}ID">아이디</option>
							</select>
							<input id="${infoPrefix}term" autofocus type="text" placeholder="조회 조건을 입력하십시오." class="form-control">
						</div>
					</div>
					<div>
						<button onclick="searchaction${infoPrefix}s();" class="btn btn-primary">찾기</button>
						<button onclick="action${infoPrefix}Control.groups.newInfo();" class="btn btn-primary">+ 추가</button>
						<button id="btnRemoveaction${infoPrefix}s" onclick="removeaction${infoPrefix}s();" 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 id="action${infoPrefix}Thead">
						<tr><th tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="text-align:center;"><input onchange="action${infoPrefix}Control.groups.select(this.checked);" type="checkbox" class="form-check-input"></th>
							<th class="sorting sorting_asc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Full name: activate to sort column descending" style="">아이디</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="action${infoPrefix}List">
					</tbody>
                   	<template id="action${infoPrefix}Row">
                   	<tr data-key="{GRP_ID}">
                       <td style="text-align:center;"><input value="{GRP_ID}" onchange="action${infoPrefix}Control.groups.select('{GRP_ID}', this.checked);" type="checkbox" class="form-check-input"></td>
                       <td onclick="action${infoPrefix}Control.groups.setCurrent('{GRP_ID}')" ondblclick="action${infoPrefix}Control.groups.getInfo({})">{GRP_ID}</td>
                       <td onclick="action${infoPrefix}Control.groups.setCurrent('{GRP_ID}')" ondblclick="action${infoPrefix}Control.groups.getInfo({})">{GRP_NM}</td>
                       <td onclick="action${infoPrefix}Control.groups.setCurrent('{GRP_ID}')" ondblclick="action${infoPrefix}Control.groups.getInfo({})">{REG_DT}</td>
                    </tr>
                    </template>
                   	<template id="action${infoPrefix}NotFound">
					<tr class="odd">
						<td valign="top" colspan="4" class="dataTables_empty text-center">${prefixName} 정보를 찾지 못했습니다.</td>
					</tr>
                    </template>
				</table>
				<div class="d-flex flex-row p-3 justify-content-between">
					<label id="action${infoPrefix}PagingInfo" class="dataTables_info" role="status" aria-live="polite"></label>
	                 <ul id="action${infoPrefix}Paging" class="pagination pagination-primary">
	                 </ul>
				</div>
				</div>
				<div style="width:49%;">
				<h5 class="mt-3">기능 URL</h5>
				<div class="d-flex flex-row justify-content-end p-3">
					<div>
						<button id="btnAddActions" onclick="action${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 id="actionThead">
						<tr><th tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="text-align:center;"><input id="actionToggler" onchange="action${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="">기능 URL</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="actionList">
					</tbody>
                   	<template id="actionRow">
                   	<tr data-key="{GRP_ID}-{ACTION}">
                       <td style="text-align:center;"><input value="{GRP_ID}-{ACTION}" onchange="action${infoPrefix}Control.actions.select('{GRP_ID}-{ACTION}', this.checked);" type="checkbox" class="form-check-input"></td>
                       <td onclick="action${infoPrefix}Control.actions.setCurrent('{GRP_ID}-{ACTION}')">{ACTION}</td>
                       <td onclick="action${infoPrefix}Control.actions.setCurrent('{GRP_ID}-{ACTION}">{REG_DT}</td>
                    </tr>
                    </template>
                   	<template id="actionNotFound">
					<tr class="odd">
						<td valign="top" colspan="3" class="dataTables_empty text-center">기능 URL 정보를 찾지 못했습니다.</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>
				</div>
			</div>
		</div>
    </div>
              <!--/ Page Body -->
<script >
var action${infoPrefix}Control = new ActionGroupControl();

function searchaction${infoPrefix}s() {
	action${infoPrefix}Control.groups.query = {
		by:$("#${infoPrefix}-query [name='by']").val(),
		term:$("#${infoPrefix}-query [name='term']").val()
	};
	action${infoPrefix}Control.groups.load(1);
}

function removeaction${infoPrefix}s() {
	dialog.alert({
		content:"선택한 ${prefixName} 정보를 제거하시겠습니까?",
		onOK:() => {
			action${infoPrefix}Control.groups.remove();
		}
	});
}

function removeActions() {
	dialog.alert({
		content:"선택한 기능 URL을 삭제하시겠습니까?",
		onOK:() => {
			action${infoPrefix}Control.removeActions();
		}
	});
}

function renderaction${infoPrefix}List() {
	let ${infoPrefix}List = action${infoPrefix}Control.groups.dataset;
	let empty = action${infoPrefix}List.empty;
	
	let trs = empty ?
		[document.getElementById("action${infoPrefix}NotFound").innerHTML] : <%-- from template#action${infoPrefix}NotFound --%>
		${infoPrefix}List.inStrings(document.getElementById("action${infoPrefix}Row").innerHTML); <%-- from template#action${infoPrefix}Row --%>
	$("#action${infoPrefix}List").html(trs.join());
	$("#action${infoPrefix}Thead").find("th input[type='checkbox']").prop("checked", false);
	$("#actionThead").find("th input[type='checkbox']").prop("checked", false);
}

action${infoPrefix}Control.onGroupListChange = obj => {
	renderaction${infoPrefix}List();

	$("#action${infoPrefix}Paging").setPaging({
		list:action${infoPrefix}Control.groups.dataset,
		prefix:action${infoPrefix}Control.groups.prefix,
		start:obj.${infoPrefix}Start,
		totalSize:obj.${infoPrefix}Total,
		fetchSize:obj.${infoPrefix}Fetch,
		func:"action${infoPrefix}Control.groups.load({index})"
	});
};

action${infoPrefix}Control.onCurrentGroupChange = item => {
	$("#btnAddActions").prop("disabled", !item);
	if (!item) return;
	
	let key = item.data.GRP_ID;
	$("#action${infoPrefix}List").setCurrentRow(key);
};

action${infoPrefix}Control.onGroupSelect = selected => {
	let ${infoPrefix}List = action${infoPrefix}Control.groups.dataset;
	let keys = selected.map(e => ${infoPrefix}List.getKey(e));
	$("#action${infoPrefix}List input[type='checkbox']").each(function() {
		let checkbox = $(this);
		checkbox.prop("checked", keys.includes(checkbox.val()));
	});
	
	$("#btnRemoveaction${infoPrefix}s").prop("disabled", keys.length < 1);
};


action${infoPrefix}Control.onActionListChange = obj => {
	let ${infoPrefix}List = action${infoPrefix}Control.actions.dataset;
	let empty = ${infoPrefix}List.empty;
	
	let trs = empty ?
		[document.getElementById("actionNotFound").innerHTML] : <%-- from template#${infoPrefix}NotFound --%>
		${infoPrefix}List.inStrings(document.getElementById("actionRow").innerHTML); <%-- from template#${infoPrefix}Row --%>
	$("#actionList").html(trs.join());
	$("#actionToggler").prop("checked", false);

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

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

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

$("#${infoPrefix}term").onEnterPress(searchaction${infoPrefix}s);

$(function(){
	${onload}
	action${infoPrefix}Control.groups.setData({
		${infoPrefix}List:${groupList},
		${infoPrefix}Start:${groupStart},
		${infoPrefix}Fetch:${groupFetch},
		${infoPrefix}Total:${groupTotal}
	});
});
//# sourceURL=actionGroup-main.jsp
</script>
