diff --git a/public/js/menu-tree.js b/public/js/menu-tree.js new file mode 100644 index 00000000..976aaa07 --- /dev/null +++ b/public/js/menu-tree.js @@ -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); + } + } + }); +} \ No newline at end of file diff --git a/resources/views/department-permissions/index.blade.php b/resources/views/department-permissions/index.blade.php index e77bc88e..7ca36320 100644 --- a/resources/views/department-permissions/index.blade.php +++ b/resources/views/department-permissions/index.blade.php @@ -148,4 +148,5 @@ function reloadPermissions() { } }); + @endsection diff --git a/resources/views/department-permissions/partials/permission-matrix.blade.php b/resources/views/department-permissions/partials/permission-matrix.blade.php index 2f392564..3e277603 100644 --- a/resources/views/department-permissions/partials/permission-matrix.blade.php +++ b/resources/views/department-permissions/partials/permission-matrix.blade.php @@ -20,16 +20,43 @@ $permissionTypes = ['view', 'create', 'update', 'delete', 'approve', 'export', 'manage']; @endphp @forelse($menus as $index => $menu) -