fix: 자동인쇄 토글 수정 - showToast 함수 추가
문제: - onclick 이벤트에서 showToast 함수가 정의되지 않아 에러 발생 - JavaScript 함수들이 전역 스코프에 없어서 접근 불가 해결: - window.showToast 함수 추가 (전역) - 즉시 실행 함수(IIFE)로 이벤트 바인딩 - HTML onclick 속성 제거, JS에서만 처리 테스트 완료: - 토글 클릭 시 ON/OFF 전환 확인 - localStorage에 상태 저장 확인 - 콘솔에 [AutoPrint] 로그 출력 확인
This commit is contained in:
parent
0b17139daa
commit
0bbc8a56f7
@ -999,7 +999,7 @@
|
||||
<span class="status-dot"></span>
|
||||
자동감지 OFF
|
||||
</div>
|
||||
<div id="autoPrintToggle" class="status-badge auto-print-off" onclick="toggleAutoPrint()">
|
||||
<div id="autoPrintToggle" class="status-badge auto-print-off">
|
||||
<span class="status-dot"></span>
|
||||
자동인쇄 OFF
|
||||
</div>
|
||||
@ -2649,38 +2649,44 @@
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 자동인쇄 기능
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
let autoPrintEnabled = localStorage.getItem('pmr_auto_print') === 'true';
|
||||
var autoPrintEnabled = localStorage.getItem('pmr_auto_print') === 'true';
|
||||
|
||||
// 초기화
|
||||
function initAutoPrint() {
|
||||
updateAutoPrintIndicator();
|
||||
}
|
||||
|
||||
// 토글
|
||||
function toggleAutoPrint() {
|
||||
autoPrintEnabled = !autoPrintEnabled;
|
||||
localStorage.setItem('pmr_auto_print', autoPrintEnabled);
|
||||
updateAutoPrintIndicator();
|
||||
showToast(autoPrintEnabled ? '🖨️ 자동인쇄 ON' : '🖨️ 자동인쇄 OFF', autoPrintEnabled ? 'success' : 'info');
|
||||
}
|
||||
// 간단한 토스트 알림 (전역)
|
||||
window.showToast = function(message, type) {
|
||||
var container = document.getElementById('paaiToastContainer');
|
||||
if (!container) return;
|
||||
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'paai-toast';
|
||||
toast.style.background = type === 'success' ? 'linear-gradient(135deg, #10b981, #059669)' :
|
||||
type === 'error' ? 'linear-gradient(135deg, #ef4444, #dc2626)' :
|
||||
'linear-gradient(135deg, #6b7280, #4b5563)';
|
||||
|
||||
toast.innerHTML = '<div class="content"><div class="title">' + message + '</div></div>';
|
||||
toast.onclick = function() { toast.remove(); };
|
||||
|
||||
container.appendChild(toast);
|
||||
setTimeout(function() { toast.remove(); }, 3000);
|
||||
};
|
||||
|
||||
// 표시 업데이트
|
||||
function updateAutoPrintIndicator() {
|
||||
const toggle = document.getElementById('autoPrintToggle');
|
||||
if (toggle) {
|
||||
toggle.className = `status-badge ${autoPrintEnabled ? 'auto-print-on' : 'auto-print-off'}`;
|
||||
toggle.innerHTML = `
|
||||
<span class="status-dot"></span>
|
||||
자동인쇄 ${autoPrintEnabled ? 'ON' : 'OFF'}
|
||||
`;
|
||||
toggle.className = 'status-badge ' + (autoPrintEnabled ? 'auto-print-on' : 'auto-print-off');
|
||||
toggle.innerHTML = '<span class="status-dot"></span>자동인쇄 ' + (autoPrintEnabled ? 'ON' : 'OFF');
|
||||
}
|
||||
}
|
||||
|
||||
// PAAI 결과 인쇄
|
||||
async function printPaaiResult(preSerial, patientName, result) {
|
||||
if (!autoPrintEnabled) return;
|
||||
if (!autoPrintEnabled) {
|
||||
console.log('[AutoPrint] 비활성화됨');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[AutoPrint] 인쇄 요청:', preSerial);
|
||||
const response = await fetch('/pmr/api/paai/print', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
@ -2693,17 +2699,33 @@
|
||||
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
console.log('[AutoPrint] 인쇄 완료:', preSerial);
|
||||
console.log('[AutoPrint] 인쇄 완료');
|
||||
showToast('인쇄 완료: ' + patientName, 'success');
|
||||
} else {
|
||||
console.error('[AutoPrint] 인쇄 실패:', data.error);
|
||||
console.error('[AutoPrint] 실패:', data.error);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[AutoPrint] 오류:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 페이지 로드 시 초기화
|
||||
document.addEventListener('DOMContentLoaded', initAutoPrint);
|
||||
// 즉시 실행: 토글 이벤트 바인딩
|
||||
(function() {
|
||||
const toggle = document.getElementById('autoPrintToggle');
|
||||
if (toggle) {
|
||||
toggle.style.cursor = 'pointer';
|
||||
toggle.onclick = function() {
|
||||
autoPrintEnabled = !autoPrintEnabled;
|
||||
localStorage.setItem('pmr_auto_print', autoPrintEnabled ? 'true' : 'false');
|
||||
updateAutoPrintIndicator();
|
||||
showToast(autoPrintEnabled ? '자동인쇄 ON' : '자동인쇄 OFF', autoPrintEnabled ? 'success' : 'info');
|
||||
console.log('[AutoPrint] 토글:', autoPrintEnabled);
|
||||
};
|
||||
// 초기 상태 표시
|
||||
updateAutoPrintIndicator();
|
||||
console.log('[AutoPrint] 초기화 완료, 상태:', autoPrintEnabled);
|
||||
}
|
||||
})();
|
||||
|
||||
// 알림 소리
|
||||
function playTriggerSound() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user