merge master into develop - CscListRForm.jsp FAQ 아코디언 버그 수정
This commit is contained in:
@@ -0,0 +1,921 @@
|
||||
var Intakchl = (function() {
|
||||
"use strict";
|
||||
|
||||
const baseUrl = '/sopmal/bnft';
|
||||
let bnfInnb;
|
||||
let screenInfo;
|
||||
let productList;
|
||||
let selectedProducts = [];
|
||||
const calendarDays = document.getElementById('calendarDays');
|
||||
const currentMonthElement = document.getElementById('currentMonth');
|
||||
const prevWeekButton = document.getElementById('prevWeek');
|
||||
const nextWeekButton = document.getElementById('nextWeek');
|
||||
|
||||
let count = 1;
|
||||
let currentDate = new Date();
|
||||
let focusedDate = null;
|
||||
const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
|
||||
|
||||
|
||||
|
||||
function init(info, products) {
|
||||
bnfInnb = getUrlParameter('bnfInnb');
|
||||
count = info.dailyIntakeCount || 1;
|
||||
screenInfo = info || {};
|
||||
productList = products || [];
|
||||
loadSelectedProducts();
|
||||
initModal();
|
||||
bindEvents();
|
||||
updateDisplay();
|
||||
showTab('purchased-tab');
|
||||
initEventListeners();
|
||||
// 현재 페이지가 섭취 챌린지 메인 페이지인 경우에만 이벤트 리스너 추가
|
||||
if (isIntakeChallengeMainPage()) {
|
||||
addCalendarEventListeners();
|
||||
loadDailyIntakeData(formatDate(currentDate));
|
||||
loadIntakeChallengeDashboard(); // 새로운 함수 호출 추가
|
||||
updateCalendar();
|
||||
} else if (isIntakchlDailyRecordMainPage) {
|
||||
loadStatsDateClasses();
|
||||
loadCurrentChallengeProducts();
|
||||
}
|
||||
|
||||
if (window.location.hash) {
|
||||
var modalId = window.location.hash.replace('#', '');
|
||||
openModal({ preventDefault: function(){}, target: $('[data-micromodal-trigger="' + modalId + '"]')[0] });
|
||||
}
|
||||
|
||||
// MicroModal 초기화
|
||||
MicroModal.init({
|
||||
disableScroll: true,
|
||||
awaitCloseAnimation: true,
|
||||
});
|
||||
}
|
||||
|
||||
function initModal() {
|
||||
MicroModal.init({
|
||||
disableScroll: true,
|
||||
awaitCloseAnimation: true,
|
||||
});
|
||||
}
|
||||
|
||||
function navigateToAddProduct() {
|
||||
const url = `${baseUrl}/intakchlMain?bnfInnb=${bnfInnb}`;
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
function getUrlParameter(name) {
|
||||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
||||
var results = regex.exec(location.search);
|
||||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
function isIntakeChallengeMainPage() {
|
||||
// 현재 페이지가 섭취 챌린지 메인 페이지인지 확인하는 로직
|
||||
// 예: URL 체크, 특정 요소의 존재 여부 확인 등
|
||||
return window.location.pathname.includes('/intakchlDailyRecordMain');
|
||||
}
|
||||
|
||||
function isIntakchlDailyRecordMainPage() {
|
||||
// 현재 페이지가 섭취 통계 페이지인지 확인하는 로직
|
||||
// 예: URL 체크, 특정 요소의 존재 여부 확인 등
|
||||
return window.location.pathname.includes('/intakchlMileageSummary');
|
||||
}
|
||||
|
||||
function isintakchlChallengeSettingsPage() {
|
||||
// 현재 페이지가 섭취 통계 페이지인지 확인하는 로직
|
||||
// 예: URL 체크, 특정 요소의 존재 여부 확인 등
|
||||
return window.location.pathname.includes('/intakchlChallengeSettings');
|
||||
}
|
||||
|
||||
function goToProductDetail(bnfNtkInnb) {
|
||||
window.location.href = baseUrl + '/intakchlProductDetail?bnfNtkInnb=' + bnfNtkInnb;
|
||||
}
|
||||
|
||||
function goToAddProduct() {
|
||||
window.location.href = baseUrl + '/intakchlMain?bnfInnb=' + bnfInnb;
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
$('#addToChallengeBtn').off('click');
|
||||
|
||||
$('.headerTab__item').on('click', function() {
|
||||
showTab($(this).attr('id'));
|
||||
});
|
||||
|
||||
$('#addToChallengeBtn').on('click', addToChallenge);
|
||||
$('#continueAdding').on('click', continueAdding);
|
||||
$('#startChallenge').on('click', startChallenge);
|
||||
|
||||
$('.challenge_checklist input[type="checkbox"]').on('change', function() {
|
||||
updateSelectedProductCount();
|
||||
});
|
||||
|
||||
$('.btn_add_challenge').on('click', function() {
|
||||
window.location.href = baseUrl + '/intakeChallengeAdd?bnfInnb=' + screenInfo.bnfInnb;
|
||||
});
|
||||
|
||||
$('#prevWeek').on('click', function() {
|
||||
updateCalendar(-7);
|
||||
});
|
||||
|
||||
$('#nextWeek').on('click', function() {
|
||||
updateCalendar(7);
|
||||
});
|
||||
|
||||
$(document).on('click', '.calendar-days .day', function() {
|
||||
handleDateClick(new Date($(this).data('date')));
|
||||
});
|
||||
|
||||
// 섭취 버튼 클릭 이벤트 추가
|
||||
$(document).on('click', '.drugCheck span', function() {
|
||||
updateIntakeStatus($(this));
|
||||
});
|
||||
|
||||
$('#save_toast').off('click').on('click', updateDailyIntakeAndMemo);
|
||||
|
||||
$('.btn_add_challenge').on('click', navigateToAddProduct);
|
||||
|
||||
$('.microModal__btn-primary').on('click', deleteProduct);
|
||||
|
||||
// 섭취 카운트 관련 이벤트
|
||||
$('#decrease').on('click', decreaseCount);
|
||||
$('#increase').on('click', increaseCount);
|
||||
|
||||
// 모달 관련 이벤트
|
||||
$('.fullscreen-trigger').on('click', openModal);
|
||||
$('.microModal .microModal__close').on('click', closeModal);
|
||||
window.addEventListener('popstate', handlePopState);
|
||||
|
||||
$('.header__toBack__btn').on('click', function() {
|
||||
history.back();
|
||||
});
|
||||
$('#modal-1 .microModal__btn-primary').on('click', deleteProduct);
|
||||
|
||||
}
|
||||
|
||||
document.getElementById('statsButton').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
window.location.href = '/sopmal/bnft/intakchlMileageSummary';
|
||||
});
|
||||
|
||||
document.getElementById('settingsButton').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
window.location.href = '/sopmal/bnft/intakchlChallengeSettings';
|
||||
});
|
||||
|
||||
function decreaseCount() {
|
||||
if (count > 1) {
|
||||
count--;
|
||||
updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
function increaseCount() {
|
||||
if (count < 10) {
|
||||
count++;
|
||||
updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
function updateDisplay() {
|
||||
$('#count').text(count);
|
||||
$('#decrease').prop('disabled', count === 1);
|
||||
$('#increase').prop('disabled', count === 10);
|
||||
}
|
||||
|
||||
function openModal(e) {
|
||||
e.preventDefault();
|
||||
var modalId = $(this).attr('data-micromodal-trigger');
|
||||
MicroModal.show(modalId, {
|
||||
onShow: function (modal) {
|
||||
if (window.location.hash !== '#' + modalId) {
|
||||
window.history.pushState({ modal: 'open' }, '', '#' + modalId);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
var modalId = $(this).closest('.microModal').attr('id');
|
||||
document.body.style.overflow = '';
|
||||
MicroModal.close(modalId);
|
||||
window.history.replaceState({}, '', window.location.pathname);
|
||||
}
|
||||
|
||||
function handlePopState(event) {
|
||||
var modalId = window.location.hash.replace('#', '');
|
||||
if (modalId) {
|
||||
closeModal();
|
||||
} else {
|
||||
$('.microModal').each(function () {
|
||||
MicroModal.close($(this).attr('id'));
|
||||
});
|
||||
}
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
|
||||
function deleteProduct() {
|
||||
const bnfNtkInnb = $('#bnfNtkInnb').val();
|
||||
$.ajax({
|
||||
url: baseUrl + '/deleteIntakeChallengeProduct',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfNtkInnb: bnfNtkInnb,
|
||||
mbrInnb: getMbrInnb(),
|
||||
mbrDvCd: getMbrDvCd()
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
alert('제품이 삭제되었습니다.');
|
||||
window.location.href = baseUrl + '/intakchlMain?bnfInnb=' + bnfInnb;
|
||||
} else {
|
||||
alert('삭제에 실패했습니다: ' + result.message);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('서버 오류가 발생했습니다. 다시 시도해 주세요.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateDailyIntakeAndMemo() {
|
||||
const productData = {
|
||||
bnfNtkInnb: $('#bnfNtkInnb').val(),
|
||||
intakeStatus: $('input[name="intakeStatus"]:checked').val(),
|
||||
dailyIntakeCount: count,
|
||||
memo: $('.white_textarea').val()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/updateDailyIntakeAndMemo',
|
||||
method: 'POST',
|
||||
data: JSON.stringify(productData),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
showToast(result.message);
|
||||
} else {
|
||||
alert(result.message);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('서버 오류가 발생했습니다. 다시 시도해 주세요.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showToast(message) {
|
||||
const $toastPop = $('#toastPop');
|
||||
$toastPop.find('p').text(message);
|
||||
$toastPop.addClass('show');
|
||||
|
||||
setTimeout(function() {
|
||||
$toastPop.removeClass('show');
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function updateIntakeStatus(element) {
|
||||
const productContainer = element.closest('.challengeProduct');
|
||||
const bnfNtkInnb = productContainer.data('bnf-ntk-innb');
|
||||
const goodsInnb = productContainer.data('goods-innb');
|
||||
const targetIntakeCount = productContainer.data('target-intake-count');
|
||||
const currentIntakeCount = productContainer.find('.drug_on').length;
|
||||
const newStatus = element.hasClass('drug_off') ? 'Y' : 'N';
|
||||
|
||||
// 현재 선택된 날짜 가져오기
|
||||
const selectedDate = formatDate(currentDate);
|
||||
|
||||
// 섭취 완료 시 목표 섭취 횟수를 초과하는지 확인
|
||||
if (newStatus === 'Y' && currentIntakeCount >= targetIntakeCount) {
|
||||
alert('오늘의 목표 섭취 횟수를 이미 달성했습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/updateIntakeStatus',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
bnfNtkInnb: bnfNtkInnb,
|
||||
intakeStatus: newStatus,
|
||||
goodsInnb: goodsInnb,
|
||||
currentIntakeCount: currentIntakeCount,
|
||||
targetIntakeCount: targetIntakeCount,
|
||||
mbrInnb: getMbrInnb(),
|
||||
mbrDvCd: getMbrDvCd(),
|
||||
selectedDate: selectedDate // 추가된 부분
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
const updatedProduct = result.updatedProductInfo.find(p => p.goodsInnb === goodsInnb);
|
||||
if (updatedProduct) {
|
||||
updateProductUI(productContainer, updatedProduct);
|
||||
}
|
||||
updateTotalIntakeUI(result.updatedTotalInfo);
|
||||
checkAndAwardMileage(); // 섭취 상태 업데이트 후 마일리지 적립 확인
|
||||
} else {
|
||||
alert(result.message || '상태 업데이트에 실패했습니다.');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX 요청 실패:', error);
|
||||
alert('서버 오류가 발생했습니다. 다시 시도해 주세요.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkAndAwardMileage() {
|
||||
$.ajax({
|
||||
url: baseUrl + '/awardIntakeChallengesMileage',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
mbrInnb: getMbrInnb(),
|
||||
mbrDvCd: getMbrDvCd()
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
showMileageAwardMessage(result.awardedAmount);
|
||||
} else if (result.message !== "일일 섭취 목표를 달성하지 못했습니다.") {
|
||||
// 목표 미달성이 아닌 다른 이유로 실패한 경우에만 메시지 표시
|
||||
alert(result.message);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('마일리지 지급 요청 실패:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showMileageAwardMessage(amount) {
|
||||
$('.topupPoint span').html(`<i class="ico_mile"></i><b>마일리지 ${amount}원</b> 적립완료!`);
|
||||
}
|
||||
|
||||
function updateMileageMessage(percentage) {
|
||||
if (percentage < 100) {
|
||||
$('.topupPoint span').html(`오늘의 섭취기록 100% 도달시<i class="ico_mile"></i><b>마일리지 10원</b>적립`);
|
||||
}
|
||||
// 100% 도달 시 메시지는 showMileageAwardMessage 함수에서 처리됩니다.
|
||||
}
|
||||
|
||||
// 개별 제품 UI 업데이트 함수
|
||||
function updateProductUI(productContainer, updatedInfo) {
|
||||
const drugCheckContainer = productContainer.find('.drugCheck');
|
||||
drugCheckContainer.empty();
|
||||
|
||||
for (let i = 0; i < updatedInfo.targetIntakeCount; i++) {
|
||||
const className = i < updatedInfo.dailyIntakeCount ? 'drug_on' : 'drug_off';
|
||||
const text = i < updatedInfo.dailyIntakeCount ? '섭취완료' : '섭취미완료';
|
||||
drugCheckContainer.append(`<span class="${className}">${text}</span>`);
|
||||
}
|
||||
|
||||
productContainer.data('target-intake-count', updatedInfo.targetIntakeCount);
|
||||
productContainer.find('.target-count').text(updatedInfo.targetIntakeCount);
|
||||
}
|
||||
|
||||
// 전체 섭취 현황 UI 업데이트 함수
|
||||
function updateTotalIntakeUI(totalInfo) {
|
||||
updateProgressBar(totalInfo.totalDailyIntakeRatio);
|
||||
updateMileageMessage(totalInfo.totalDailyIntakeRatio);
|
||||
}
|
||||
|
||||
function showTab(tabId) {
|
||||
$('.headerTab__item').removeClass('active');
|
||||
$('#' + tabId).addClass('active');
|
||||
$('.challenge_checklist').hide();
|
||||
$('.challenge_checklist.' + tabId.replace('-tab', '')).show();
|
||||
}
|
||||
|
||||
function addToChallenge() {
|
||||
var newSelectedProducts = $('.challenge_checklist input[type="checkbox"]:checked').map(function() {
|
||||
return {
|
||||
goodsInnb: $(this).val(),
|
||||
sopmalCd: "NC"
|
||||
};
|
||||
}).get();
|
||||
|
||||
if (newSelectedProducts.length === 0) {
|
||||
alert('선택한 제품이 없습니다. 제품을 선택해 주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
selectedProducts = selectedProducts.concat(newSelectedProducts);
|
||||
saveSelectedProducts();
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/addSelectedProducts',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: screenInfo.bnfInnb,
|
||||
products: newSelectedProducts
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
MicroModal.show('modal-1');
|
||||
} else {
|
||||
alert(response.message || '제품 추가에 실패했습니다.');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('서버 오류가 발생했습니다. 다시 시도해 주세요.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function continueAdding() {
|
||||
MicroModal.close('modal-1');
|
||||
$('.challenge_checklist input[type="checkbox"]').prop('checked', false);
|
||||
updateSelectedProductCount();
|
||||
}
|
||||
|
||||
function startChallenge() {
|
||||
window.location.href = baseUrl + '/IntakchlDailyRecordMain?bnfInnb=' + screenInfo.bnfInnb;
|
||||
}
|
||||
|
||||
function updateSelectedProductCount() {
|
||||
var count = $('.challenge_checklist input[type="checkbox"]:checked').length;
|
||||
$('#selectedCount').text(count);
|
||||
}
|
||||
|
||||
function saveSelectedProducts() {
|
||||
localStorage.setItem('selectedProducts', JSON.stringify(selectedProducts));
|
||||
}
|
||||
|
||||
function loadSelectedProducts() {
|
||||
var storedProducts = localStorage.getItem('selectedProducts');
|
||||
if (storedProducts) {
|
||||
selectedProducts = JSON.parse(storedProducts);
|
||||
selectedProducts.forEach(function(productId) {
|
||||
$('.challenge_checklist input[value="' + productId.goodsInnb + '"]').prop('checked', true);
|
||||
});
|
||||
updateSelectedProductCount();
|
||||
}
|
||||
}
|
||||
|
||||
//캘린더 스크립트
|
||||
function updateCalendar() {
|
||||
calendarDays.innerHTML = '';
|
||||
currentMonthElement.textContent = `${currentDate.getFullYear()}년 ${currentDate.getMonth() + 1}월`;
|
||||
|
||||
for (let i = -3; i <= 3; i++) {
|
||||
const date = new Date(currentDate);
|
||||
date.setDate(currentDate.getDate() + i);
|
||||
|
||||
const dayElement = document.createElement('div');
|
||||
dayElement.classList.add('day');
|
||||
if (i === 0) dayElement.classList.add('center');
|
||||
if (date.toDateString() === new Date().toDateString()) {
|
||||
dayElement.classList.add('today');
|
||||
}
|
||||
if (focusedDate && date.toDateString() === focusedDate.toDateString()) {
|
||||
dayElement.classList.add('focused');
|
||||
}
|
||||
|
||||
const dayNameElement = document.createElement('div');
|
||||
dayNameElement.classList.add('day-name');
|
||||
dayNameElement.textContent = dayNames[date.getDay()];
|
||||
|
||||
const dayNumberElement = document.createElement('div');
|
||||
dayNumberElement.classList.add('day-number');
|
||||
dayNumberElement.textContent = date.getDate();
|
||||
|
||||
dayElement.appendChild(dayNameElement);
|
||||
dayElement.appendChild(dayNumberElement);
|
||||
dayElement.addEventListener('click', () => handleDateClick(date));
|
||||
calendarDays.appendChild(dayElement);
|
||||
}
|
||||
}
|
||||
|
||||
function handleDateClick(date) {
|
||||
currentDate = new Date(date); // 이 줄을 추가
|
||||
focusedDate = date;
|
||||
updateCalendar();
|
||||
loadDailyIntakeData(formatDate(date));
|
||||
}
|
||||
|
||||
function loadDailyIntakeData(dateStr) {
|
||||
$.ajax({
|
||||
url: baseUrl + '/selectDailyTotalIntakeRecord',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
selectedDate: dateStr,
|
||||
mbrInnb: getMbrInnb(), // 회원 정보 추가
|
||||
mbrDvCd: getMbrDvCd() // 회원 구분 코드 추가
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
if (response.resBody && response.resBody.result) {
|
||||
var result = JSON.parse(response.resBody.result);
|
||||
if (result.dailyTotalIntakeRecord) {
|
||||
updateIntakeUI(result.dailyTotalIntakeRecord, result.dailyIntakeRecordsDetail);
|
||||
} else {
|
||||
console.error('데이터 로드 실패:', result.message);
|
||||
}
|
||||
} else {
|
||||
console.error('잘못된 응답 형식:', response);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX 요청 실패:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateIntakeUI(totalData, detailData) {
|
||||
updateProgressBar(totalData.totalDailyIntakeRatio);
|
||||
|
||||
const container = $('#challengeProductContainer');
|
||||
container.empty();
|
||||
|
||||
detailData.forEach(function(product) {
|
||||
const productElement = createProductElement(product);
|
||||
container.append(productElement);
|
||||
});
|
||||
}
|
||||
|
||||
// createProductElement 함수 수정
|
||||
function createProductElement(product) {
|
||||
const productHtml = `
|
||||
<div class="challengeProduct" data-bnf-ntk-innb="${product.bnfNtkInnb}" data-goods-innb="${product.goodsInnb}" data-target-intake-count="${product.targetIntakeCount}">
|
||||
<a href="#">
|
||||
<div class="thum"><img src="../resources/images/event/discount_thum3.png" alt="${product.goodsNm}"></div>
|
||||
<div class="cpTit">
|
||||
<p class="tit">${product.goodsNm}</p>
|
||||
<p class="dayCheck">1일 <span class="target-count">${product.targetIntakeCount}</span>회</p>
|
||||
</div>
|
||||
<div class="drugCheck">
|
||||
${createIntakeButtons(product.dailyIntakeCount, product.targetIntakeCount)}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
return $(productHtml);
|
||||
}
|
||||
|
||||
|
||||
function formatDate(date) {
|
||||
var d = new Date(date),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
day = '' + d.getDate(),
|
||||
year = d.getFullYear();
|
||||
|
||||
if (month.length < 2) month = '0' + month;
|
||||
if (day.length < 2) day = '0' + day;
|
||||
|
||||
return [year, month, day].join('-');
|
||||
}
|
||||
|
||||
function createIntakeButtons(dailyIntakeCount, targetIntakeCount) {
|
||||
let buttons = '';
|
||||
for (let i = 0; i < (targetIntakeCount || 1); i++) {
|
||||
const className = i < dailyIntakeCount ? 'drug_on' : 'drug_off';
|
||||
const text = i < dailyIntakeCount ? '섭취완료' : '섭취미완료';
|
||||
buttons += `<span class="${className}">${text}</span>`;
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
function updateProgressBar(percentage) {
|
||||
percentage = Math.round(percentage || 0);
|
||||
$('.challengeBar-container .per').css('width', percentage + '%');
|
||||
$('.challengeBar-container .per-txt').text(percentage + '%');
|
||||
updateMileageMessage(percentage);
|
||||
}
|
||||
|
||||
function addCalendarEventListeners() {
|
||||
if (prevWeekButton && nextWeekButton) {
|
||||
prevWeekButton.addEventListener('click', () => {
|
||||
currentDate.setDate(currentDate.getDate() - 7);
|
||||
updateCalendar();
|
||||
});
|
||||
|
||||
nextWeekButton.addEventListener('click', () => {
|
||||
currentDate.setDate(currentDate.getDate() + 7);
|
||||
updateCalendar();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 회원 정보를 가져오는 함수 (예시)
|
||||
function getMbrInnb() {
|
||||
// 실제 구현에서는 세션 스토리지나 다른 방법으로 회원 정보를 가져와야 합니다.
|
||||
return localStorage.getItem('mbrInnb') || '';
|
||||
}
|
||||
|
||||
function getMbrDvCd() {
|
||||
// 실제 구현에서는 세션 스토리지나 다른 방법으로 회원 구분 코드를 가져와야 합니다.
|
||||
return localStorage.getItem('mbrDvCd') || '';
|
||||
}
|
||||
|
||||
function loadIntakeChallengeDashboard() {
|
||||
$.ajax({
|
||||
url: baseUrl + '/getIntakechallengeDashboard',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
mbrInnb: getMbrInnb(),
|
||||
mbrDvCd: getMbrDvCd()
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
updateDashboardUI(result);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('대시보드 로드 실패:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateDashboardUI(dashboardData) {
|
||||
// 연속 성공일 업데이트
|
||||
$('.inTit b').text(dashboardData.consecutiveSuccessDays);
|
||||
|
||||
// 누적 보상 정보 업데이트
|
||||
$('.reward01').text(formatNumber(dashboardData.accumulatedRewards.dailyReward) + '원');
|
||||
$('.reward02').text(formatNumber(dashboardData.accumulatedRewards.consecutiveBonus) + '원');
|
||||
$('.reward03').text(formatNumber(dashboardData.accumulatedRewards.couponCount) + '개');
|
||||
|
||||
// 월간 챌린지 현황 업데이트
|
||||
updateMonthlyChallengeSummary(dashboardData.monthlyChallengeSummary);
|
||||
}
|
||||
|
||||
function updateMonthlyChallengeSummary(summary) {
|
||||
const statsContainer = $('#stats-dates');
|
||||
statsContainer.empty();
|
||||
|
||||
summary.forEach(day => {
|
||||
const dayElement = $('<div>').addClass('day ' + day.status);
|
||||
dayElement.text(new Date(day.challengeDate).getDate());
|
||||
statsContainer.append(dayElement);
|
||||
});
|
||||
}
|
||||
|
||||
function formatNumber(num) {
|
||||
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
|
||||
function updateMonthlySummary(monthlySummary) {
|
||||
const statsContainer = $('#stats-dates');
|
||||
statsContainer.empty();
|
||||
|
||||
monthlySummary.forEach(day => {
|
||||
const dayElement = $('<div>').addClass('day ' + day.status);
|
||||
dayElement.text(new Date(day.challengeDate).getDate());
|
||||
statsContainer.append(dayElement);
|
||||
});
|
||||
}
|
||||
// 섭취통계 시작
|
||||
const statsMonthNames = ["1월", "2월", "3월", "4월", "5월", "6월",
|
||||
"7월", "8월", "9월", "10월", "11월", "12월"];
|
||||
|
||||
let statsCurrentDate = new Date();
|
||||
const calendarContainer = document.getElementById('stats-dates');
|
||||
let isLoading = false;
|
||||
|
||||
//진행중인 상황 객체
|
||||
let statsDateClasses = {};
|
||||
|
||||
// statsDateClasses 부분을 초기화하는 함수 추가
|
||||
function loadStatsDateClasses() {
|
||||
$.ajax({
|
||||
url: baseUrl + '/getStatsDateClasses',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
mbrInnb: getMbrInnb(),
|
||||
mbrDvCd: getMbrDvCd()
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
console.log("Loaded stats date classes:", result.data); // 로드된 데이터 확인
|
||||
statsDateClasses = result.data;
|
||||
renderStatsCalendar(statsCurrentDate);
|
||||
} else {
|
||||
console.error('Failed to load stats date classes:', result.message);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderStatsCalendar(date, position = 'bottom') {
|
||||
const statsDatesElement = document.getElementById('stats-dates');
|
||||
|
||||
const statsCurrentYear = date.getFullYear();
|
||||
const statsCurrentMonth = date.getMonth();
|
||||
|
||||
const monthYearText = `${statsMonthNames[statsCurrentMonth]} ${statsCurrentYear}`;
|
||||
|
||||
console.log(1);
|
||||
if (!statsDatesElement.innerHTML.includes(monthYearText)) {
|
||||
const statsFirstDay = new Date(statsCurrentYear, statsCurrentMonth, 1).getDay();
|
||||
const statsLastDate = new Date(statsCurrentYear, statsCurrentMonth + 1, 0).getDate();
|
||||
|
||||
const today = new Date();
|
||||
const isCurrentMonth = today.getFullYear() === statsCurrentYear && today.getMonth() === statsCurrentMonth;
|
||||
const todayDate = today.getDate();
|
||||
|
||||
const monthContainer = document.createElement('div');
|
||||
monthContainer.classList.add('month-container');
|
||||
|
||||
const monthHeader = document.createElement('div');
|
||||
monthHeader.classList.add('month-header');
|
||||
monthHeader.textContent = monthYearText;
|
||||
monthContainer.appendChild(monthHeader);
|
||||
|
||||
const daysRow = document.createElement('div');
|
||||
daysRow.classList.add('stats-days');
|
||||
const days = ["일", "월", "화", "수", "목", "금", "토"];
|
||||
days.forEach(day => {
|
||||
const dayElement = document.createElement('div');
|
||||
dayElement.textContent = day;
|
||||
daysRow.appendChild(dayElement);
|
||||
});
|
||||
monthContainer.appendChild(daysRow);
|
||||
|
||||
const datesGrid = document.createElement('div');
|
||||
datesGrid.classList.add('dates-grid');
|
||||
console.log(2);
|
||||
|
||||
for (let i = 0; i < statsFirstDay; i++) {
|
||||
const statsEmptyCell = document.createElement('div');
|
||||
datesGrid.appendChild(statsEmptyCell);
|
||||
}
|
||||
console.log(3);
|
||||
|
||||
for (let statsDate = 1; statsDate <= statsLastDate; statsDate++) {
|
||||
const statsDateElement = document.createElement('div');
|
||||
const dateSpan = document.createElement('span');
|
||||
dateSpan.textContent = statsDate;
|
||||
statsDateElement.appendChild(dateSpan);
|
||||
|
||||
const fullDate = `${statsCurrentYear}-${String(statsCurrentMonth + 1).padStart(2, '0')}-${String(statsDate).padStart(2, '0')}`;
|
||||
|
||||
// 콘솔 로그 추가
|
||||
console.log(`Checking date: ${fullDate}`);
|
||||
if (statsDateClasses[fullDate]) {
|
||||
console.log(`Applying class '${statsDateClasses[fullDate]}' to date ${fullDate}`); // 클래스 적용 확인
|
||||
statsDateElement.classList.add(statsDateClasses[fullDate]);
|
||||
}
|
||||
|
||||
if (isCurrentMonth && statsDate === todayDate) {
|
||||
statsDateElement.classList.add('today');
|
||||
}
|
||||
datesGrid.appendChild(statsDateElement);
|
||||
}
|
||||
|
||||
monthContainer.appendChild(datesGrid);
|
||||
console.log(4);
|
||||
|
||||
if (position === 'top') {
|
||||
statsDatesElement.prepend(monthContainer);
|
||||
} else {
|
||||
statsDatesElement.appendChild(monthContainer);
|
||||
}
|
||||
console.log(5);
|
||||
|
||||
hideAfterStatsDone(datesGrid);
|
||||
}
|
||||
}
|
||||
|
||||
function loadPreviousMonth() {
|
||||
const newDate = new Date(statsCurrentDate.getFullYear(), statsCurrentDate.getMonth() - 1, 1);
|
||||
renderStatsCalendar(newDate, 'top');
|
||||
statsCurrentDate = newDate;
|
||||
}
|
||||
|
||||
function loadNextMonth() {
|
||||
const newDate = new Date(statsCurrentDate.getFullYear(), statsCurrentDate.getMonth() + 1, 1);
|
||||
renderStatsCalendar(newDate, 'bottom');
|
||||
statsCurrentDate = newDate;
|
||||
}
|
||||
|
||||
function hideAfterStatsDone(datesGrid) {
|
||||
const statsDoneElements = datesGrid.querySelectorAll('.stats_done');
|
||||
statsDoneElements.forEach((element) => {
|
||||
const nextElement = element.nextElementSibling;
|
||||
if (nextElement && !nextElement.classList.contains('stats_done') && !nextElement.classList.contains('stats_30done')) {
|
||||
element.classList.add('hide-after');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//섭취완료 스크립트
|
||||
document.addEventListener('click', function(event) {
|
||||
if (event.target.classList.contains('drug_off')) {
|
||||
event.preventDefault();
|
||||
|
||||
event.target.classList.remove('drug_off');
|
||||
event.target.classList.add('drug_on');
|
||||
event.target.textContent = '섭취완료';
|
||||
|
||||
// 섭취 완료 후 클릭 이벤트 제거
|
||||
event.target.style.pointerEvents = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
function loadCurrentChallengeProducts() {
|
||||
$.ajax({
|
||||
url: baseUrl + '/selectCurrentChallengeProducts',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
mbrInnb: getMbrInnb(),
|
||||
mbrDvCd: getMbrDvCd()
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response.resBody.result);
|
||||
if (result.success) {
|
||||
updateCurrentChallengeProductsUI(result.currentChallengeProducts);
|
||||
} else {
|
||||
alert('현재 챌린지 중인 제품을 불러오는데 실패했습니다.');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX 요청 실패:', error);
|
||||
alert('서버 오류가 발생했습니다. 다시 시도해 주세요.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateCurrentChallengeProductsUI(products) {
|
||||
const container = $('#challengeProductWrap');
|
||||
container.empty();
|
||||
|
||||
products.forEach(function(product) {
|
||||
const productHtml = `
|
||||
<div class="challengeProduct">
|
||||
<a href="#">
|
||||
<div class="thum"><img src="../resources/images/event/discount_thum3.png" alt="썸네일"></div>
|
||||
<div class="cpTit">
|
||||
<p class="tit">${product.goodsNm}</p>
|
||||
<p class="dayCheck">1일 ${product.ntkCnt}회</p>
|
||||
</div>
|
||||
<div class="drugCheck">
|
||||
${createIntakeButtons(product.dailyIntakeCount, product.ntkCnt)}
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
container.append(productHtml);
|
||||
});
|
||||
}
|
||||
|
||||
function openDeleteModal() {
|
||||
MicroModal.show('modal-1', {
|
||||
onClose: function() {
|
||||
// 모달이 닫힐 때 이벤트 리스너 제거
|
||||
$('#modal-1 .microModal__btn-primary').off('click');
|
||||
}
|
||||
});
|
||||
|
||||
// 모달의 "예" 버튼에 클릭 이벤트 리스너 추가
|
||||
$('#modal-1 .microModal__btn-primary').on('click', function() {
|
||||
deleteProduct();
|
||||
MicroModal.close('modal-1');
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
addToChallenge: addToChallenge,
|
||||
handleDateClick: handleDateClick, // 외부에서 호출할 수 있도록 함수를 노출
|
||||
navigateToAddProduct: navigateToAddProduct, // 외부에서 호출할 수 있도록 함수를 노출
|
||||
updateMonthlySummary: updateMonthlySummary,
|
||||
goToProductDetail: goToProductDetail,
|
||||
goToAddProduct: goToAddProduct,
|
||||
deleteProduct: deleteProduct,
|
||||
openDeleteModal: openDeleteModal
|
||||
};
|
||||
})();
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
Intakchl.init();
|
||||
calendarContainer.scrollTop = calendarContainer.scrollHeight / 2; // Start in the middle
|
||||
calendarContainer.addEventListener('scroll', handleScroll);
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
Intakchl.init({
|
||||
bnfInnb: $('input[name="bnfInnb"]').val(),
|
||||
dailyIntakeCount: parseInt($('#count').text(), 10)
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,302 @@
|
||||
var IntakchlAlarmSettings = (function() {
|
||||
"use strict";
|
||||
|
||||
const baseUrl = '/sopmal/bnft';
|
||||
let alarmStatuses = [];
|
||||
let isAgreed = false;
|
||||
let bnfInnb;
|
||||
let bnfNtkInnb;
|
||||
let currentAlarmIndex = -1;
|
||||
|
||||
function init(screenInfoData) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
bnfInnb = urlParams.get('bnfInnb');
|
||||
bnfNtkInnb = urlParams.get('bnfNtkInnb');
|
||||
|
||||
if (screenInfoData && screenInfoData.alarmStatuses && screenInfoData.alarmStatuses.length > 0) {
|
||||
alarmStatuses = screenInfoData.alarmStatuses;
|
||||
|
||||
// 기본 알람 설정을 유지하기 위해 부족한 알람을 채워 넣습니다.
|
||||
while (alarmStatuses.length < 3) {
|
||||
const defaultAlarm = {
|
||||
bnfNtkNtcnInnb: alarmStatuses.length + 1,
|
||||
ntcnTme: alarmStatuses.length === 0 ? '07:00:00' : (alarmStatuses.length === 1 ? '12:00:00' : '19:00:00'),
|
||||
useAt: 'N'
|
||||
};
|
||||
alarmStatuses.push(defaultAlarm);
|
||||
}
|
||||
|
||||
} else {
|
||||
alarmStatuses = [
|
||||
{ bnfNtkNtcnInnb: 1, ntcnTme: '07:00:00', useAt: 'N' },
|
||||
{ bnfNtkNtcnInnb: 2, ntcnTme: '12:00:00', useAt: 'N' },
|
||||
{ bnfNtkNtcnInnb: 3, ntcnTme: '19:00:00', useAt: 'N' }
|
||||
];
|
||||
}
|
||||
|
||||
isAgreed = screenInfoData.isAgreed || false;
|
||||
initTimePicker();
|
||||
initAlarmSettings();
|
||||
bindEvents();
|
||||
updateAlarmSettingsVisibility();
|
||||
}
|
||||
|
||||
function initTimePicker() {
|
||||
const hourSelect = document.getElementById('hour-select');
|
||||
const minuteSelect = document.getElementById('minute-select');
|
||||
|
||||
for (let i = 1; i <= 12; i++) {
|
||||
const option = document.createElement('option');
|
||||
option.value = i.toString().padStart(2, '0');
|
||||
option.textContent = i.toString().padStart(2, '0');
|
||||
hourSelect.appendChild(option);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 60; i += 10) {
|
||||
const option = document.createElement('option');
|
||||
option.value = i.toString().padStart(2, '0');
|
||||
option.textContent = i.toString().padStart(2, '0');
|
||||
minuteSelect.appendChild(option);
|
||||
}
|
||||
}
|
||||
|
||||
function initAlarmSettings() {
|
||||
const alarmList = document.querySelector('.alarmList');
|
||||
if (!alarmList) return;
|
||||
|
||||
alarmList.innerHTML = '';
|
||||
|
||||
alarmStatuses.forEach((status, index) => {
|
||||
const li = document.createElement('li');
|
||||
li.innerHTML = `
|
||||
<span><a data-micromodal-trigger="modal-1" id="alarmTime${index + 1}" data-bnfNtkNtcnInnb="${status.bnfNtkNtcnInnb}">${formatTime(status.ntcnTme)}</a></span>
|
||||
<fieldset class="toggle">
|
||||
<label>
|
||||
<input role="switch" type="checkbox" id="alarmToggle${index + 1}" ${status.useAt === 'Y' ? 'checked' : ''}>
|
||||
</label>
|
||||
</fieldset>
|
||||
`;
|
||||
alarmList.appendChild(li);
|
||||
});
|
||||
|
||||
document.getElementById('mainAlarmToggle').checked = isAgreed;
|
||||
|
||||
bindAlarmEvents();
|
||||
}
|
||||
|
||||
function bindAlarmEvents() {
|
||||
document.querySelectorAll('[id^="alarmToggle"]').forEach((toggle, index) => {
|
||||
toggle.addEventListener('change', (e) => {
|
||||
alarmStatuses[index].useAt = e.target.checked ? 'Y' : 'N';
|
||||
saveAlarmSettings(index);
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('[id^="alarmTime"]').forEach((timeElement, index) => {
|
||||
timeElement.addEventListener('click', () => {
|
||||
currentAlarmIndex = index;
|
||||
setupTimePicker(index);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
const mainAlarmToggle = document.getElementById('mainAlarmToggle');
|
||||
if (mainAlarmToggle) {
|
||||
mainAlarmToggle.addEventListener('change', (e) => {
|
||||
isAgreed = e.target.checked;
|
||||
saveAgreementStatus();
|
||||
updateAlarmSettingsVisibility();
|
||||
});
|
||||
}
|
||||
|
||||
const agreeCheckbox = document.querySelector('input[role="switch"]');
|
||||
if (agreeCheckbox) {
|
||||
agreeCheckbox.addEventListener('change', (e) => {
|
||||
isAgreed = e.target.checked;
|
||||
saveAgreementStatus();
|
||||
updateAlarmSettingsVisibility();
|
||||
});
|
||||
}
|
||||
|
||||
MicroModal.init({
|
||||
onShow: (modal) => {
|
||||
setupTimePicker(currentAlarmIndex);
|
||||
},
|
||||
onClose: (modal) => {
|
||||
saveTimePickerSelection();
|
||||
}
|
||||
});
|
||||
|
||||
const modal = document.getElementById('modal-1');
|
||||
if (modal) {
|
||||
const ampmElem = modal.querySelector('#ampm');
|
||||
const hourElem = modal.querySelector('#hour');
|
||||
const minuteElem = modal.querySelector('#minute');
|
||||
|
||||
if (ampmElem) ampmElem.addEventListener('click', () => showSelect('ampm'));
|
||||
if (hourElem) hourElem.addEventListener('click', () => showSelect('hour'));
|
||||
if (minuteElem) minuteElem.addEventListener('click', () => showSelect('minute'));
|
||||
|
||||
modal.querySelectorAll('.challenge-arrow').forEach(arrow => {
|
||||
arrow.addEventListener('click', function() {
|
||||
const type = this.parentElement.querySelector('.challenge-value').id;
|
||||
adjustValue(type, -1);
|
||||
});
|
||||
});
|
||||
|
||||
modal.querySelectorAll('.challenge-next').forEach(next => {
|
||||
next.addEventListener('click', function() {
|
||||
const type = this.parentElement.querySelector('.challenge-value').id;
|
||||
adjustValue(type, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateAlarmSettingsVisibility() {
|
||||
const alarmToggles = document.querySelectorAll('[id^="alarmToggle"]');
|
||||
const alarmTimes = document.querySelectorAll('[id^="alarmTime"]');
|
||||
|
||||
alarmToggles.forEach(toggle => {
|
||||
toggle.disabled = !isAgreed;
|
||||
});
|
||||
|
||||
alarmTimes.forEach(time => {
|
||||
time.style.pointerEvents = isAgreed ? 'auto' : 'none';
|
||||
time.style.opacity = isAgreed ? '1' : '0.5';
|
||||
});
|
||||
}
|
||||
|
||||
function saveAgreementStatus() {
|
||||
var agreementStatus = isAgreed ? 'Y' : 'N';
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/updateAlarmAgreement',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
agreAt: agreementStatus
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
console.log('Alarm agreement status updated successfully');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to update alarm agreement status:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function saveAlarmSettings(index) {
|
||||
const status = alarmStatuses[index];
|
||||
const bnfNtkNtcnInnb = document.getElementById(`alarmTime${index + 1}`).getAttribute('data-bnfNtkNtcnInnb');
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/saveAlarmSettings',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: bnfInnb,
|
||||
bnfNtkInnb: bnfNtkInnb,
|
||||
bnfNtkNtcnInnb: bnfNtkNtcnInnb, // 이 값을 전송합니다
|
||||
ntcnTme: status.ntcnTme,
|
||||
useAt: status.useAt
|
||||
}),
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
console.log('Alarm setting saved successfully');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to save alarm setting:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setupTimePicker(index) {
|
||||
const currentSetting = alarmStatuses[index];
|
||||
const [hours, minutes] = currentSetting.ntcnTme.split(':');
|
||||
const date = new Date();
|
||||
date.setHours(parseInt(hours, 10));
|
||||
date.setMinutes(parseInt(minutes, 10));
|
||||
|
||||
document.getElementById('ampm').textContent = date.getHours() >= 12 ? '오후' : '오전';
|
||||
document.getElementById('hour').textContent = (date.getHours() % 12 || 12).toString().padStart(2, '0');
|
||||
document.getElementById('minute').textContent = date.getMinutes().toString().padStart(2, '0');
|
||||
}
|
||||
|
||||
function saveTimePickerSelection() {
|
||||
if (currentAlarmIndex === -1) return;
|
||||
|
||||
const ampm = document.getElementById('ampm').textContent;
|
||||
let hour = parseInt(document.getElementById('hour').textContent, 10);
|
||||
const minute = document.getElementById('minute').textContent;
|
||||
|
||||
if (ampm === '오후' && hour !== 12) hour += 12;
|
||||
if (ampm === '오전' && hour === 12) hour = 0;
|
||||
|
||||
const newTime = `${hour.toString().padStart(2, '0')}:${minute}:00`;
|
||||
if (alarmStatuses[currentAlarmIndex].ntcnTme !== newTime) {
|
||||
alarmStatuses[currentAlarmIndex].ntcnTme = newTime;
|
||||
document.getElementById(`alarmTime${currentAlarmIndex + 1}`).textContent = formatTime(newTime);
|
||||
saveAlarmSettings(currentAlarmIndex);
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(timeString) {
|
||||
const [hours, minutes] = timeString.split(':');
|
||||
const date = new Date();
|
||||
date.setHours(parseInt(hours, 10));
|
||||
date.setMinutes(parseInt(minutes, 10));
|
||||
const ampm = date.getHours() >= 12 ? '오후' : '오전';
|
||||
const formattedHours = date.getHours() % 12 || 12;
|
||||
return `${ampm} ${formattedHours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function adjustValue(type, direction) {
|
||||
const elem = document.getElementById(type);
|
||||
const select = document.getElementById(`${type}-select`);
|
||||
let currentValue = parseInt(elem.textContent, 10);
|
||||
|
||||
if (type === 'hour') {
|
||||
currentValue = (currentValue + direction + 12 - 1) % 12 + 1;
|
||||
elem.textContent = currentValue.toString().padStart(2, '0');
|
||||
} else if (type === 'minute') {
|
||||
let currentIndex = Array.from(select.options).findIndex(option => option.value === elem.textContent);
|
||||
currentIndex = (currentIndex + direction + select.options.length) % select.options.length;
|
||||
elem.textContent = select.options[currentIndex].value;
|
||||
} else if (type === 'ampm') {
|
||||
elem.textContent = elem.textContent === '오전' ? '오후' : '오전';
|
||||
}
|
||||
}
|
||||
|
||||
function showSelect(type) {
|
||||
const elem = document.getElementById(type);
|
||||
const select = document.getElementById(`${type}-select`);
|
||||
elem.style.display = 'none';
|
||||
select.style.display = 'inline-block';
|
||||
select.value = elem.textContent;
|
||||
select.focus();
|
||||
}
|
||||
|
||||
function updateValue(type) {
|
||||
const elem = document.getElementById(type);
|
||||
const select = document.getElementById(`${type}-select`);
|
||||
elem.textContent = select.value;
|
||||
elem.style.display = 'inline-block';
|
||||
select.style.display = 'none';
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
adjustValue: adjustValue,
|
||||
showSelect: showSelect,
|
||||
updateValue: updateValue
|
||||
};
|
||||
})();
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const isAgreed = document.querySelector('input[role="switch"]').checked;
|
||||
// screenInfoData 객체가 이미 설정된 경우 이 값을 사용하고, 그렇지 않으면 기본 값을 사용합니다.
|
||||
const alarmStatuses = window.alarmStatuses || screenInfoData.alarmStatuses;
|
||||
IntakchlAlarmSettings.init({ alarmStatuses: alarmStatuses, isAgreed: isAgreed });
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
document.getElementById('manageProducts').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
window.location.href = '/sopmal/bnft/intakchlChallengeProductManagement';
|
||||
});
|
||||
|
||||
document.getElementById('setAlarms').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
window.location.href = '/sopmal/bnft/intakchllAlarmSettings';
|
||||
});
|
||||
Reference in New Issue
Block a user