function initSurveyListModule(moduleId) {
const moduleElement = document.getElementById(moduleId);
if (!moduleElement || moduleElement.classList.contains('initialized')) return;
const surveySection = moduleElement.querySelector('.survey-section');
const surveyGrid = moduleElement.querySelector('.survey-grid');
const modal = moduleElement.querySelector('.survey-modal');
const modalOverlay = modal.querySelector('.modal-overlay');
const modalClose = modal.querySelector('.modal-close');
const modalTitle = modal.querySelector('.modal-title');
const modalAuthor = modal.querySelector('.modal-author');
const modalDeadline = modal.querySelector('.modal-deadline');
const modalDescription = modal.querySelector('.modal-description');
const questionsCount = modal.querySelector('.questions-count');
const participantsCount = modal.querySelector('.participants-count');
const estimatedTime = modal.querySelector('.estimated-time');
const progressFill = modal.querySelector('.progress-fill');
const progressText = modal.querySelector('.progress-text');
const btnParticipate = modal.querySelector('.modal-footer .btn-participate');
const btnCancel = modal.querySelector('.btn-cancel');
// 설문 데이터 가져오기
const surveysData = JSON.parse(surveySection.dataset.surveys || '[]');
// 설문 카드 렌더링
function renderSurveyCards() {
if (!surveysData.length) return;
const cardsHTML = surveysData.map(survey => `
${survey.days_left}일 남음
${survey.created_by}
${survey.questions_count}개 질문
${formatNumber(survey.response_count)}명 참여
약 ${survey.questions_count}분
${survey.max_responses ? `
${formatNumber(survey.response_count)} / ${formatNumber(survey.max_responses)}명
` : ''}
`).join('');
surveyGrid.innerHTML = cardsHTML;
}
// 모달 열기
function openModal(surveyId) {
const survey = surveysData.find(s => s.id == surveyId);
if (!survey) return;
// 모달 내용 업데이트
modalTitle.textContent = survey.title;
modalAuthor.textContent = survey.created_by;
modalDeadline.textContent = `${survey.days_left}일 남음`;
modalDescription.textContent = survey.description || '설문에 대한 설명이 없습니다.';
questionsCount.textContent = `${survey.questions_count}개`;
participantsCount.textContent = `${formatNumber(survey.response_count)}명`;
estimatedTime.textContent = `${survey.questions_count}분`;
// 진행률 업데이트
if (survey.max_responses) {
progressFill.style.width = `${survey.progress}%`;
progressText.textContent = `${formatNumber(survey.response_count)} / ${formatNumber(survey.max_responses)}명 참여`;
modal.querySelector('.progress-section').style.display = 'block';
} else {
modal.querySelector('.progress-section').style.display = 'none';
}
// 참여하기 버튼 링크 설정
btnParticipate.href = `${window.location.origin}/theme/rd.lwd/survey_page.php?sv_id=${survey.id}`;
// 모달 표시
modal.classList.add('show');
document.body.style.overflow = 'hidden';
}
// 모달 닫기
function closeModal() {
modal.classList.remove('show');
document.body.style.overflow = '';
}
// 설문 공유
function shareSurvey(surveyId, title) {
const url = `${window.location.origin}/theme/rd.lwd/rb.custom/survey_form/survey_page.php?sv_id=${surveyId}`;
if (navigator.share) {
// Web Share API 지원시
navigator.share({
title: title,
text: '설문에 참여해보세요!',
url: url
}).catch(err => {
console.log('공유 취소:', err);
});
} else {
// 클립보드에 복사
if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(() => {
showNotification('설문 링크가 클립보드에 복사되었습니다!', 'success');
}).catch(() => {
// 클립보드 복사 실패시 프롬프트로 표시
prompt('설문 링크를 복사하세요:', url);
});
} else {
// 클립보드 API 미지원시 프롬프트로 표시
prompt('설문 링크를 복사하세요:', url);
}
}
}
// 알림 표시
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `survey-notification survey-notification-${type}`;
notification.innerHTML = `