var ajaxRequest5 = null; $(document).ready(function() { let todo_currentMonth = new Date().getMonth(); let todo_currentYear = new Date().getFullYear(); function todo_fetchCalendarData(month, year) { var search = $('#searchTodo').val(); // 선택된 라디오 버튼 정보를 배열로 변환 (_all 제외) var radioarray = []; $('.filter-radio').each(function(index) { // console.log(`index ${index}`); // 템플릿 리터럴 수정 var id = $(this).attr('id'); if (id) { var splitItem = id.split('_')[1]; // "_"로 분리하여 두 번째 요소 가져오기 if (splitItem && splitItem !== 'all') { // 'all'은 제외 radioarray.push(splitItem); // 배열에 추가 } } }); // 필터에 따라 데이터 표시 let selectedFilter = $('input[name="filter"]:checked').attr('id'); // let filteredData = filterDataByProcess(response.todo_data, selectedFilter); // radioarray 결과 확인 // console.log(radioarray); // showWaitingModal(); ajaxRequest5 = $.ajax({ url: "/todo/fetch_todo.php", type: "post", data: { month: month + 1, year: year, selectedFilter : selectedFilter, search : search, radioarray : radioarray }, dataType: "json", success: function(response) { // console.log(response); let calendarHtml = todo_generateCalendarHtml( response.leave_data, response.holiday_data, response.todo_data, response.shutter_data, response.registration_data, selectedFilter ); $('#todo-calendar-container').html(calendarHtml); var showTodoView = getCookie("showTodoView"); var todoCalendarContainer = $("#todo-list"); if (showTodoView === "show") { todoCalendarContainer.css("display", "inline-block"); } else { todoCalendarContainer.css("display", "none"); } // 검색 결과를 부트스트랩 테이블로 렌더링 if (search && response.integratedData.length > 0) { $('#todosMain-list').empty(); renderTodosMainTable(response.integratedData); } else if (search) { $('#todosMain-list').html('
검색 결과가 없습니다.
'); } else { $('#todosMain-list').empty(); } ajaxRequest5 = null; hideSavingModal(); }, error: function() { console.log('Failed to fetch data'); ajaxRequest5 = null; hideSavingModal(); } }); } // 테이블 생성 함수 function renderTodosMainTable(data) { let tableHtml = `| 구분 | 접수일 | 출고일 | 발주처 | 현장명 | 주소 |
|---|---|---|---|---|---|
| ${tableType} | ${item.indate || '-'} | ${item.outdate || '-'} | ${item.secondord || '-'} | ${item.outworkplace || '-'} | ${item.receiver || '-'} |
| ${day} | `; }); calendarHtml += '|
|---|---|
| '; } else { let currentDate = new Date(todo_currentYear, todo_currentMonth, day); currentDate.setHours(0, 0, 0, 0); let dayData = todoData.filter(item => new Date(item.orderdate).toDateString() === currentDate.toDateString()); let leaveDataForDay = leaveData.filter(item => { let leaveStart = convertToKST(item.al_askdatefrom); let leaveEnd = convertToKST(item.al_askdateto); return currentDate >= leaveStart && currentDate <= leaveEnd; }); let holidayForDay = holidayData.filter(item => { let startDate = convertToKST(item.startdate); let endDate = item.enddate && item.enddate !== '0000-00-00' ? convertToKST(item.enddate) : startDate; return currentDate >= startDate && currentDate <= endDate; }); let registrationforData = registrationData.filter(item => new Date(item.indate).toDateString() === currentDate.toDateString()); let shutterforData = shutterData.filter(item => new Date(item.outdate).toDateString() === currentDate.toDateString()); let dayClass = ''; if (j === 0 || j === 6) dayClass += ' red-day'; if (currentDate.toDateString() === today.toDateString()) dayClass += ' today-bg'; if (holidayForDay.length > 0) dayClass += ' text-danger'; calendarHtml += ` |
${day}
${item.comment} `;
});
// 두번째행 공지사항
dayData.forEach(item => {
let workStatus = item.work_status === '완료' ? '완료' : '';
calendarHtml += `
${item.towhom ? `${item.towhom}` : ''}
${item.title ? ` `;
});
// 세번째행 연차휴가
// leaveDataForDay.forEach(item => {
// if(j != 0 && j != 6) { // 토요일, 일요일 제외
// calendarHtml += `${item.title}` : ''} ${workStatus}${item.author} (${item.al_item}) `;
// }
// });
// 주말(토,일)이 아니고 휴일이 아닌 경우에만 generateLeaveHtml 호출
if (j !== 0 && j !== 6 && holidayForDay.length === 0) {
const leaveHtml = generateLeaveHtml(leaveDataForDay);
calendarHtml += leaveHtml;
}
// 해당날짜의 접수 표시
registrationforData.forEach(item => {
// 원본 값
let title = item.secondord;
let placeName = item.outworkplace;
// combined 길이 체크 후 축약
if ((title.length + placeName.length) > 20) {
title = title.length > 8
? title.substring(0, 8) + '..'
: title;
placeName = placeName.length > 8
? placeName.substring(0, 8) + '..'
: placeName;
}
// 화면에 표시할 작업장 이름
const outworkplace = placeName;
// 기본 HTML 구조 시작
calendarHtml +=
``;
// 배지(순서)
calendarHtml += `${title}`;
// 조건에 따른 텍스트 색상 및 스타일
if (item.indate && item.indate !== '0000-00-00') {
calendarHtml += `${outworkplace}`;
} else {
calendarHtml += `${outworkplace}`;
}
// 기본 HTML 구조 종료
calendarHtml += ' ';
});
// 해당날짜의 출고 표시
shutterforData.forEach(item => {
// 원본 값
let title = item.secondord;
let placeName = item.outworkplace;
// combined 길이 체크 후 축약 (합이 20자 초과 시)
if ((title.length + placeName.length) > 20) {
title = title.length > 8
? title.substring(0, 8) + '..'
: title;
placeName = placeName.length > 8
? placeName.substring(0, 8) + '..'
: placeName;
}
// 화면에 표시할 작업장 이름
const outworkplace = placeName;
// 기본 HTML 구조 시작
calendarHtml +=
``;
// 배지(순서)
calendarHtml += `${title}`;
// 조건에 따른 텍스트 색상 및 스타일
if (item.outdate && item.outdate !== '0000-00-00') {
calendarHtml += `${outworkplace}`;
} else {
calendarHtml += `${outworkplace}`;
}
// 기본 HTML 구조 종료
calendarHtml += ' ';
});
calendarHtml += ' | ';
day++;
}
}
calendarHtml += '
이 날짜에 데이터가 없습니다.
'; } $('#dayModal .modal-body').html(modalContent).css('font-size', '20px'); // 글자 크기 설정 $('#dayModal').modal('show'); }); $('#dayModal').on('shown.bs.modal', function () { $(document).on('mouseenter', '.list-group-item', function () { $(this).css({ 'box-shadow': '0 .125rem .25rem rgba(0, 0, 0, .075)', 'transition': 'box-shadow 0.2s ease-in-out', 'cursor': 'pointer' }); }).on('mouseleave', '.list-group-item', function () { $(this).css({ 'box-shadow': 'none' }); }); }); $('#todo-prev-month').click(function() { todo_currentMonth--; if (todo_currentMonth < 0) { todo_currentMonth = 11; todo_currentYear--; } todo_fetchCalendarData(todo_currentMonth, todo_currentYear); }); $('#todo-next-month').click(function() { todo_currentMonth++; if (todo_currentMonth > 11) { todo_currentMonth = 0; todo_currentYear++; } todo_fetchCalendarData(todo_currentMonth, todo_currentYear); }); $('#todo-current-month').click(function() { todo_currentMonth = new Date().getMonth(); todo_currentYear = new Date().getFullYear(); todo_fetchCalendarData(todo_currentMonth, todo_currentYear); }); // 초기 라디오 버튼 상태 설정 및 필터 변경 이벤트 function initializeRadioButtons() { let selectedFilter = getCookie("todoFilter") || 'filter_all'; $('#' + selectedFilter).prop('checked', true); todo_fetchCalendarData(todo_currentMonth, todo_currentYear); } // 일정검색시 $('#searchTodoBtn').off('click').on('click', function () { var search = $('#searchTodo').val(); // console.log(search); todo_fetchCalendarData(todo_currentMonth, todo_currentYear, search); }); // 라디오 버튼 변경 이벤트 핸들러 $('input[name="filter"]').on('change', function () { let selectedFilter = $('input[name="filter"]:checked').attr('id'); setCookie("todoFilter", selectedFilter, 10); var search = $('#searchTodo').val(); // console.log(search); todo_fetchCalendarData(todo_currentMonth, todo_currentYear, search); }); // 팝업 창 열기 함수 function popupCenter(url, title, w, h) { const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left; const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top; const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; const left = (width / 2) - (w / 2) + dualScreenLeft; const top = (height / 2) - (h / 2) + dualScreenTop; const newWindow = window.open(url, title, `scrollbars=yes, width=${w}, height=${h}, top=${top}, left=${left}`); if (window.focus) newWindow.focus(); } //todo_fetchCalendarData(todo_currentMonth, todo_currentYear); // 초기 필터 위치가 저장된 곳을 보여준다. 달력 필터 라디오버튼 initializeRadioButtons(); }); // ⑤ 마우스 hover 이벤트 (jQuery) 연차리스트에 마우스를 올리면 나타나는 효과 $(document) .on('mouseenter', '.leave-container', function() { $(this).find('.leave-more-list') .stop(true,true) .slideDown(100); }) .on('mouseleave', '.leave-container', function() { $(this).find('.leave-more-list') .stop(true,true) .slideUp(100); });