fix: admin.html 스크립트 로딩 순서 오류 수정

Issue Fixed:
- ReferenceError: Can't find variable: initializeAdmin

Root Cause:
- initializeAdmin 함수가 정의되기 전에 API 스크립트의 onload에서 호출됨
- 스크립트 로딩 순서 문제로 함수 참조 오류 발생

Solution:
1. 스크립트 순서 재정렬
   - 공통 스크립트들을 먼저 로드
   - initializeAdmin 함수를 먼저 정의
   - API 스크립트를 마지막에 동적 로드

2. 에러 핸들링 추가
   - script.onerror 이벤트 추가
   - API 로드 실패 시 적절한 에러 메시지

Changes:
- 스크립트 로딩 순서 변경: 공통 스크립트 → 함수 정의 → API 동적 로드
- initializeAdmin 함수가 API 로드 전에 정의되도록 수정
- 스크립트 로드 실패 시 에러 핸들링 추가

Result:
 initializeAdmin 함수 정상 호출
 사용자 관리 페이지 정상 로드
 권한 설정 기능 정상 작동
This commit is contained in:
Hyungi Ahn
2025-10-25 09:55:04 +09:00
parent d821387e4b
commit 79b1524a42

View File

@@ -220,19 +220,6 @@
</main>
<!-- Scripts -->
<script>
const cacheBuster = Date.now() + Math.random() + Math.floor(Math.random() * 1000000);
const script = document.createElement('script');
script.src = `/static/js/api.js?v=20251025-2&cb=${cacheBuster}&t=${Date.now()}&r=${Math.random()}`;
script.setAttribute('cache-control', 'no-cache');
script.setAttribute('pragma', 'no-cache');
script.onload = function() {
console.log('✅ API 스크립트 로드 완료 (admin.html)');
// API 로드 후 초기화 시작
initializeAdmin();
};
document.head.appendChild(script);
</script>
<script src="/static/js/date-utils.js?v=20250917"></script>
<script src="/static/js/core/permissions.js?v=20251025"></script>
<script src="/static/js/components/common-header.js?v=20251025"></script>
@@ -678,6 +665,22 @@
saveBtn.innerHTML = '<i class="fas fa-save mr-2"></i>권한 저장';
}
});
// API 스크립트 동적 로딩
const cacheBuster = Date.now() + Math.random() + Math.floor(Math.random() * 1000000);
const script = document.createElement('script');
script.src = `/static/js/api.js?v=20251025-2&cb=${cacheBuster}&t=${Date.now()}&r=${Math.random()}`;
script.setAttribute('cache-control', 'no-cache');
script.setAttribute('pragma', 'no-cache');
script.onload = function() {
console.log('✅ API 스크립트 로드 완료 (admin.html)');
// API 로드 후 초기화 시작
initializeAdmin();
};
script.onerror = function() {
console.error('❌ API 스크립트 로드 실패');
};
document.head.appendChild(script);
</script>
</body>
</html>