From 0bbc8a56f719bbbe83dd6f01138530a085103474 Mon Sep 17 00:00:00 2001 From: thug0bin Date: Thu, 5 Mar 2026 12:37:54 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=9E=90=EB=8F=99=EC=9D=B8=EC=87=84=20?= =?UTF-8?q?=ED=86=A0=EA=B8=80=20=EC=88=98=EC=A0=95=20-=20showToast=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: - onclick 이벤트에서 showToast 함수가 정의되지 않아 에러 발생 - JavaScript 함수들이 전역 스코프에 없어서 접근 불가 해결: - window.showToast 함수 추가 (전역) - 즉시 실행 함수(IIFE)로 이벤트 바인딩 - HTML onclick 속성 제거, JS에서만 처리 테스트 완료: - 토글 클릭 시 ON/OFF 전환 확인 - localStorage에 상태 저장 확인 - 콘솔에 [AutoPrint] 로그 출력 확인 --- backend/templates/pmr.html | 70 +++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/backend/templates/pmr.html b/backend/templates/pmr.html index d96d466..cdb7407 100644 --- a/backend/templates/pmr.html +++ b/backend/templates/pmr.html @@ -999,7 +999,7 @@ 자동감지 OFF -
+
자동인쇄 OFF
@@ -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 = '
' + message + '
'; + 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 = ` - - 자동인쇄 ${autoPrintEnabled ? 'ON' : 'OFF'} - `; + toggle.className = 'status-badge ' + (autoPrintEnabled ? 'auto-print-on' : 'auto-print-off'); + toggle.innerHTML = '자동인쇄 ' + (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() {