<%@ 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="authorityMainCss">
	#authorityMainCss+div tr[data-key='ROLE_ADMIN'] > td:nth-child(n+2):nth-child(-n+3),
	#authorityMainCss+div tr[data-key='ROLE_USER'] > td:nth-child(n+2):nth-child(-n+3),
	#authorityMainCss+div tr[data-key='ROLE_ANONYMOUS'] > 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" name="by" onchange="document.getElementById('${infoPrefix}term').focus();" aria-controls="DataTables_Table_0" class="form-select">
								<option value="authName">이름</option>
								<option value="authID">아이디</option>
							</select>
							<input id="${infoPrefix}term" name="term" autofocus type="text" placeholder="조회 조건을 입력하십시오." class="form-control">
						</div>
					</div>
					<div>
						<button onclick="search${infoPrefix}s();" class="btn btn-primary">찾기</button>
						<button onclick="${infoPrefix}Control.authorities.newInfo();" class="btn btn-primary">+ 추가</button>
						<button id="btnRemove${infoPrefix}s" onclick="remove${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="${infoPrefix}Thead">
						<tr><th tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="text-align:center;"><input onchange="${infoPrefix}Control.authorities.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="${infoPrefix}List">
					</tbody>
                   	<template id="${infoPrefix}Row">
                   	<tr data-key="{AUTH_ID}">
                       <td style="text-align:center;"><input value="{AUTH_ID}" onchange="${infoPrefix}Control.authorities.select('{AUTH_ID}', this.checked);" type="checkbox" class="form-check-input"></td>
                       <td onclick="${infoPrefix}Control.authorities.setCurrent('{AUTH_ID}')" ondblclick="${infoPrefix}Control.authorities.getInfo({})">{AUTH_ID}</td>
                       <td onclick="${infoPrefix}Control.authorities.setCurrent('{AUTH_ID}')" ondblclick="${infoPrefix}Control.authorities.getInfo({})">{AUTH_NM}</td>
                       <td onclick="${infoPrefix}Control.authorities.setCurrent('{AUTH_ID}')" ondblclick="${infoPrefix}Control.authorities.getInfo({})">{REG_DT}</td>
                    </tr>
                    </template>
                   	<template id="${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="${infoPrefix}PagingInfo" class="dataTables_info" role="status" aria-live="polite"></label>
	                 <ul id="${infoPrefix}Paging" class="pagination pagination-primary">
	                 </ul>
				</div>
				</div>
				<div style="width:49%; padding-top:.25em;">
<div class="nav-align-top">
  <ul class="nav nav-tabs" role="tablist">
    <li class="nav-item">
      <button type="button" onClick="${infoPrefix}Control.getLinkedList('users');" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-top-users" aria-controls="navs-top-users" aria-selected="true">사용자</button>
    </li>
    <li class="nav-item">
      <button type="button" onClick="${infoPrefix}Control.getLinkedList('actions');" class="nav-link" role="tab" data-bs-toggle="tab" data-bs-target="#navs-top-actions" aria-controls="navs-top-actions" aria-selected="false">기능그룹</button>
    </li>
  </ul>
  <div class="tab-content" style="padding:.6em 0;" id="${infoPrefix}RightInclude">
    <div class="tab-pane fade show active" id="navs-top-users" role="tabpanel">
    	<div class="ox-scroll">
    		<jsp:include page="user-list.jsp" />
    	</div>
    </div>
    <div class="tab-pane fade" id="navs-top-actions" role="tabpanel">
		<jsp:include page="actionGroup-list.jsp" />
    </div>
  </div>
</div>
				</div>
			</div>
		</div>
    </div>
              <!--/ Page Body -->
<script >
var ${infoPrefix}Control = new AuthorityControl();

${infoPrefix}Control.authorities.onSave = (resp) => {
	if (resp.saved) {
		dialog.alert("저장됐습니다.");
		dialog.close(${infoPrefix}Control.authorities.prefixed("dialog"));
		${infoPrefix}Control.authorities.query.fetchAll = true;
		${infoPrefix}Control.authorities.load(1);
	}
}
${infoPrefix}Control.authorities.onRemove = (selected, resp) => {
	if (resp.saved){
		${infoPrefix}Control.authorities.query.fetchAll = true;
		${infoPrefix}Control.authorities.load(1);
	}
}

function search${infoPrefix}s() {
	${infoPrefix}Control.authorities.query = {
		by:$("#${infoPrefix}-query [name='by']").val(),
		term:$("#${infoPrefix}-query [name='term']").val()
	};
	${infoPrefix}Control.authorities.query.fetchAll = true;
	${infoPrefix}Control.authorities.load(1);
}

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

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

${infoPrefix}Control.onAuthorityListChange = obj => {
	render${infoPrefix}List();

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

${infoPrefix}Control.onCurrentAuthorityChange = item => {
	$("#btnAddActions").prop("disabled", !item || ${infoPrefix}Control.authorities.isAdmin(item.data));
	$("#btnAddUsers").prop("disabled", !item || ${infoPrefix}Control.authorities.isImplicit(item.data));
	if (!item) return;
	
	let key = item.data.AUTH_ID;
	$("#${infoPrefix}List").setCurrentRow(key);
};

${infoPrefix}Control.onAuthoritySelect = selected => {
	let ${infoPrefix}List = ${infoPrefix}Control.authorities.dataset;
	let keys = selected.map(e => ${infoPrefix}List.getKey(e));
	$("#${infoPrefix}List input[type='checkbox']").each(function() {
		let checkbox = $(this);
		checkbox.prop("checked", keys.includes(checkbox.val()));
	});
	
	let builtIn = selected.filter(info => ${infoPrefix}Control.authorities.isBuiltIn(info)).length > 0;
	
	$("#btnRemove${infoPrefix}s").prop("disabled", keys.length < 1 || builtIn);
};

${userFunc}
${actionGroupFunc}

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

$(function(){
	${onload}
	${infoPrefix}Control.authorities.setData({
		${infoPrefix}List:${authorityList},
		${infoPrefix}Start:${authorityStart},
		${infoPrefix}Fetch:${authorityFetch},
		${infoPrefix}Total:${authorityTotal}
	});
});
//# sourceURL=authority-main.jsp
</script>
