api 모듈 수정
This commit is contained in:
@@ -118,7 +118,6 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
@@ -167,12 +166,12 @@
|
||||
|
||||
function renderNode(node, parentUl, depth) {
|
||||
const li = document.createElement('li');
|
||||
// 1depth와 2depth는 기본적으로 확장, 3depth는 축소
|
||||
// 1depth와 2depth는 기본적으로 확장, 3depth 이상은 접힘
|
||||
li.className = depth <= 1 ? '' : 'folding';
|
||||
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'tit';
|
||||
button.className = (!node.nodes || node.nodes.length === 0) ? '' : 'tit' + (depth === 1 ? ' onedepth' : depth === 2 ? ' twodepth' : '');
|
||||
button.setAttribute('data-id', node.id || '');
|
||||
button.setAttribute('data-parent-id', node.parentId || '');
|
||||
button.setAttribute('data-order-no', node.orderNo || '0');
|
||||
@@ -181,19 +180,15 @@
|
||||
textSpan.textContent = node.text || node.codeText;
|
||||
button.appendChild(textSpan);
|
||||
|
||||
button.onclick = function (e) {
|
||||
// 하위 노드가 있고, depth가 2 이하인 경우 토글 동작
|
||||
if (node.nodes && node.nodes.length > 0 && depth <= 2) {
|
||||
toggleNode(this);
|
||||
}
|
||||
// 항상 노드 선택 동작 수행
|
||||
button.onclick = function () {
|
||||
selectNode(this);
|
||||
};
|
||||
li.appendChild(button);
|
||||
|
||||
if (node.nodes && node.nodes.length > 0) {
|
||||
const childUl = document.createElement('ul');
|
||||
childUl.className = depth === 1 ? 'list-detail' : 'list-detail';
|
||||
// 중간 노드(depth >= 2)는 list-depth, 리프 노드의 하위는 list-detail
|
||||
childUl.className = node.nodes.some(child => child.nodes && child.nodes.length > 0) ? 'list-depth' : 'list-detail';
|
||||
li.appendChild(childUl);
|
||||
node.nodes.forEach(child => renderNode(child, childUl, depth + 1));
|
||||
}
|
||||
@@ -219,7 +214,7 @@
|
||||
// 상위 노드 확장
|
||||
let parent = currentNode.parentElement;
|
||||
while (parent && parent.tagName === 'LI') {
|
||||
parent.classList.add('open');
|
||||
parent.classList.remove('folding');
|
||||
parent = parent.parentElement.parentElement;
|
||||
}
|
||||
selectNode(currentNode);
|
||||
@@ -228,11 +223,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function toggleNode(button) {
|
||||
const li = button.parentElement;
|
||||
li.classList.toggle('open');
|
||||
}
|
||||
|
||||
function selectNode(button) {
|
||||
const treeWrap = document.querySelector('#tree');
|
||||
const f = document.formDto;
|
||||
@@ -241,15 +231,18 @@
|
||||
const previouslySelected = treeWrap.querySelector('button.selected');
|
||||
if (previouslySelected) {
|
||||
previouslySelected.classList.remove('selected');
|
||||
if (previouslySelected.classList.contains('tit')) {
|
||||
previouslySelected.parentNode.classList.add('folding');
|
||||
}
|
||||
}
|
||||
|
||||
// 새 노드 선택
|
||||
button.classList.add('selected');
|
||||
|
||||
if (button.classList.contains('tit')) {
|
||||
button.parentNode.classList.remove('folding');
|
||||
}
|
||||
// 노드 데이터 추출
|
||||
const data = {
|
||||
id: button.getAttribute('data-id'),
|
||||
text: button.querySelector('span:not(.toggle-icon)').textContent,
|
||||
text: button.querySelector('span').textContent,
|
||||
parentId: button.getAttribute('data-parent-id'),
|
||||
orderNo: parseInt(button.getAttribute('data-order-no')) || 0
|
||||
};
|
||||
@@ -280,20 +273,20 @@
|
||||
|
||||
const parentId = selectedButton.getAttribute('data-id');
|
||||
const parentLi = selectedButton.parentElement;
|
||||
let ul = parentLi.querySelector('.list-twodepth') || parentLi.querySelector('.list-threedepth');
|
||||
let ul = parentLi.querySelector('.list-depth') || parentLi.querySelector('.list-detail');
|
||||
const depth = parentLi.parentElement.classList.contains('list-onedepth') ? 2 : 3;
|
||||
|
||||
if (!ul) {
|
||||
ul = document.createElement('ul');
|
||||
ul.className = depth === 2 ? 'list-twodepth' : 'list-threedepth';
|
||||
ul.className = 'list-detail'; // 새로 추가된 노드는 기본적으로 list-detail
|
||||
parentLi.appendChild(ul);
|
||||
}
|
||||
|
||||
const li = document.createElement('li');
|
||||
// 새 노드는 기본적으로 표시 (depth에 따라 folding은 renderNode에서 처리)
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = depth === 2 ? 'tit twodepth' : '';
|
||||
button.classList.add('no-toggle');
|
||||
button.className = 'tit' + (depth === 2 ? ' twodepth' : '');
|
||||
button.setAttribute('data-id', 'code.new.temp');
|
||||
button.setAttribute('data-parent-id', parentId);
|
||||
button.setAttribute('data-order-no', '0');
|
||||
@@ -304,15 +297,11 @@
|
||||
|
||||
button.onclick = function () {
|
||||
selectNode(this);
|
||||
if (depth <= 2 && this.classList.contains('toggle-icon')) {
|
||||
toggleNode(this);
|
||||
}
|
||||
};
|
||||
li.appendChild(button);
|
||||
ul.appendChild(li);
|
||||
|
||||
parentLi.classList.add('open');
|
||||
selectedButton.classList.replace('no-toggle', 'toggle-icon');
|
||||
parentLi.classList.remove('folding');
|
||||
selectNode(button);
|
||||
}
|
||||
|
||||
@@ -353,7 +342,7 @@
|
||||
const selectedNode = treeWrap.querySelector('button.selected');
|
||||
|
||||
if (!selectedNode) {
|
||||
alert(/*[[#{operation.adminRole.save.choose.first}]]*/);
|
||||
alert('저장할 노드를 선택하세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -403,7 +392,7 @@
|
||||
|
||||
const info = {
|
||||
id: selectedNode.getAttribute('data-id'),
|
||||
text: selectedNode.querySelector('span:not(.toggle-icon)').textContent
|
||||
text: selectedNode.querySelector('span').textContent
|
||||
};
|
||||
|
||||
if (confirm("'" + info.text + "' 메뉴를 정말 삭제하시겠습니까?")) {
|
||||
@@ -411,7 +400,7 @@
|
||||
const parentLi = selectedNode.parentElement.parentElement.parentElement;
|
||||
selectedNode.parentElement.remove();
|
||||
if (!parentLi.querySelector('ul')) {
|
||||
parentLi.querySelector('.toggle-icon')?.classList.replace('toggle-icon', 'no-toggle');
|
||||
// 하위 노드가 없으면 버튼 스타일 유지
|
||||
}
|
||||
alert('삭제되었습니다.');
|
||||
cleanFormFields();
|
||||
@@ -447,7 +436,7 @@
|
||||
f.inUse.value = 'true';
|
||||
}
|
||||
|
||||
function move(dir) {
|
||||
function move(direction) {
|
||||
const treeWrap = document.querySelector('#tree');
|
||||
const selectedNode = treeWrap.querySelector('button.selected');
|
||||
if (!selectedNode) {
|
||||
@@ -470,14 +459,14 @@
|
||||
const currentLi = selectedNode.parentElement;
|
||||
let targetItem;
|
||||
|
||||
switch (dir) {
|
||||
switch (direction) {
|
||||
case 'up':
|
||||
targetItem = siblings.find((li, idx) => {
|
||||
const btn = li.querySelector('button');
|
||||
return btn !== selectedNode && parseInt(btn.getAttribute('data-order-no')) < info.orderNo && siblings[idx + 1] === currentLi;
|
||||
});
|
||||
if (!targetItem) {
|
||||
alert(/*[[#{operation.uri.move.cannot.before}]]*/);
|
||||
alert('더 이상 위로 이동할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -487,7 +476,7 @@
|
||||
return btn !== selectedNode && parseInt(btn.getAttribute('data-order-no')) > info.orderNo && siblings[idx - 1] === currentLi;
|
||||
});
|
||||
if (!targetItem) {
|
||||
alert(/*[[#{operation.uri.move.cannot.after}]]*/);
|
||||
alert('더 이상 아래로 이동할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -524,25 +513,33 @@
|
||||
function collapse() {
|
||||
const treeWrap = document.querySelector('#tree');
|
||||
const lis = treeWrap.querySelectorAll('li');
|
||||
lis.forEach(li => li.classList.remove('open'));
|
||||
treeWrap.querySelectorAll('.list-onedepth > li').forEach(li => li.classList.add('open'));
|
||||
lis.forEach(li => {
|
||||
li.classList.add('folding');
|
||||
});
|
||||
// 1depth는 기본적으로 열림
|
||||
treeWrap.querySelectorAll('.list-onedepth > li').forEach(li => {
|
||||
li.classList.remove('folding');
|
||||
});
|
||||
}
|
||||
|
||||
function expand() {
|
||||
const treeWrap = document.querySelector('#tree');
|
||||
const lis = treeWrap.querySelectorAll('li');
|
||||
lis.forEach(li => li.classList.add('open'));
|
||||
lis.forEach(li => {
|
||||
li.classList.remove('folding');
|
||||
});
|
||||
}
|
||||
|
||||
function searchNode() {
|
||||
const searchVal = $('#searchNode').val().trim();
|
||||
if (!searchVal) {
|
||||
alert('검색어를 입력하세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
const treeWrap = document.querySelector('#tree');
|
||||
const buttons = treeWrap.querySelectorAll('button');
|
||||
const matchingNode = Array.from(buttons).find(btn => btn.querySelector('span:not(.toggle-icon)').textContent.toLowerCase().includes(searchVal.toLowerCase()));
|
||||
const matchingNode = Array.from(buttons).find(btn => btn.querySelector('span').textContent.toLowerCase().includes(searchVal.toLowerCase()));
|
||||
|
||||
if (matchingNode) {
|
||||
const previouslySelected = treeWrap.querySelector('button.selected');
|
||||
@@ -551,10 +548,10 @@
|
||||
}
|
||||
matchingNode.classList.add('selected');
|
||||
matchingNode.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
let parent = matchingNode.parentElement;
|
||||
while (parent && parent.tagName === 'LI') {
|
||||
parent.classList.add('open');
|
||||
parent = parent.parentElement.parentElement;
|
||||
let parentLi = matchingNode.parentElement;
|
||||
while (parentLi && parentLi.tagName === 'LI') {
|
||||
parentLi.classList.remove('folding');
|
||||
parentLi = parentLi.parentElement.parentElement;
|
||||
}
|
||||
selectNode(matchingNode);
|
||||
} else {
|
||||
@@ -563,5 +560,4 @@
|
||||
}
|
||||
</script>
|
||||
</section>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user