refactor: 메뉴 트리 스크립트 공통화 및 디자인 통일
- public/js/menu-tree.js 공통 스크립트 생성 - 테이블(tr.menu-row) / div(.menu-item) 둘 다 지원 - toggleChildren, hideChildren, showChildren 함수 통합 - 권한 관리 페이지들 메뉴 트리 디자인 통일 - role-permissions, department-permissions, user-permissions - 폴더/파일 아이콘, 접기/펼치기 버튼, chevron 아이콘 - menu-row 클래스 및 data 속성 추가 - permission-analyze 접기/펼치기 기능 추가 - data-parent-id, data-depth 속성 추가 - 폴더 버튼 클릭으로 하위 메뉴 토글 - menus 페이지 스크립트 공통화 - 각 페이지 중복 코드 제거 및 공통 menu-tree.js 로드
This commit is contained in:
63
public/js/menu-tree.js
Normal file
63
public/js/menu-tree.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 메뉴 트리 공통 스크립트
|
||||
* - 부서 권한 관리 (department-permissions) - 테이블 기반
|
||||
* - 개인 권한 관리 (user-permissions) - 테이블 기반
|
||||
* - 권한 분석 (permission-analyze) - div 기반
|
||||
*/
|
||||
|
||||
// 자식 메뉴 접기/펼치기
|
||||
window.toggleChildren = function(menuId) {
|
||||
const button = document.querySelector(`.toggle-btn[data-menu-id="${menuId}"]`);
|
||||
if (!button) return;
|
||||
|
||||
const chevron = button.querySelector('.chevron-icon');
|
||||
if (!chevron) return;
|
||||
|
||||
const isCollapsed = chevron.classList.contains('rotate-[-90deg]');
|
||||
|
||||
if (isCollapsed) {
|
||||
// 펼치기
|
||||
chevron.classList.remove('rotate-[-90deg]');
|
||||
showChildren(menuId);
|
||||
} else {
|
||||
// 접기
|
||||
chevron.classList.add('rotate-[-90deg]');
|
||||
hideChildren(menuId);
|
||||
}
|
||||
};
|
||||
|
||||
// 자식 요소 선택자 (테이블: tr.menu-row, div: .menu-item)
|
||||
function getChildElements(parentId) {
|
||||
// 테이블 기반 (tr.menu-row)
|
||||
let children = document.querySelectorAll(`tr.menu-row[data-parent-id="${parentId}"]`);
|
||||
if (children.length > 0) return children;
|
||||
|
||||
// div 기반 (.menu-item)
|
||||
return document.querySelectorAll(`.menu-item[data-parent-id="${parentId}"]`);
|
||||
}
|
||||
|
||||
// 재귀적으로 자식 메뉴 숨기기
|
||||
function hideChildren(parentId) {
|
||||
const children = getChildElements(parentId);
|
||||
children.forEach(child => {
|
||||
child.style.display = 'none';
|
||||
const childId = child.getAttribute('data-menu-id');
|
||||
hideChildren(childId);
|
||||
});
|
||||
}
|
||||
|
||||
// 재귀적으로 직계 자식만 표시
|
||||
function showChildren(parentId) {
|
||||
const children = getChildElements(parentId);
|
||||
children.forEach(child => {
|
||||
child.style.display = '';
|
||||
const childId = child.getAttribute('data-menu-id');
|
||||
const childButton = child.querySelector(`.toggle-btn[data-menu-id="${childId}"]`);
|
||||
if (childButton) {
|
||||
const chevron = childButton.querySelector('.chevron-icon');
|
||||
if (chevron && !chevron.classList.contains('rotate-[-90deg]')) {
|
||||
showChildren(childId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user